Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
DodgeChance.cs
Go to the documentation of this file.
1 using Loot.Api.Attributes;
2 using Loot.Api.Core;
3 using Loot.Api.Delegators;
4 using Loot.Modifiers.Base;
5 using Terraria;
6 using Terraria.DataStructures;
7 
8 namespace Loot.Modifiers.EquipModifiers.Defensive
9 {
10  public class DodgeEffect : ModifierEffect
11  {
12  public float DodgeChance; // Dodge chance
13 
14  public override void ResetEffects()
15  {
16  DodgeChance = 0f;
17  }
18 
19  [AutoDelegation("OnPreHurt")]
21  private bool TryDodge(bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
22  {
23  if (Main.rand.NextFloat() < DodgeChance)
24  {
25  player.NinjaDodge();
26  return false;
27  }
28 
29  return true;
30  }
31  }
32 
33  [UsesEffect(typeof(DodgeEffect))]
34  public class DodgeChance : EquipModifier
35  {
37  {
38  return base.GetTooltip()
39  .WithPositive($"+{Properties.RoundedPower}% dodge chance");
40  }
41 
43  {
44  return base.GetModifierProperties(item)
45  .WithMaxMagnitude(5f)
46  .WithRollChance(0.333f);
47  }
48 
49  public override void UpdateEquip(Item item, Player player)
50  {
51  ModifierDelegatorPlayer.GetPlayer(player).GetEffect<DodgeEffect>().DodgeChance += Properties.RoundedPower / 100f;
52  }
53  }
54 }
The ModifierPropertiesBuilder implements the builder pattern for ModifierProperties It provides a str...
This attribute may be used to skip usage of AttachDelegations and DetachDelegations Which is a cumber...
A ModifierEffect signifies the effect of a modifier on a player It should house the implementation...
override ModifierProperties.ModifierPropertiesBuilder GetModifierProperties(Item item)
Definition: DodgeChance.cs:42
Defines a modifier that can roll on an equip item (armor or accessory) These modifiers will have 60% ...
override void ResetEffects()
Automatically called when the ModPlayer does its ResetEffects Also automatically called when the dele...
Definition: DodgeChance.cs:14
DelegationPrioritization
Specify when you want your delegation to happen in the chain
static ModifierDelegatorPlayer GetPlayer(Player player)
override void UpdateEquip(Item item, Player player)
Definition: DodgeChance.cs:49
Defines the properties of a modifier
bool TryDodge(bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
Definition: DodgeChance.cs:21
Defines a tooltip line of a modifier A modifier can have multiple lines
override ModifierTooltipLine.ModifierTooltipBuilder GetTooltip()
Definition: DodgeChance.cs:36
Holds player-entity data and handles it