Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
DamagePlusDaytime.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using System.IO;
3 using Loot.Api.Core;
4 using Loot.Modifiers.Base;
5 using Terraria;
6 using Terraria.ModLoader.IO;
7 
8 namespace Loot.Modifiers.WeaponModifiers
9 {
11  {
13  {
14  return base.GetTooltip()
15  .WithPositive($"+{Properties.RoundedPower}% damage during the {(_duringDay ? "day" : "night")}");
16  }
17 
19  {
20  return base.GetModifierProperties(item)
21  .WithMinMagnitude(5f)
22  .WithMaxMagnitude(15f)
23  .WithRollChance(2f);
24  }
25 
26  private bool _duringDay;
27 
28  public override void Roll(ModifierContext ctx, IEnumerable<Modifier> rolledModifiers)
29  {
30  base.Roll(ctx, rolledModifiers);
31  _duringDay = Main.rand.NextBool();
32  }
33 
34  // Here we showcase custom MP syncing
35 
36  public override void NetReceive(Item item, BinaryReader reader)
37  {
38  base.NetReceive(item, reader);
39  _duringDay = reader.ReadBoolean();
40  }
41 
42  public override void NetSend(Item item, BinaryWriter writer)
43  {
44  base.NetSend(item, writer);
45  writer.Write(_duringDay);
46  }
47 
48  // Here we showcase custom loading and saving for a modifier
49 
50  public override void Load(Item item, TagCompound tag)
51  {
52  base.Load(item, tag);
53  _duringDay = tag.GetBool("duringDay");
54  }
55 
56  public override void Save(Item item, TagCompound tag)
57  {
58  base.Save(item, tag);
59  tag.Add("duringDay", _duringDay);
60  }
61 
62  public override void ModifyWeaponDamage(Item item, Player player, ref float add, ref float mult, ref float flat)
63  {
64  base.ModifyWeaponDamage(item, player, ref add, ref mult, ref flat);
65  if (_duringDay && Main.dayTime || !_duringDay && !Main.dayTime)
66  {
67  add += Properties.RoundedPower / 100;
68  }
69  }
70  }
71 }
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...
override ModifierTooltipLine.ModifierTooltipBuilder GetTooltip()
override ModifierProperties.ModifierPropertiesBuilder GetModifierProperties(Item item)
override void NetReceive(Item item, BinaryReader reader)
override void ModifyWeaponDamage(Item item, Player player, ref float add, ref float mult, ref float flat)
override 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)
Defines a modifier that can roll on a weapon item You can use this class and add to CanRoll by callin...
Defines the properties of a modifier
Defines a tooltip line of a modifier A modifier can have multiple lines
override void NetSend(Item item, BinaryWriter writer)
override void Roll(ModifierContext ctx, IEnumerable< Modifier > rolledModifiers)
Allows modders to do something when the modifier is rolled in the given context The passed rolledModi...
override 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...