Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
Modifier.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using Loot.Api.Content;
6 using Loot.Api.Graphics.Shader;
7 using Microsoft.Xna.Framework;
8 using Terraria;
9 using Terraria.ModLoader;
10 using Terraria.ModLoader.IO;
11 using Terraria.Utilities;
12 
13 namespace Loot.Api.Core
14 {
21  public abstract class Modifier : GlobalItem, ILoadableContent, ILoadableContentSetter, ICloneable
22  {
23  public Mod Mod { get; internal set; }
24 
25  Mod ILoadableContentSetter.Mod
26  {
27  set => Mod = value;
28  }
29 
30  public uint Type { get; internal set; }
31 
32  uint ILoadableContentSetter.Type
33  {
34  set => Type = value;
35  }
36 
37  public new string Name => GetType().Name;
38  public virtual string UniqueName => string.Empty;
39  public string GetFormattedUniqueName() => !string.IsNullOrEmpty(UniqueName) ? $"\"{UniqueName}\"" : string.Empty;
40 
41  public virtual GlowmaskEntity GetGlowmaskEntity(Item item) => null;
42  public virtual ShaderEntity GetShaderEntity(Item item) => null;
43 
44  public ModifierProperties Properties { get; internal set; }
45 
46  public virtual ModifierTooltipLine.ModifierTooltipBuilder GetTooltip()
47  => ModifierTooltipLine.Builder;
48 
49  public virtual ModifierProperties.ModifierPropertiesBuilder GetModifierProperties(Item item)
51 
52  /* Global
53  For now:
54  We cannot roll on items that can stack (stacking is undefined behavior)
55  */
56  protected internal bool _CanRoll(ModifierContext ctx)
57  {
58  // Properties are pre-loaded before CanRoll as they may be needed for checks
59  Properties = GetModifierProperties(ctx.Item).Build();
60  return ctx.Item.maxStack <= 1 && CanRoll(ctx);
61  }
62 
67  public virtual bool CanRoll(ModifierContext ctx)
68  => true;
69 
74  public virtual void Roll(ModifierContext ctx, IEnumerable<Modifier> rolledModifiers)
75  {
76  }
77 
84  public virtual bool PostRoll(ModifierContext ctx, IEnumerable<Modifier> rolledModifiers)
85  => true;
86 
92  public virtual void Apply(Item item)
93  {
94  }
95 
100  public virtual void Clone(ref Modifier clone)
101  {
102  }
103 
104  public new object Clone()
105  {
106  Modifier clone = (Modifier)MemberwiseClone();
107  clone.Mod = Mod;
108  clone.Type = Type;
109  clone.Properties = Properties;
110  Clone(ref clone);
111  return clone;
112  }
113 
119  public new virtual void Load(Item item, TagCompound tag)
120  {
121  }
122 
127  public virtual void Save(Item item, TagCompound tag)
128  {
129  }
130 
131  // Never autoload us
132  public sealed override bool Autoload(ref string name) => false;
133  public sealed override bool InstancePerEntity => true;
134  public sealed override bool CloneNewInstances => true;
135 
136  public sealed override void SetDefaults(Item item)
137  {
138  base.SetDefaults(item);
139  Apply(item);
140  }
141 
142  public sealed override int ChoosePrefix(Item item, UnifiedRandom rand)
143  {
144  return base.ChoosePrefix(item, rand);
145  }
146 
147  // The following hooks aren't applicable in instanced context, so we seal them here so they can't be used
148  public sealed override GlobalItem Clone(Item item, Item itemClone) => base.Clone(item, itemClone);
149 
150  public sealed override void ExtractinatorUse(int extractType, ref int resultType, ref int resultStack)
151  {
152  }
153 
154  public sealed override void CaughtFishStack(int type, ref int stack)
155  {
156  }
157 
158  public sealed override void AnglerChat(int type, ref string chat, ref string catchLocation)
159  {
160  }
161 
162  public sealed override void OnCraft(Item item, Recipe recipe)
163  {
164  }
165 
166  public sealed override void ArmorSetShadows(Player player, string set)
167  {
168  }
169 
170  public sealed override void ArmorArmGlowMask(int slot, Player drawPlayer, float shadow, ref int glowMask, ref Color color)
171  {
172  }
173 
174  public sealed override void DrawArmorColor(EquipType type, int slot, Player drawPlayer, float shadow, ref Color color, ref int glowMask, ref Color glowMaskColor)
175  {
176  }
177 
178  public sealed override bool DrawBody(int body) => base.DrawBody(body);
179 
180  public sealed override void DrawHair(int head, ref bool drawHair, ref bool drawAltHair)
181  {
182  }
183 
184  public sealed override void DrawHands(int body, ref bool drawHands, ref bool drawArms)
185  {
186  }
187 
188  public sealed override bool DrawHead(int head) => base.DrawHead(head);
189  public sealed override bool DrawLegs(int legs, int shoes) => base.DrawLegs(legs, shoes);
190  public sealed override Vector2? HoldoutOffset(int type) => base.HoldoutOffset(type);
191  public sealed override Vector2? HoldoutOrigin(int type) => base.HoldoutOrigin(type);
192  public sealed override bool IsAnglerQuestAvailable(int type) => base.IsAnglerQuestAvailable(type);
193  public sealed override string IsArmorSet(Item head, Item body, Item legs) => base.IsArmorSet(head, body, legs);
194 
195  public sealed override string IsVanitySet(int head, int body, int legs) => base.IsVanitySet(head, body, legs);
196 
197  // If modders wish to save/load data, they should use our custom save and load hooks
198  public sealed override void LoadLegacy(Item item, BinaryReader reader)
199  {
200  }
201 
202  public sealed override bool NeedsSaving(Item item) => base.NeedsSaving(item);
203  public sealed override GlobalItem NewInstance(Item item) => base.NewInstance(item);
204 
205  public sealed override void OpenVanillaBag(string context, Player player, int arg)
206  {
207  }
208 
209  public sealed override bool PreOpenVanillaBag(string context, Player player, int arg) => base.PreOpenVanillaBag(context, player, arg);
210 
211  public sealed override void PreUpdateVanitySet(Player player, string set)
212  {
213  }
214 
215  // If modders wish to save/load data, they should use our custom save and load hooks
216  public sealed override TagCompound Save(Item item) => base.Save(item);
217 
218  public sealed override void SetMatch(int armorSlot, int type, bool male, ref int equipSlot, ref bool robes)
219  {
220  }
221 
222  public sealed override void UpdateArmorSet(Player player, string set)
223  {
224  }
225 
226  public sealed override void UpdateVanitySet(Player player, string set)
227  {
228  }
229 
230  public sealed override bool WingUpdate(int wings, Player player, bool inUse) => base.WingUpdate(wings, player, inUse);
231  }
232 }
sealed override void DrawHands(int body, ref bool drawHands, ref bool drawArms)
Definition: Modifier.cs:184
Defines a modifier, which is an unloaded GlobalItem Making it a GlobalItem gives easy access to all h...
Definition: Modifier.cs:21
sealed override void PreUpdateVanitySet(Player player, string set)
Definition: Modifier.cs:211
Defines a context in which a Modifier might be rolled Which fields are available (not null) depends o...
The ModifierPropertiesBuilder implements the builder pattern for ModifierProperties It provides a str...
sealed override void AnglerChat(int type, ref string chat, ref string catchLocation)
Definition: Modifier.cs:158
ModifierProperties Properties
Definition: Modifier.cs:44
sealed override void SetMatch(int armorSlot, int type, bool male, ref int equipSlot, ref bool robes)
Definition: Modifier.cs:218
sealed override void ArmorArmGlowMask(int slot, Player drawPlayer, float shadow, ref int glowMask, ref Color color)
Definition: Modifier.cs:170
sealed override void UpdateVanitySet(Player player, string set)
Definition: Modifier.cs:226
Defines a Shader entity, part of GraphicsEntity<T> The entity defines a particular &#39;shader&#39; "of" the ...
Definition: ShaderEntity.cs:16
virtual void Clone(ref Modifier clone)
Allows modders to do custom cloning here Happens after default cloning, which clones various info (mo...
Definition: Modifier.cs:100
new object Clone()
Definition: Modifier.cs:104
virtual void Apply(Item item)
Allows modders to do something when this modifier is applied If a modder needs ModPlayer hooks...
Definition: Modifier.cs:92
sealed override void ArmorSetShadows(Player player, string set)
Definition: Modifier.cs:166
Defines the properties of a modifier
sealed override void SetDefaults(Item item)
Definition: Modifier.cs:136
virtual void Roll(ModifierContext ctx, IEnumerable< Modifier > rolledModifiers)
Allows modders to do something when the modifier is rolled in the given context The passed rolledModi...
Definition: Modifier.cs:74
sealed override void LoadLegacy(Item item, BinaryReader reader)
Definition: Modifier.cs:198
sealed override int ChoosePrefix(Item item, UnifiedRandom rand)
Definition: Modifier.cs:142
Defines a tooltip line of a modifier A modifier can have multiple lines
sealed override void CaughtFishStack(int type, ref int stack)
Definition: Modifier.cs:154
sealed override void UpdateArmorSet(Player player, string set)
Definition: Modifier.cs:222
Defines a Glowmask entity, part of GraphicsEntity The entity defines a particular &#39;glowmask&#39; "of" the...
sealed override void ExtractinatorUse(int extractType, ref int resultType, ref int resultStack)
Definition: Modifier.cs:150
sealed override void DrawArmorColor(EquipType type, int slot, Player drawPlayer, float shadow, ref Color color, ref int glowMask, ref Color glowMaskColor)
Definition: Modifier.cs:174
sealed override void OpenVanillaBag(string context, Player player, int arg)
Definition: Modifier.cs:205
Defines a piece of loadable content The interface is used in classes where the deriving class already...
static ModifierPropertiesBuilder Builder
sealed override void DrawHair(int head, ref bool drawHair, ref bool drawAltHair)
Definition: Modifier.cs:180
virtual void Save(Item item, TagCompound tag)
Allows modder to do custom saving here Use the given TC to put data you want to save, which can be loaded using Load(Item,TagCompound)
Definition: Modifier.cs:127
sealed override void OnCraft(Item item, Recipe recipe)
Definition: Modifier.cs:162
virtual new void Load(Item item, TagCompound tag)
Allows modder to do custom loading here Use the given TC to pull data you saved using Save(Item...
Definition: Modifier.cs:119