Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
Loot.LootModItem Class Reference

Defines an item that may be modified by modifiers from mods More...

+ Inheritance diagram for Loot.LootModItem:
+ Collaboration diagram for Loot.LootModItem:

Public Member Functions

override GlobalItem Clone (Item item, Item itemClone)
 Attempts to roll new modifiers Has a set chance to hit a predefined pool of modifiers More...
 
override void Load (Item item, TagCompound tag)
 
override void ModifyTooltips (Item item, List< TooltipLine > tooltips)
 Will modify vanilla tooltips to add additional information for the affected item's modifiers More...
 
override bool NeedsSaving (Item item)
 
override void NetReceive (Item item, BinaryReader reader)
 
override void NetSend (Item item, BinaryWriter writer)
 
override TagCompound Save (Item item)
 

Static Public Member Functions

static List< ModifierGetActivePool (Item item)
 
static LootModItem GetInfo (Item item)
 

Public Attributes

override bool CloneNewInstances => true
 
override bool InstancePerEntity => true
 

Properties

bool HasRolled [get, set]
 
bool IsActivated [get, set]
 Keeps track of if the particular item was activated ('delegated') Specific usecase see CursedEffect and modifier More...
 
bool JustTinkerModified [get, set]
 
FiniteModifierPool Modifiers [get, set]
 
ModifierRarity Rarity [get, set]
 
bool SealedModifiers [get, set]
 
bool SlottedInUI [get, set]
 

Private Member Functions

string GetPrefixNormString (float cpStat, float rStat, ref double num, ref Color?color)
 
void InvalidateRolls ()
 

Private Attributes

const int SAVE_VERSION = 14
 

Detailed Description

Defines an item that may be modified by modifiers from mods

Definition at line 21 of file LootModItem.cs.

Member Function Documentation

override GlobalItem Loot.LootModItem.Clone ( Item  item,
Item  itemClone 
)

Attempts to roll new modifiers Has a set chance to hit a predefined pool of modifiers

Definition at line 165 of file LootModItem.cs.

References Loot.LootModItem.Clone(), Loot.LootModItem.Modifiers, and Loot.LootModItem.Rarity.

Referenced by Loot.LootModItem.Clone().

166  {
167  LootModItem clone = (LootModItem)base.Clone(item, itemClone);
168  clone.Rarity = (ModifierRarity)Rarity?.Clone() ?? mod.GetNullModifierRarity();
169  clone.Modifiers = (FiniteModifierPool)Modifiers?.Clone() ?? mod.GetNullModifierPool();
170  // there is no need to apply here, we already cloned the item which stats are already modified by its pool
171  return clone;
172  }
Defines the rarity of a modifier
ModifierRarity Rarity
Definition: LootModItem.cs:31
FiniteModifierPool Modifiers
Definition: LootModItem.cs:32
override GlobalItem Clone(Item item, Item itemClone)
Attempts to roll new modifiers Has a set chance to hit a predefined pool of modifiers ...
Definition: LootModItem.cs:165

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

string Loot.LootModItem.GetPrefixNormString ( float  cpStat,
float  rStat,
ref double  num,
ref Color?  color 
)
private

Definition at line 309 of file LootModItem.cs.

Referenced by Loot.LootModItem.ModifyTooltips().

310  {
311  //float num19 = (float)Main.mouseTextColor / 255f;
312  //patch file: num20
313  float defColorVal = Main.mouseTextColor / 255f;
314  int alphaColor = Main.mouseTextColor;
315 
316  if (cpStat == 0f && rStat != 0f)
317  {
318  num = 1;
319  if (rStat > 0f)
320  {
321  color = new Color((byte)(120f * defColorVal), (byte)(190f * defColorVal), (byte)(120f * defColorVal), alphaColor);
322  return "+" + rStat.ToString(CultureInfo.InvariantCulture); /* + Lang.tip[39].Value;*/
323  }
324 
325  color = new Color((byte)(190f * defColorVal), (byte)(120f * defColorVal), (byte)(120f * defColorVal), alphaColor);
326  return rStat.ToString(CultureInfo.InvariantCulture); /* + Lang.tip[39].Value;*/
327  }
328 
329  double diffStat = rStat - cpStat;
330  diffStat = diffStat / cpStat * 100.0;
331  diffStat = Math.Round(diffStat);
332  num = diffStat;
333 
334  // for some reason - is handled automatically, but + is not
335  if (diffStat > 0.0)
336  {
337  color = new Color((byte)(120f * defColorVal), (byte)(190f * defColorVal), (byte)(120f * defColorVal), alphaColor);
338  return "+" + diffStat.ToString(CultureInfo.InvariantCulture); /* + Lang.tip[39].Value;*/
339  }
340 
341  color = new Color((byte)(190f * defColorVal), (byte)(120f * defColorVal), (byte)(120f * defColorVal), alphaColor);
342  return diffStat.ToString(CultureInfo.InvariantCulture); /* + Lang.tip[39].Value;*/
343  //if (num12 < 0.0)
344  //{
345  // array3[num4] = true;
346  //}
347  }

+ Here is the caller graph for this function:

void Loot.LootModItem.InvalidateRolls ( )
private

Definition at line 47 of file LootModItem.cs.

References Loot.LootModItem.Modifiers, and Loot.LootModItem.Rarity.

Referenced by Loot.LootModItem.Load().

48  {
49  Rarity = mod.GetNullModifierRarity();
50  Modifiers = mod.GetNullModifierPool();
51  }
ModifierRarity Rarity
Definition: LootModItem.cs:31
FiniteModifierPool Modifiers
Definition: LootModItem.cs:32

+ Here is the caller graph for this function:

override void Loot.LootModItem.Load ( Item  item,
TagCompound  tag 
)

Definition at line 174 of file LootModItem.cs.

References Loot.Api.Core.FiniteModifierPool.Apply(), Loot.LootModItem.HasRolled, Loot.LootModItem.InvalidateRolls(), Loot.Api.Core.ModifierRarity.Load(), Loot.Api.Core.ModifierPool.Load(), Loot.Api.Core.FiniteModifierPool.Modifiers, Loot.LootModItem.Modifiers, Loot.LootModItem.Rarity, Loot.LootModItem.SealedModifiers, and Loot.Api.Graphics.GraphicsGlobalItem.UpdateGraphicsEntities().

175  {
176  // enforce illegitimate rolls to go away (needed for earliest versions saves)
177  if (!item.IsModifierRollableItem())
178  {
179  InvalidateRolls();
180  }
181  else if (tag.ContainsKey("SaveVersion"))
182  {
183  int saveVersion = tag.GetInt("SaveVersion");
184  if (saveVersion < 14)
185  {
186  InvalidateRolls();
187  }
188  else
189  {
190  Rarity = ModifierRarityIO.Load(item, tag.GetCompound("ModifierRarity"));
191  Modifiers = ModifierPoolIO.Load(item, tag.GetCompound("ModifierPool"));
192  SealedModifiers = tag.GetBool("SealedModifiers");
193  HasRolled = tag.GetBool("HasRolled");
194  Modifiers.Apply(item);
196  }
197  }
198  }
static void UpdateGraphicsEntities(List< Modifier > modifiers, Item item)
This class is responsible for handling ShaderEntity and GlowmaskEntity that come from the Modifiers o...
virtual 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...
virtual void Load(Item item, TagCompound tag)
Allows modder to do custom loading here Use the given TagCompound to pull data you saved using Save(I...
readonly List< Modifier > Modifiers
Definition: ModifierPool.cs:19
ModifierRarity Rarity
Definition: LootModItem.cs:31
FiniteModifierPool Modifiers
Definition: LootModItem.cs:32
void InvalidateRolls()
Definition: LootModItem.cs:47

+ Here is the call graph for this function:

override void Loot.LootModItem.ModifyTooltips ( Item  item,
List< TooltipLine >  tooltips 
)

Will modify vanilla tooltips to add additional information for the affected item's modifiers

Definition at line 352 of file LootModItem.cs.

References Loot.Api.Core.ModifierRarity.Color, Loot.Hacks.CheatedItemHackGlobalItem.GetInfo(), Loot.LootModItem.GetPrefixNormString(), Loot.Api.Core.ModifierRarity.ItemPrefix, Loot.Api.Core.ModifierRarity.ItemSuffix, Loot.LootModItem.Modifiers, Loot.Api.Core.ModifierRarity.OverrideNameColor, Loot.LootModItem.Rarity, Loot.LootModItem.SealedModifiers, and Loot.Hacks.CheatedItemHackGlobalItem.ShouldBeIgnored().

353  {
354  var pool = Modifiers;
355  if (pool != null)
356  {
357  // the following part, recalculate the vanilla prefix tooltips
358  // this is because our mods modify the stats, which was never intended by vanilla, causing the differences to be innacurate and bugged
359 
360  // RECALC START
361  var vanillaTooltips = tooltips.Where(x => x.mod.Equals("Terraria")).ToArray();
362  var baseItem = new Item();
363  baseItem.netDefaults(item.netID);
364 
365  // the item with just the modifiers applied
366  // var poolItem = baseItem.CloneWithModdedDataFrom(item);
367  // GetItemInfo(poolItem)?.ModifierPool.ApplyModifiers(poolItem);
368 
369  // the item with just the prefix applied
370  var prefixItem = baseItem.Clone();
371  prefixItem.Prefix(item.prefix);
372 
373  try
374  {
375  foreach (var tooltipLine in vanillaTooltips)
376  {
377  double outNumber = 0d;
378  string newTooltipLine = tooltipLine.text;
379  Color? newColor = tooltipLine.overrideColor;
380  string tooltipEndText =
381  new string(tooltipLine.text
382  .Reverse()
383  .TakeWhile(x => !char.IsDigit(x))
384  .Reverse()
385  .ToArray());
386 
387  //private string[] _prefixTooltipLines = {
388  // "PrefixDamage", "PrefixSpeed", "PrefixCritChance", "PrefixUseMana", "PrefixSize",
389  // "PrefixShootSpeed", "PrefixKnockback", "PrefixAccDefense", "PrefixAccMaxMana",
390  // "PrefixAccCritChance", "PrefixAccDamage", "PrefixAccMoveSpeed", "PrefixAccMeleeSpeed"
391  // };
392 
393  if (tooltipLine.Name.Equals("PrefixDamage"))
394  {
395  newTooltipLine = baseItem.damage > 0
396  ? GetPrefixNormString(baseItem.damage, prefixItem.damage, ref outNumber, ref newColor)
397  : GetPrefixNormString(prefixItem.damage, baseItem.damage, ref outNumber, ref newColor);
398  }
399  else if (tooltipLine.Name.Equals("PrefixSpeed"))
400  {
401  newTooltipLine = baseItem.useAnimation <= 0
402  ? GetPrefixNormString(baseItem.useAnimation, prefixItem.useAnimation, ref outNumber, ref newColor)
403  : GetPrefixNormString(prefixItem.useAnimation, baseItem.useAnimation, ref outNumber, ref newColor);
404  }
405  else if (tooltipLine.Name.Equals("PrefixCritChance"))
406  {
407  outNumber = prefixItem.crit - baseItem.crit;
408  float defColorVal = Main.mouseTextColor / 255f;
409  int alphaColor = Main.mouseTextColor;
410  newTooltipLine = "";
411  if (outNumber >= 0)
412  {
413  newTooltipLine += "+";
414  newColor = new Color((byte)(120f * defColorVal), (byte)(190f * defColorVal), (byte)(120f * defColorVal), alphaColor);
415  }
416  else
417  {
418  newColor = new Color((byte)(190f * defColorVal), (byte)(120f * defColorVal), (byte)(120f * defColorVal), alphaColor);
419  }
420 
421  newTooltipLine += outNumber.ToString(CultureInfo.InvariantCulture);
422  }
423  else if (tooltipLine.Name.Equals("PrefixUseMana"))
424  {
425  if (baseItem.mana != 0)
426  {
427  float defColorVal = Main.mouseTextColor / 255f;
428  int alphaColor = Main.mouseTextColor;
429  newTooltipLine = GetPrefixNormString(baseItem.mana, prefixItem.mana, ref outNumber, ref newColor);
430  newColor = prefixItem.mana < baseItem.mana
431  ? new Color((byte)(120f * defColorVal), (byte)(190f * defColorVal), (byte)(120f * defColorVal), alphaColor)
432  : new Color((byte)(190f * defColorVal), (byte)(120f * defColorVal), (byte)(120f * defColorVal), alphaColor);
433  }
434  }
435  else if (tooltipLine.Name.Equals("PrefixSize"))
436  {
437  newTooltipLine = baseItem.scale > 0
438  ? GetPrefixNormString(baseItem.scale, prefixItem.scale, ref outNumber, ref newColor)
439  : GetPrefixNormString(prefixItem.scale, baseItem.scale, ref outNumber, ref newColor);
440  }
441  else if (tooltipLine.Name.Equals("PrefixShootSpeed"))
442  {
443  newTooltipLine = baseItem.shootSpeed > 0
444  ? GetPrefixNormString(baseItem.shootSpeed, prefixItem.shootSpeed, ref outNumber, ref newColor)
445  : GetPrefixNormString(prefixItem.shootSpeed, baseItem.shootSpeed, ref outNumber, ref newColor);
446  }
447  else if (tooltipLine.Name.Equals("PrefixKnockback"))
448  {
449  newTooltipLine = baseItem.knockBack > 0
450  ? GetPrefixNormString(baseItem.knockBack, prefixItem.knockBack, ref outNumber, ref newColor)
451  : GetPrefixNormString(prefixItem.knockBack, baseItem.knockBack, ref outNumber, ref newColor);
452  }
453  else
454  {
455  continue;
456  }
457 
458  int ttlI = tooltips.FindIndex(x => x.mod.Equals(tooltipLine.mod) && x.Name.Equals(tooltipLine.Name));
459  if (ttlI == -1)
460  {
461  continue;
462  }
463 
464  if (outNumber == 0d)
465  {
466  tooltips.RemoveAt(ttlI);
467  }
468  else
469  {
470  tooltips[ttlI].text = $"{newTooltipLine}{tooltipEndText}";
471  tooltips[ttlI].overrideColor = newColor;
472  }
473  }
474  }
475  catch (Exception e)
476  {
477  Loot.Logger.Error(
478  $"A problem occurred during modification of the item's tooltip." +
479  $"\nItem in question: {item.AffixName()}",
480  e);
481  }
482  // RECALC END
483 
484  // Modifies the tooltips, to insert generic mods data
485  int i = tooltips.FindIndex(x => x.mod == "Terraria" && x.Name == "ItemName");
486  if (i != -1)
487  {
488  var namelayer = tooltips[i];
489 
490  if (Rarity.ItemPrefix != null)
491  {
492  namelayer.text = $"{Rarity.ItemPrefix} {namelayer.text}";
493  }
494 
495  if (Rarity.ItemSuffix != null)
496  {
497  namelayer.text = $"{namelayer.text} {Rarity.ItemSuffix}";
498  }
499 
500  if (Rarity.OverrideNameColor != null)
501  {
502  namelayer.overrideColor = Rarity.OverrideNameColor;
503  }
504 
505  tooltips[i] = namelayer;
506  }
507 
508 
509  CheatedItemHackGlobalItem cheatedItemHackGlobalItem = CheatedItemHackGlobalItem.GetInfo(item);
510  bool isVanityIgnored = cheatedItemHackGlobalItem.ShouldBeIgnored(item, Main.LocalPlayer);
511  Color? inactiveColor = isVanityIgnored ? (Color?)Color.DarkSlateGray : null;
512  // Insert modifier rarity
513 
514  if (!(Rarity is NullModifierRarity))
515  {
516  i = tooltips.Count;
517  tooltips.Insert(i, new TooltipLine(mod, "Loot: Modifier:Rarity", $"[{Rarity.RarityName}]{(isVanityIgnored ? " [IGNORED]" : "")}")
518  {
519  overrideColor = inactiveColor ?? Rarity.Color * Main.inventoryScale
520  });
521  }
522 
523  i = tooltips.Count - 1;
524 
525  foreach (var modifier in pool.Modifiers)
526  {
527  foreach (var tt in modifier.GetTooltip().Build())
528  {
529  tooltips.Insert(++i, new TooltipLine(mod, $"Loot: Modifier:Line:{i}", $"{modifier.GetFormattedUniqueName()} {tt.Text}".TrimStart())
530  {
531  overrideColor = inactiveColor ?? (tt.Color ?? Color.White) * Main.inventoryScale
532  });
533  }
534  }
535 
536  if (SealedModifiers)
537  {
538  var ttl = new TooltipLine(mod, "Loot: Modifier:Sealed", "Modifiers cannot be changed")
539  {
540  overrideColor = inactiveColor ?? Color.Cyan
541  };
542  tooltips.Insert(++i, ttl);
543  }
544 
545  foreach (var e in pool.Modifiers)
546  {
547  e.ModifyTooltips(item, tooltips);
548  }
549  }
550  }
string GetPrefixNormString(float cpStat, float rStat, ref double num, ref Color?color)
Definition: LootModItem.cs:309
Can detect if an item was activated via cheats
ModifierRarity Rarity
Definition: LootModItem.cs:31
static CheatedItemHackGlobalItem GetInfo(Item item)
FiniteModifierPool Modifiers
Definition: LootModItem.cs:32
bool ShouldBeIgnored(Item item, Player player)
Defines a "Null" rarity which represents no rarity safely Cannot be rolled normally ...

+ Here is the call graph for this function:

override bool Loot.LootModItem.NeedsSaving ( Item  item)

Referenced by Loot.LootModItem.Save().

+ Here is the caller graph for this function:

override void Loot.LootModItem.NetReceive ( Item  item,
BinaryReader  reader 
)

Definition at line 218 of file LootModItem.cs.

References Loot.LootModItem.HasRolled, Loot.LootModItem.JustTinkerModified, Loot.Api.Core.FiniteModifierPool.Modifiers, Loot.LootModItem.Modifiers, Loot.Api.Core.ModifierRarity.NetReceive(), Loot.Api.Core.ModifierPool.NetReceive(), Loot.LootModItem.Rarity, and Loot.LootModItem.SealedModifiers.

219  {
220  bool hasPool = reader.ReadBoolean();
221 
222  if (hasPool)
223  {
224  Rarity = ModifierRarityIO.NetReceive(item, reader);
225  Modifiers = ModifierPoolIO.NetReceive(item, reader);
226  }
227 
228  HasRolled = reader.ReadBoolean();
229  SealedModifiers = reader.ReadBoolean();
230  JustTinkerModified = reader.ReadBoolean();
231 
232  item.UpdateModifiers(Modifiers.Modifiers);
233  }
virtual void NetReceive(Item item, BinaryReader reader)
Allows the modder to do custom NetReceive
readonly List< Modifier > Modifiers
Definition: ModifierPool.cs:19
ModifierRarity Rarity
Definition: LootModItem.cs:31
FiniteModifierPool Modifiers
Definition: LootModItem.cs:32
bool JustTinkerModified
Definition: LootModItem.cs:38
virtual void NetReceive(Item item, BinaryReader reader)
Allows the modder to do custom NetReceive

+ Here is the call graph for this function:

override void Loot.LootModItem.NetSend ( Item  item,
BinaryWriter  writer 
)

Definition at line 235 of file LootModItem.cs.

References Loot.LootModItem.HasRolled, Loot.LootModItem.JustTinkerModified, Loot.LootModItem.Modifiers, Loot.Api.Core.ModifierPool.NetSend(), Loot.LootModItem.Rarity, and Loot.LootModItem.SealedModifiers.

236  {
237  bool hasPool = Modifiers != null;
238  writer.Write(hasPool);
239 
240  if (hasPool)
241  {
242  ModifierRarityIO.NetSend(Rarity, item, writer);
243  ModifierPoolIO.NetSend(Modifiers, item, writer);
244  }
245 
246  writer.Write(HasRolled);
247  writer.Write(SealedModifiers);
248 
249  writer.Write(JustTinkerModified);
250  }
virtual void NetSend(Item item, BinaryWriter writer)
Allows modder to do custom NetSend here
ModifierRarity Rarity
Definition: LootModItem.cs:31
FiniteModifierPool Modifiers
Definition: LootModItem.cs:32
bool JustTinkerModified
Definition: LootModItem.cs:38

+ Here is the call graph for this function:

override TagCompound Loot.LootModItem.Save ( Item  item)

Definition at line 200 of file LootModItem.cs.

References Loot.LootModItem.HasRolled, Loot.LootModItem.Modifiers, Loot.LootModItem.NeedsSaving(), Loot.LootModItem.Rarity, and Loot.LootModItem.SealedModifiers.

201  {
202  TagCompound tag = new TagCompound
203  {
204  // SaveVersion saved since SaveVersion 2, version 1 not present
205  {"SaveVersion", SAVE_VERSION},
206  {"SealedModifiers", SealedModifiers},
207  {"HasRolled", HasRolled},
208  {"ModifierRarity", ModifierRarityIO.Save(item, Rarity)},
209  {"ModifierPool", ModifierPoolIO.Save(item, Modifiers)}
210  };
211 
212  return tag;
213  }
ModifierRarity Rarity
Definition: LootModItem.cs:31
FiniteModifierPool Modifiers
Definition: LootModItem.cs:32
const int SAVE_VERSION
Definition: LootModItem.cs:23

+ Here is the call graph for this function:

Member Data Documentation

override bool Loot.LootModItem.CloneNewInstances => true

Definition at line 29 of file LootModItem.cs.

override bool Loot.LootModItem.InstancePerEntity => true

Definition at line 28 of file LootModItem.cs.

const int Loot.LootModItem.SAVE_VERSION = 14
private

Definition at line 23 of file LootModItem.cs.

Property Documentation

bool Loot.LootModItem.HasRolled
getset
bool Loot.LootModItem.IsActivated
getset

Keeps track of if the particular item was activated ('delegated') Specific usecase see CursedEffect and modifier

Definition at line 45 of file LootModItem.cs.

Referenced by Loot.Caching.ModifierCachePlayer.AddAttachItem(), Loot.Caching.ModifierCachePlayer.AddDetachItem(), and Loot.Modifiers.WeaponModifiers.CursedEffect.CurseHolding().

bool Loot.LootModItem.JustTinkerModified
getset

Definition at line 38 of file LootModItem.cs.

Referenced by Loot.LootModItem.NetReceive(), and Loot.LootModItem.NetSend().

bool Loot.LootModItem.SlottedInUI
getset