Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
ManaShield.cs
Go to the documentation of this file.
1 using System;
2 using Loot.Api.Attributes;
3 using Loot.Api.Core;
4 using Loot.Api.Delegators;
5 using Loot.Modifiers.Base;
6 using Terraria;
7 using Terraria.DataStructures;
8 
9 namespace Loot.Modifiers.EquipModifiers.Defensive
10 {
12  {
13  public float ManaShield; // % of damage redirected to mana
14 
15  public override void ResetEffects()
16  {
17  ManaShield = 0f;
18  }
19 
20  [AutoDelegation("OnPreHurt")]
22  private bool ManaBlock(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)
23  {
24  // If we have a mana shield (% damage redirected to mana)
25  // Then try to redirect the damage
26  int manaBlock = (int) Math.Ceiling(damage * ManaShield) * 2;
27  if (manaBlock > 0 && player.statMana > 0)
28  {
29  // We cannot block more than how much mana we have
30  if (manaBlock > player.statMana)
31  {
32  manaBlock = player.statMana;
33  }
34 
35  damage -= manaBlock / 2;
36  player.statMana -= manaBlock;
37  player.manaRegenDelay = Math.Max(player.manaRegenDelay, 120);
38  }
39 
40  return true;
41  }
42  }
43 
44  [UsesEffect(typeof(ManaShieldEffect))]
45  public class ManaShield : EquipModifier
46  {
48  {
49  return base.GetTooltip()
50  .WithPositive($"+{Properties.RoundedPower}% of damage taken is redirected to mana");
51  }
52 
54  {
55  return base.GetModifierProperties(item)
56  .WithMaxMagnitude(5f)
57  .WithRollChance(0.75f);
58  }
59 
60  public override void UpdateEquip(Item item, Player player)
61  {
62  ModifierDelegatorPlayer.GetPlayer(player).GetEffect<ManaShieldEffect>().ManaShield += Properties.RoundedPower / 100f;
63  }
64  }
65 }
The ModifierPropertiesBuilder implements the builder pattern for ModifierProperties It provides a str...
bool ManaBlock(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: ManaShield.cs:22
This attribute may be used to skip usage of AttachDelegations and DetachDelegations Which is a cumber...
override void UpdateEquip(Item item, Player player)
Definition: ManaShield.cs:60
A ModifierEffect signifies the effect of a modifier on a player It should house the implementation...
Defines a modifier that can roll on an equip item (armor or accessory) These modifiers will have 60% ...
override ModifierTooltipLine.ModifierTooltipBuilder GetTooltip()
Definition: ManaShield.cs:47
DelegationPrioritization
Specify when you want your delegation to happen in the chain
static ModifierDelegatorPlayer GetPlayer(Player player)
Defines the properties of a modifier
Defines a tooltip line of a modifier A modifier can have multiple lines
override void ResetEffects()
Automatically called when the ModPlayer does its ResetEffects Also automatically called when the dele...
Definition: ManaShield.cs:15
override ModifierProperties.ModifierPropertiesBuilder GetModifierProperties(Item item)
Definition: ManaShield.cs:53
Holds player-entity data and handles it