Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
LightPlus.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 Microsoft.Xna.Framework;
6 using Terraria;
7 
8 namespace Loot.Modifiers.EquipModifiers.Utility
9 {
10  // Light effect, spawns a light on the player
11  // This is one of the most basic modifiers with effect examples
12  public class LightEffect : ModifierEffect
13  {
14  // Public variables that are adjustable
15  public float LightStrength;
16  public Color LightColor;
17 
18  // OnInitialize can initialize an effect's values
19  // It is called when a player initializes its effects
20  public override void OnInitialize()
21  {
22  // Setting Strength is not really needed, as the default
23  // value for floats is already 0f. Just for clarity's sake.
24  LightStrength = 0f;
25  LightColor = Color.White;
26  }
27 
28  // ResetEffects is called automatically if the effect is being delegated
29  // This is used to reset variables like you are used to in ModPlayer
30  public override void ResetEffects()
31  {
32  LightStrength = 0f;
33  LightColor = Color.White;
34  }
35 
36  public override void Clone(ref ModifierEffect clone)
37  {
38  // For clarity, additional cloning is possible like this
39  ((LightEffect) clone).LightStrength = LightStrength;
40  ((LightEffect) clone).LightColor = LightColor;
41  }
42 
43  // This method will be delegated to PostUpdate
44  // Meaning that this code is automatically called
45  // on ModifierPlayer's PostUpdate hook if this effect
46  // is being delegated
47  [AutoDelegation("OnPostUpdate")]
48  private void Light()
49  {
50  Lighting.AddLight(player.Center, LightColor.ToVector3() * .15f * LightStrength);
51  }
52  }
53 
54  // The UsesEffect attribute is linking this Modifier
55  // to the LightEffect effect.
56  // This will make the LightEffect become activated
57  // if we have an item with this modifier.
58  [UsesEffect(typeof(LightEffect))]
59  public class LightPlus : EquipModifier
60  {
62  {
63  return base.GetTooltip()
64  .WithPositive($"+{Properties.RoundedPower} light");
65  }
66 
68  {
69  return base.GetModifierProperties(item)
70  .WithMaxMagnitude(2f);
71  }
72 
73  public override void UpdateEquip(Item item, Player player)
74  {
75  ModifierDelegatorPlayer.GetPlayer(player).GetEffect<LightEffect>().LightStrength += (int) Properties.RoundedPower;
76  }
77  }
78 }
override void OnInitialize()
Called when the ModPlayer initializes the effect
Definition: LightPlus.cs:20
The ModifierPropertiesBuilder implements the builder pattern for ModifierProperties It provides a str...
override void UpdateEquip(Item item, Player player)
Definition: LightPlus.cs:73
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...
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: LightPlus.cs:30
override ModifierTooltipLine.ModifierTooltipBuilder GetTooltip()
Definition: LightPlus.cs:61
static ModifierDelegatorPlayer GetPlayer(Player player)
override void Clone(ref ModifierEffect clone)
A modder can provide custom cloning of effects in this hook
Definition: LightPlus.cs:36
Defines the properties of a modifier
Defines a tooltip line of a modifier A modifier can have multiple lines
override ModifierProperties.ModifierPropertiesBuilder GetModifierProperties(Item item)
Definition: LightPlus.cs:67
Holds player-entity data and handles it