Skip to content

Commit

Permalink
KosmosisDire#60 added separate chance for reviver to get Death Curse
Browse files Browse the repository at this point in the history
  • Loading branch information
amadare42 committed Nov 26, 2022
1 parent 608bf76 commit d89e1af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 7 additions & 1 deletion TeammateRevive/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,16 @@ static BindCollection BindRuleValues(ConfigFile configFile, ReviveRuleValues val
defaultValue: values.CutReviveeHp)
.Bind(
key: "Death Curse chance",
description: "[Only with Death Curse enabled] Chance to receive Death Curse on revival (Range: 0-100%)",
description: "[Only with Death Curse enabled] Chance to receive Death Curse on revival for revivee (Range: 0-100%)",
set: v => values.DeathCurseChance = v,
defaultValue: values.DeathCurseChance,
metadata: new FloatMetadata(0, 100, 1))
.Bind(
key: "Reviver Death Curse chance",
description: "[Only with Death Curse enabled] Chance to receive Death Curse on revival for reviver (Range: 0-100%)",
set: v => values.ReviverDeathCurseChance = v,
defaultValue: values.ReviverDeathCurseChance,
metadata: new FloatMetadata(0, 100, 1))
.Bind(
key: "Post revive regeneration time",
description: "After reviving, 40% of revivee and linked revivers HP is restored. This value specify how long regeneration buff is active in seconds. If set to 0 - revive regen is disabled.",
Expand Down
17 changes: 10 additions & 7 deletions TeammateRevive/Revive/RevivalTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,19 @@ void Revive(Player dead)
private void ApplyDeathCurses(Player dead, Player[] linkedPlayers)
{
// invert - from "chance to get curse" to "chance to avoid curse"
var percentChance = Mathf.Clamp(100 - rules.Values.DeathCurseChance, 0, 100);
var reviveeChance = Mathf.Clamp(100 - rules.Values.DeathCurseChance, 0, 100);
var reviverChance = Mathf.Clamp(100 - rules.Values.ReviverDeathCurseChance, 0, 100);

bool RollCurse(Player player, float extraLuck)
bool RollCurse(Player player, float chance, float extraLuck)
{
// negative luck - take largest roll value
// if value > chance - roll is failed
// therefore positive luck - outcome is more likely
// using inverted roll, so clover sound effect will be triggered if clover is present
var luckTotal = extraLuck + player.master.master.luck;
var curseAvoided = Util.CheckRoll(percentChance, luckTotal, player.master.master.luck > 0 ? player.master.master : null);
var curseAvoided = Util.CheckRoll(chance, luckTotal, player.master.master.luck > 0 ? player.master.master : null);

Log.Info($"Rolled curse for {player.networkUser.userName}: {chance:F1}% (luck: {player.master.master.luck:F0}+{extraLuck:F0}). Success: {curseAvoided}");
if (!curseAvoided)
{
player.GiveItem(DeathCurse.ItemIndex);
Expand All @@ -225,8 +228,7 @@ bool RollCurse(Player player, float extraLuck)
});
return true;
}

Log.Info($"Rolled curse for {player.networkUser.userName}: {percentChance:F1}% (luck: {player.master.master.luck:F0}+{extraLuck:F0}). Success: {curseAvoided}");

Chat.SendBroadcastChat(new Chat.SimpleChatMessage
{
baseToken = LanguageConsts.TEAMMATE_REVIVAL_UI_AVOIDED_CURSE,
Expand All @@ -235,14 +237,15 @@ bool RollCurse(Player player, float extraLuck)
return false;
}

RollCurse(dead, dead.ItemCount(RevivalToken.Index));
// roll for revivee
RollCurse(dead, reviveeChance, dead.ItemCount(RevivalToken.Index));

// the more time spent reviving this player - the greater chance to receive a curse
var array = SortByLinkDuration(linkedPlayers, dead).ToArray();
for (var index = 0; index < array.Length; index++)
{
var player = array[index];
if (RollCurse(player, index))
if (RollCurse(player, reviverChance, index))
{
// when at least one player received curse, stop rolling for other members
break;
Expand Down
2 changes: 2 additions & 0 deletions TeammateRevive/Revive/Rules/ReviveRuleValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class ReviveRuleValues

public float DeathCurseChance { get; set; } = 66f;

public float ReviverDeathCurseChance { get; set; } = 66f;

public ReviveRuleValues Clone()
{
return (ReviveRuleValues)MemberwiseClone();
Expand Down

0 comments on commit d89e1af

Please sign in to comment.