-
Notifications
You must be signed in to change notification settings - Fork 1
/
BuffPlayer.cs
480 lines (426 loc) · 18.8 KB
/
BuffPlayer.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
using Microsoft.Xna.Framework;
using PathOfModifiers.Affixes.Items;
using PathOfModifiers.ModNet.PacketHandlers;
using PathOfModifiers.Projectiles;
using System;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
namespace PathOfModifiers
{
public class BuffPlayer : ModPlayer
{
TimedValueInstanceCollection timedValueInstanceCollection;
int staticStrikeDamage;
int staticStrikeIntervalTicks;
int staticStrikeCurrentInterval;
int staticStrikeTimeLeft;
float moltenShellDustAngle;
int moltenShellStoredDamage;
int moltenShellTimeLeft;
int noManaCostTimeLeft;
int knockbackImmunityTimeLeft;
float weaponMoveSpeedValue;
float weaponMoveSpeedTimeLeft;
float greavesMoveSpeedValue;
float greavesMoveSpeedTimeLeft;
public override void Initialize()
{
timedValueInstanceCollection = new TimedValueInstanceCollection();
}
public override void ModifyHurt(ref Player.HurtModifiers modifiers)
{
var damage = modifiers.FinalDamage;
if (modifiers.PvP)
{
var source_player_index = modifiers.DamageSource.SourcePlayerIndex;
var source_player = Main.player[source_player_index].GetModPlayer<BuffPlayer>();
damage = source_player.ChillModifyDamageDealt(damage);
}
damage = ShockModifyDamageTaken(damage);
modifiers.FinalDamage = damage;
}
public override void PostHurt(Player.HurtInfo info)
{
if (moltenShellTimeLeft > 0)
{
moltenShellStoredDamage += info.Damage;
}
}
public override void ResetEffects()
{
timedValueInstanceCollection.ResetEffects();
}
public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers)
{
var damage = ChillModifyDamageDealt(modifiers.FinalDamage);
modifiers.FinalDamage = damage;
}
public override void PostUpdateEquips()
{
var affixPlayer = Player.GetModPlayer<ItemPlayer>();
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.DodgeChance), out var dodgeChances))
{
affixPlayer.dodgeChance += dodgeChances.totalValue;
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.MoveSpeed), out var moveSpeeds))
{
affixPlayer.moveSpeed += moveSpeeds.totalValue;
}
if (greavesMoveSpeedTimeLeft > 0)
{
affixPlayer.moveSpeed += greavesMoveSpeedValue;
}
if (weaponMoveSpeedTimeLeft > 0)
{
affixPlayer.moveSpeed += weaponMoveSpeedValue;
}
if (moltenShellTimeLeft > 0)
{
affixPlayer.damageTaken += -0.1f;
if (Main.GameUpdateCount % 2 == 0)
{
for (int i = 0; i < 3; i++)
{
Vector2 dustPosition = Player.Center + new Vector2(0, 32).RotatedBy(moltenShellDustAngle + (2.095f * i));
Dust.NewDustPerfect(dustPosition, DustType<Dusts.MoltenShell>(), Velocity: Vector2.Zero, Scale: 2f);
Dust.NewDustPerfect(dustPosition, DustType<Dusts.FireDebris>(), Scale: 1.5f);
}
moltenShellDustAngle += 0.2f;
}
}
if (knockbackImmunityTimeLeft > 0)
{
Player.noKnockback = true;
}
}
public override void UpdateBadLifeRegen()
{
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))
{
int maxDps = (int)Math.Round(Player.statLifeMax2 * 0.01f);
totalDPS += Math.Min(burningAirs.totalValue, maxDps);
}
if (totalDPS > 0)
{
int totalDamage = (int)Math.Round(totalDPS * Buffs.DamageOverTime.damageMultiplierHalfSecond);
Player.lifeRegenTime = 0;
if (Player.lifeRegen > 0)
{
Player.lifeRegen = 0;
}
Player.lifeRegen -= totalDamage;
}
}
public override void PostNurseHeal(NPC nurse, int health, bool removeDebuffs, int price)
{
if (removeDebuffs)
{
timedValueInstanceCollection.RemoveInstances(typeof(TimedValueInstanceCollection.InstanceType.Bleed));
timedValueInstanceCollection.RemoveInstances(typeof(TimedValueInstanceCollection.InstanceType.Poison));
timedValueInstanceCollection.RemoveInstances(typeof(TimedValueInstanceCollection.InstanceType.Shock));
timedValueInstanceCollection.RemoveInstances(typeof(TimedValueInstanceCollection.InstanceType.Ignite));
timedValueInstanceCollection.RemoveInstances(typeof(TimedValueInstanceCollection.InstanceType.Chill));
}
}
public override void PreUpdate()
{
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Bleed), out var bleeds))
{
if (bleeds.totalValue > 0)
{
PoMEffectHelper.Bleed(Player.Center);
}
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Poison), out var poisons))
{
if (poisons.totalValue > 0)
{
PoMEffectHelper.Poison(Player.position, Player.width, Player.height);
}
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Ignite), out var ignites))
{
if (ignites.totalValue > 0)
{
PoMEffectHelper.Ignite(Player.position, Player.width, Player.height);
}
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Shock), out var shocks))
{
if (shocks.totalValue > 0)
{
PoMEffectHelper.Shock(Player.position, Player.width, Player.height);
}
}
if (timedValueInstanceCollection.instances.TryGetValue(typeof(TimedValueInstanceCollection.InstanceType.Chill), out var chills))
{
if (chills.totalValue > 0)
{
PoMEffectHelper.Chill(Player.position, Player.width, Player.height);
}
}
if (staticStrikeTimeLeft > 0)
{
staticStrikeCurrentInterval++;
if (staticStrikeCurrentInterval >= staticStrikeIntervalTicks)
{
if (Player.whoAmI == Main.myPlayer)
{
Projectile.NewProjectile(
Player.GetSource_FromThis(),
position: Player.Center,
velocity: Vector2.Zero,
Type: ProjectileType<StaticStrike>(),
Damage: staticStrikeDamage,
KnockBack: 0,
Owner: Player.whoAmI);
}
staticStrikeCurrentInterval = 0;
}
staticStrikeTimeLeft--;
}
if (greavesMoveSpeedTimeLeft > 0)
{
if (greavesMoveSpeedValue > 0)
{
PoMEffectHelper.MoveSpeed(Player);
}
greavesMoveSpeedTimeLeft--;
}
if (weaponMoveSpeedTimeLeft > 0)
{
if (weaponMoveSpeedTimeLeft > 0)
{
PoMEffectHelper.MoveSpeed(Player);
}
weaponMoveSpeedTimeLeft--;
}
if (moltenShellTimeLeft > 0)
{
moltenShellTimeLeft--;
if (moltenShellTimeLeft <= 0)
{
PlayMoltenShellExplodeSound(Player);
if (Player.whoAmI == Main.myPlayer)
{
Projectile.NewProjectile(
Player.GetSource_FromThis(),
Player.Center,
Vector2.Zero,
ProjectileType<MoltenShellExplosion>(),
moltenShellStoredDamage,
5,
Player.whoAmI,
moltenShellStoredDamage / (float)Player.statLifeMax2);
moltenShellStoredDamage = 0;
}
}
}
if (noManaCostTimeLeft > 0)
{
noManaCostTimeLeft--;
}
if (knockbackImmunityTimeLeft > 0)
{
knockbackImmunityTimeLeft--;
}
}
public override void ModifyManaCost(Item item, ref float reduce, ref float mult)
{
if (noManaCostTimeLeft > 0)
{
mult = -10f;
}
}
public void AddBleedBuff(Player player, int dps, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.Bleed), dps, durationTicks);
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.SendAddBleedBuffPlayer(player.whoAmI, dps, durationTicks);
}
}
public void AddPoisonBuff(Player player, int dps, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.Poison), dps, durationTicks);
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.SendAddPoisonBuffPlayer(player.whoAmI, dps, durationTicks);
}
}
public void AddMoveSpeedBuff(Player player, float speedBoost, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.MoveSpeed), speedBoost, durationTicks);
if (Main.netMode != NetmodeID.SinglePlayer && syncMP)
{
BuffPacketHandler.SendAddMoveSpeedBuffPlayer(player.whoAmI, speedBoost, durationTicks);
}
}
public void AddWeaponMoveSpeedBuff(Player player, float speedBoost, int durationTicks, bool syncMP = true)
{
weaponMoveSpeedValue = speedBoost;
weaponMoveSpeedTimeLeft = durationTicks;
if (Main.netMode != NetmodeID.SinglePlayer && syncMP)
{
BuffPacketHandler.SendAddWeaponMoveSpeedBuffPlayer(player.whoAmI, speedBoost, durationTicks);
}
}
public void AddGreavesMoveSpeedBuff(Player player, float speedBoost, int durationTicks, bool syncMP = true)
{
greavesMoveSpeedValue = speedBoost;
greavesMoveSpeedTimeLeft = durationTicks;
if (Main.netMode != NetmodeID.SinglePlayer && syncMP)
{
BuffPacketHandler.SendAddGreavesMoveSpeedBuffPlayer(player.whoAmI, speedBoost, durationTicks);
}
}
public void AddBurningAirBuff(Player player, int dps)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.BurningAir), dps, 2);
}
public void AddIgnitedBuff(Player player, int dps, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.Ignite), dps, durationTicks);
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.SendAddIgnitedBuffPlayer(player.whoAmI, dps, durationTicks);
}
}
public void AddShockedAirBuff(Player player, float multiplier)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.ShockedAir), multiplier, 2);
}
public void AddShockedBuff(Player player, float multiplier, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.Shock), multiplier, durationTicks);
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.SendAddShockedBuffPlayer(player.whoAmI, multiplier, durationTicks);
}
}
public void AddChilledBuff(Player player, float multiplier, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.Chill), multiplier, durationTicks);
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.SendAddChilledBuffPlayer(player.whoAmI, multiplier, durationTicks);
}
}
public void AddChilledAirBuff(Player player, float multiplier)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.ChilledAir), multiplier, 2);
}
public void AddStaticStrikeBuff(Player player, int damage, int intervalTicks, int durationTicks, bool syncMP = true)
{
if (staticStrikeTimeLeft <= 0)
{
PlayGainStaticStrikeSound(player);
staticStrikeCurrentInterval = 0;
}
staticStrikeDamage = damage;
staticStrikeIntervalTicks = intervalTicks;
staticStrikeTimeLeft = durationTicks;
if (syncMP && Main.netMode != NetmodeID.SinglePlayer)
{
BuffPacketHandler.SendAddStaticStrikeBuffPlayer(player.whoAmI, damage, intervalTicks, durationTicks);
}
}
public void AddDodgeChanceBuff(Player player, float chance, int durationTicks, bool syncMP = true)
{
timedValueInstanceCollection.AddInstance(typeof(TimedValueInstanceCollection.InstanceType.DodgeChance), chance, durationTicks);
if (syncMP && Main.netMode == NetmodeID.MultiplayerClient)
{
BuffPacketHandler.SendAddDodgeChanceBuffPlayer(player.whoAmI, chance, durationTicks);
}
}
public void AddNoManaCostBuff(Player player, int durationTicks, bool syncMP = true)
{
if (durationTicks > noManaCostTimeLeft)
{
noManaCostTimeLeft = durationTicks;
if (syncMP && Main.netMode == NetmodeID.MultiplayerClient)
{
BuffPacketHandler.SendAddNoManaCostBuffPlayer(player.whoAmI, durationTicks);
}
}
}
public void AddKnockbackImmunityBuff(Player player, int durationTicks, bool syncMP = true)
{
if (durationTicks > knockbackImmunityTimeLeft)
{
knockbackImmunityTimeLeft = durationTicks;
if (syncMP && Main.netMode == NetmodeID.MultiplayerClient)
{
BuffPacketHandler.SendAddKnockbackImmunityBuffPlayer(player.whoAmI, durationTicks);
}
}
}
public void AddMoltenShellBuff(Player player, int durationTicks, bool syncMP = true)
{
if (durationTicks > moltenShellTimeLeft)
{
PlayGainMoltenShellSound(player);
moltenShellTimeLeft = durationTicks;
if (syncMP && Main.netMode == NetmodeID.MultiplayerClient)
{
BuffPacketHandler.SendAddMoltenShellBuffPlayer(player.whoAmI, durationTicks);
}
}
}
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;
}
void PlayGainStaticStrikeSound(Player player)
{
SoundEngine.PlaySound(SoundID.Item92.WithVolumeScale(1f).WithPitchOffset(0.3f), player.Center);
}
void PlayGainMoltenShellSound(Player player)
{
SoundEngine.PlaySound(SoundID.Item45.WithVolumeScale(1f).WithPitchOffset(0.3f), player.Center);
}
void PlayMoltenShellExplodeSound(Player player)
{
SoundEngine.PlaySound(SoundID.Item62.WithVolumeScale(1f).WithPitchOffset(0.3f), player.Center);
}
}
}