Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
WeaponDebuffModifier.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using Loot.Api.Attributes;
4 using Loot.Api.Core;
5 using Loot.Api.Delegators;
6 using Terraria;
7 using Terraria.ID;
8 using Terraria.Localization;
9 using Terraria.ModLoader;
10 using static Loot.Api.Core.ModifierProperties;
11 using static Loot.Api.Core.ModifierTooltipLine;
12 
13 namespace Loot.Modifiers.Base
14 {
16  {
17  public List<(int type, int time, float chance)> DebuffChances = new List<(int type, int time, float chance)>();
18 
19  public override void OnInitialize()
20  {
21  DebuffChances = new List<(int type, int time, float chance)>();
22  }
23 
24  public override void ResetEffects()
25  {
26  DebuffChances.Clear();
27  }
28  }
29 
33  [UsesEffect(typeof(WeaponDebuffEffect))] // The attribute is inherited, which is nice
34  public abstract class WeaponDebuffModifier : WeaponModifier
35  {
36  public override ModifierTooltipBuilder GetTooltip()
37  {
38  return base.GetTooltip()
39  .WithPositive($"+{Properties.RoundedPower}% chance to inflict {GetBuffName()} for {RoundedBuffTime()}s");
40  }
41 
42  public override ModifierPropertiesBuilder GetModifierProperties(Item item)
43  {
44  return base.GetModifierProperties(item)
45  .WithMinMagnitude(5f)
46  .WithMinMagnitude(10f)
47  .WithRoundPrecision(1);
48  }
49 
50  private float RoundedBuffTime()
51  {
52  return (float) Math.Round((double) BuffTime / 60f, Properties.RoundPrecision);
53  }
54 
55  public abstract int BuffType { get; }
56  public abstract int BuffTime { get; }
57  public abstract float BuffInflictionChance { get; }
58 
59  private string GetBuffName()
60  {
61  if (BuffType >= BuffID.Count)
62  {
63  return BuffLoader.GetBuff(BuffType)?.DisplayName.GetTranslation(LanguageManager.Instance.ActiveCulture) ?? "null";
64  }
65 
66  return Lang.GetBuffName(BuffType);
67  }
68 
69  public override void OnHitNPC(Item item, Player player, NPC target, int damage, float knockBack, bool crit)
70  {
71  if (Main.rand.NextFloat() < Properties.RoundedPower / 100f * BuffInflictionChance)
72  {
73  target.AddBuff(BuffType, BuffTime);
74  }
75  }
76 
77  public override void OnHitPvp(Item item, Player player, Player target, int damage, bool crit)
78  {
79  if (Main.rand.NextFloat() < Properties.RoundedPower / 100f * BuffInflictionChance)
80  {
81  target.AddBuff(BuffType, BuffTime);
82  }
83  }
84 
85  // Required for minion/proj snapshotting
86  public override void HoldItem(Item item, Player player)
87  {
89  .DebuffChances
90  .Add((BuffType, BuffTime, Properties.RoundedPower / 100f * BuffInflictionChance));
91  }
92  }
93 }
override ModifierPropertiesBuilder GetModifierProperties(Item item)
A ModifierEffect signifies the effect of a modifier on a player It should house the implementation...
override void OnHitNPC(Item item, Player player, NPC target, int damage, float knockBack, bool crit)
override void OnHitPvp(Item item, Player player, Player target, int damage, bool crit)
static ModifierDelegatorPlayer GetPlayer(Player player)
Defines a modifier that can roll on a weapon item You can use this class and add to CanRoll by callin...
override ModifierTooltipBuilder GetTooltip()
Defines the properties of a modifier
Defines a tooltip line of a modifier A modifier can have multiple lines
override void HoldItem(Item item, Player player)
Defines a modifier that can inflict a debuff, applicable for weapons
override void ResetEffects()
Automatically called when the ModPlayer does its ResetEffects Also automatically called when the dele...
Holds player-entity data and handles it
override void OnInitialize()
Called when the ModPlayer initializes the effect