Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
DamageWithManaCost.cs
Go to the documentation of this file.
1 using System;
2 using System.Linq;
3 using Loot.Api.Core;
4 using Loot.Modifiers.Base;
5 using Terraria;
6 
7 namespace Loot.Modifiers.WeaponModifiers
8 {
10  {
12  {
13  return base.GetTooltip()
14  .WithPositive($"+{Properties.RoundedPower}% damage, but adds +{_manaCost} mana cost");
15  }
16 
18  {
19  return base.GetModifierProperties(item)
20  .WithMinMagnitude(5f)
21  .WithMaxMagnitude(15f);
22  }
23 
24  public override bool CanRoll(ModifierContext ctx)
25  {
26  return base.CanRoll(ctx)
27  && ctx.Method != ModifierContextMethod.SetupStartInventory
28  && ctx.Item.mana == 0;
29  }
30 
31  public override void ModifyWeaponDamage(Item item, Player player, ref float add, ref float mult, ref float flat)
32  {
33  base.ModifyWeaponDamage(item, player, ref add, ref mult, ref flat);
34  add += Properties.RoundedPower / 100f;
35  }
36 
37  public override bool CanUseItem(Item item, Player player)
38  {
39  return base.CanUseItem(item, player)
40  && player.statMana >= item.mana
41  && (item.useAmmo == 0 || player.inventory.Any(x => x.ammo == item.useAmmo));
42  }
43 
44  private int _manaCost;
45 
46  public override void Apply(Item item)
47  {
48  base.Apply(item);
49  _manaCost = Math.Max((int) (item.useTime * (float) item.useTime / GetMaxUseTime(item) / 10f), 1);
50  item.mana += _manaCost;
51  }
52 
53  private int GetMaxUseTime(Item item)
54  {
55  int number = 15;
56 
57  if (item.useTime <= 8)
58  {
59  return number;
60  }
61 
62  while (number <= 55)
63  {
64  if (item.useTime <= number)
65  {
66  return number;
67  }
68 
69  number += 5;
70  }
71 
72  return 56;
73  }
74  }
75 }
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 ModifierProperties.ModifierPropertiesBuilder GetModifierProperties(Item item)
override void ModifyWeaponDamage(Item item, Player player, ref float add, ref float mult, ref float flat)
ModifierContextMethod
Defines a method for a context in which a Modifier might be rolled Used in ModifierContext ...
Defines a modifier that can roll on a weapon item You can use this class and add to CanRoll by callin...
override void Apply(Item item)
Allows modders to do something when this modifier is applied If a modder needs ModPlayer hooks...
override bool CanRoll(ModifierContext ctx)
If this Modifier can roll at all in the given context Properties are available here, apart from magnitude and power
Defines the properties of a modifier
Defines a tooltip line of a modifier A modifier can have multiple lines
ModifierContextMethod Method
override ModifierTooltipLine.ModifierTooltipBuilder GetTooltip()
override bool CanUseItem(Item item, Player player)