-
Notifications
You must be signed in to change notification settings - Fork 1
/
BuffNPC.cs
203 lines (183 loc) · 8.38 KB
/
BuffNPC.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using PathOfModifiers.Buffs;
using PathOfModifiers.ModNet.PacketHandlers;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace PathOfModifiers
{
public class BuffNPC : GlobalNPC
{
public override bool InstancePerEntity => true;
TimedValueInstanceCollection timedValueInstanceCollection = new TimedValueInstanceCollection();
public void AddBleedBuff(NPC npc, int dps, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.Bleed), dps, durationTicks);
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.CSendAddBleedBuffNPC(npc.whoAmI, dps, durationTicks);
}
}
public void AddPoisonBuff(NPC npc, int dps, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.Poison), dps, durationTicks);
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.CSendAddPoisonBuffNPC(npc.whoAmI, dps, durationTicks);
}
}
public void AddBurningAirBuff(NPC npc, int dps)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.BurningAir), dps, 2);
}
public void AddIgnitedBuff(NPC npc, int dps, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.Ignite), dps, durationTicks);
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.SendAddIgnitedBuffNPC(npc.whoAmI, dps, durationTicks);
}
}
public void AddShockedAirBuff(NPC npc, float multiplier)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.ShockedAir), multiplier, 2);
}
public void AddShockedBuff(NPC npc, float multiplier, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.Shock), multiplier, durationTicks);
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.SendAddShockedBuffNPC(npc.whoAmI, multiplier, durationTicks);
}
}
public void AddChilledBuff(NPC npc, float multiplier, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.Chill), multiplier, durationTicks);
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.SendAddChilledBuffNPC(npc.whoAmI, multiplier, durationTicks);
}
}
public void AddChilledAirBuff(NPC npc, float multiplier)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.ChilledAir), multiplier, 2);
}
public override void ResetEffects(NPC npc)
{
timedValueInstanceCollection.ResetEffects();
}
public override void UpdateLifeRegen(NPC npc, ref int damage)
{
float totalDPS = 0;
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Bleed), out var bleeds))
{
totalDPS += bleeds.totalValue;
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Poison), out var poisons))
{
totalDPS += poisons.totalValue;
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Ignite), out var ignites))
{
totalDPS += ignites.totalValue;
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.BurningAir), out var burningAirs))
{
totalDPS += burningAirs.totalValue;
}
if (totalDPS > 0)
{
int totalDamage = (int)Math.Round(totalDPS * DamageOverTime.damageMultiplierHalfSecond);
if (npc.lifeRegen > 0)
{
npc.lifeRegen = 0;
}
npc.lifeRegen -= totalDamage;
}
if (npc.lifeRegen < 0)
{
damage = npc.lifeRegen / -4;
}
}
public override void AI(NPC npc)
{
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Bleed), out var bleeds))
{
if (bleeds.totalValue > 0)
{
PoMEffectHelper.Bleed(npc.Center);
}
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Poison), out var poisons))
{
if (poisons.totalValue > 0)
{
PoMEffectHelper.Poison(npc.position, npc.width, npc.height);
}
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Ignite), out var ignites))
{
if (ignites.totalValue > 0)
{
PoMEffectHelper.Ignite(npc.position, npc.width, npc.height);
}
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Shock), out var shocks))
{
if (shocks.totalValue > 0)
{
PoMEffectHelper.Shock(npc.position, npc.width, npc.height);
}
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Chill), out var chills))
{
if (chills.totalValue < 0)
{
PoMEffectHelper.Chill(npc.position, npc.width, npc.height);
}
}
}
public StatModifier ShockModifyDamageTaken(StatModifier damage)
{
float totalMultiplier = 1;
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Shock), out var shocks))
{
totalMultiplier += shocks.totalValue;
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.ShockedAir), out var shockedAirs))
{
totalMultiplier += shockedAirs.totalValue;
}
return damage * totalMultiplier;
}
public StatModifier ChillModifyDamageDealt(StatModifier damage)
{
float totalMultiplier = 1;
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Chill), out var chills))
{
totalMultiplier += chills.totalValue;
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.ChilledAir), out var chilledAirs))
{
totalMultiplier += chilledAirs.totalValue;
}
return damage * totalMultiplier;
}
public override void ModifyHitByItem(NPC npc, Player player, Item item, ref NPC.HitModifiers modifiers)
{
modifiers.FinalDamage = ShockModifyDamageTaken(modifiers.FinalDamage);
}
public override void ModifyHitByProjectile(NPC npc, Projectile projectile, ref NPC.HitModifiers modifiers)
{
modifiers.FinalDamage = ShockModifyDamageTaken(modifiers.FinalDamage);
}
public override void ModifyHitPlayer(NPC npc, Player target, ref Player.HurtModifiers modifiers)
{
modifiers.FinalDamage = ChillModifyDamageDealt(modifiers.FinalDamage);
}
public override void ModifyHitNPC(NPC npc, NPC target, ref NPC.HitModifiers modifiers)
{
modifiers.FinalDamage = ChillModifyDamageDealt(modifiers.FinalDamage);
}
}
}