forked from Werebearguy/AssortedCrazyThings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssPlayer.cs
819 lines (703 loc) · 24.2 KB
/
AssPlayer.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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
using AssortedCrazyThings.Base;
using AssortedCrazyThings.Effects;
using AssortedCrazyThings.Items;
using AssortedCrazyThings.Items.Pets;
using AssortedCrazyThings.Items.Weapons;
using AssortedCrazyThings.Projectiles.Minions.CompanionDungeonSouls;
using AssortedCrazyThings.UI;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using Terraria;
using Terraria.DataStructures;
using Terraria.GameInput;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace AssortedCrazyThings
{
[Content(ConfigurationSystem.AllFlags, needsAllToFilter: true)]
//[LegacyName("AssPlayer")] Maybe rename later
public sealed class AssPlayer : AssPlayerBase
{
public delegate void SlainBossDelegate(Player player, int type);
public static event SlainBossDelegate OnSlainBoss; //Runs on all sides
public bool everburningCandleBuff = false;
public bool everburningCursedCandleBuff = false;
public bool everfrozenCandleBuff = false;
public bool everburningShadowflameCandleBuff = false;
public bool teleportHome = false;
public bool canTeleportHome = false;
public const short TeleportHomeTimerMax = 600; //in seconds //10 ingame minutes
public short teleportHomeTimer = 0; //gets saved when you relog so you can't cheese it
//TECHNICALLY NOT DEFENSE; YOU JUST GET 1 DAMAGE FROM EVERYTHING FOR A CERTAIN DURATION
public bool getDefense = false;
public bool canGetDefense = false;
public const short GetDefenseTimerMax = 600; //in seconds //10 ingame minutes
private const short GetDefenseDurationMax = 600; //in ticks //10 ingame seconds
public short getDefenseDuration = 0;
public short getDefenseTimer = 0; //gets saved when you relog so you can't cheese it
private int lastSlainBossTimerSeconds = -1; //-1: never slain a boss, otherwise starts at 0 and counts
private int lastSlainBossTimerInternal = 0; //Used for incrementing the seconds timer
private int lastSlainBossType = 0; //Does not save
public bool HasBossSlainTimer => lastSlainBossTimerSeconds != -1;
public bool needsNearbyEnemyNumber = false;
public int nearbyEnemyNumber = 0; //Impl of vanilla player.accThirdEyeNumber which works for all clients, shorter range
public int nearbyEnemyTimer = 0;
//soul minion stuff
public bool soulMinion = false;
public Item tempSoulMinion = null;
public SoulType selectedSoulMinionType = SoulType.Dungeon;
public bool slimePackMinion = false;
public byte selectedSlimePackMinionType = 0;
public byte nextMagicSlimeSlingMinion = 0;
//empowering buff stuff
public bool empoweringBuff = false;
private const short empoweringTimerMax = 60; //in seconds //one minute until it caps out (independent of buff duration)
private short empoweringTimer = 0;
public static float empoweringTotal = 0.5f; //this gets modified in AssWorld.PreUpdate()
public float empoweringStep = 0f;
//enhanced hunter potion stuff
public bool enhancedHunterBuff = false;
//cute slime spawn enable buff
public bool cuteSlimeSpawnEnable = false;
public bool soulSaviorArmor = false;
public bool wyvernCampfire = false;
public bool droneControllerMinion = false;
public const byte shieldDroneReductionMax = 35;
public const byte ShieldIncreaseAmount = 7;
public byte shieldDroneReduction = 0; //percentage * 100
public float shieldDroneLerpVisual = 0; //percentage
private bool drawEffectsCalledOnce = false;
public bool mouseoveredDresser = false;
/// <summary>
/// Bitfield. Use .HasFlag(DroneType.SomeType) to check if its there or not
/// </summary>
public DroneType droneControllerUnlocked = DroneType.None;
/// <summary>
/// Contains the DroneType value
/// </summary>
public DroneType selectedDroneControllerMinionType = DroneType.BasicLaser;
public override void ResetEffects()
{
everburningCandleBuff = false;
everburningCursedCandleBuff = false;
everfrozenCandleBuff = false;
everburningShadowflameCandleBuff = false;
teleportHome = false;
getDefense = false;
soulMinion = false;
tempSoulMinion = null;
slimePackMinion = false;
empoweringBuff = false;
enhancedHunterBuff = false;
cuteSlimeSpawnEnable = false;
soulSaviorArmor = false;
droneControllerMinion = false;
mouseoveredDresser = false;
needsNearbyEnemyNumber = false;
}
public bool RightClickPressed { get { return PlayerInput.Triggers.JustPressed.MouseRight; } }
public bool RightClickReleased { get { return PlayerInput.Triggers.JustReleased.MouseRight; } }
public bool LeftClickPressed { get { return PlayerInput.Triggers.JustPressed.MouseLeft; } }
public bool LeftClickReleased { get { return PlayerInput.Triggers.JustReleased.MouseLeft; } }
public override void SaveData(TagCompound tag)
{
tag.Add("teleportHomeWhenLowTimer", (int)teleportHomeTimer);
tag.Add("getDefenseTimer", (int)getDefenseTimer);
tag.Add("lastSlainBossTimerSeconds", (int)lastSlainBossTimerSeconds);
tag.Add("droneControllerUnlocked", (byte)droneControllerUnlocked);
}
public override void LoadData(TagCompound tag)
{
teleportHomeTimer = (short)tag.GetInt("teleportHomeWhenLowTimer");
getDefenseTimer = (short)tag.GetInt("getDefenseTimer");
string timerKey = "lastSlainBossTimerSeconds";
if (tag.ContainsKey(timerKey))
{
lastSlainBossTimerSeconds = tag.GetInt("lastSlainBossTimerSeconds");
}
droneControllerUnlocked = (DroneType)tag.GetByte("droneControllerUnlocked");
}
//TODO get rid of this, use manual packets since setting those values happens in a singular place
public override void clientClone(ModPlayer clientClone)
{
AssPlayer clone = clientClone as AssPlayer;
clone.shieldDroneReduction = shieldDroneReduction;
//Needs syncing because spawning drone parts depends on this serverside (See GeneralGlobalNPC.NPCLoot)
clone.droneControllerUnlocked = droneControllerUnlocked;
}
public override void SendClientChanges(ModPlayer clientPlayer)
{
AssPlayer clone = clientPlayer as AssPlayer;
if (clone.shieldDroneReduction != shieldDroneReduction ||
clone.droneControllerUnlocked != droneControllerUnlocked)
{
SendClientChangesPacket();
}
}
/// <summary>
/// Things that are sent to the server that are needed on-change
/// </summary>
public void SendClientChangesPacket(int toClient = -1, int ignoreClient = -1)
{
if (Main.netMode != NetmodeID.SinglePlayer)
{
ModPacket packet = Mod.GetPacket();
packet.Write((byte)AssMessageType.ClientChangesAssPlayer);
packet.Write((byte)Player.whoAmI);
packet.Write((byte)shieldDroneReduction);
packet.Write((byte)droneControllerUnlocked);
packet.Send(toClient, ignoreClient);
}
}
public override void SyncPlayer(int toWho, int fromWho, bool newPlayer)
{
ModPacket packet = Mod.GetPacket();
packet.Write((byte)AssMessageType.SyncAssPlayer);
packet.Write((byte)Player.whoAmI);
//Actual data here
packet.Write((byte)shieldDroneReduction);
packet.WriteVarInt(lastSlainBossTimerSeconds);
packet.WriteVarInt(lastSlainBossType);
packet.Send(toWho, fromWho);
}
public void ReceiveSyncPlayer(BinaryReader reader)
{
shieldDroneReduction = reader.ReadByte();
lastSlainBossTimerSeconds = reader.ReadVarInt();
lastSlainBossType = reader.ReadVarInt();
}
public override void OnEnterWorld(Player player)
{
SendClientChangesPacket();
}
/// <summary>
/// Resets the empowering timer from the Empowering Buff, spawns dust, sends sync
/// </summary>
public void ResetEmpoweringTimer(bool fromServer = false)
{
if (empoweringBuff && !Player.HasBuff(BuffID.ShadowDodge))
{
for (int i = 0; i < empoweringTimer; i++)
{
Dust dust = Dust.NewDustPerfect(Player.Center, 135, new Vector2(Main.rand.NextFloat(-3f, 3f), Main.rand.NextFloat(-3f, 3f)) + (new Vector2(Main.rand.Next(-1, 1), Main.rand.Next(-1, 1)) * ((6 * empoweringTimer) / empoweringTimerMax)), 26, Color.White, Main.rand.NextFloat(1.5f, 2.4f));
dust.noLight = true;
dust.noGravity = true;
dust.fadeIn = Main.rand.NextFloat(1f, 2.3f);
}
empoweringTimer = 0;
if (Main.netMode == NetmodeID.MultiplayerClient && !fromServer)
{
ModPacket packet = Mod.GetPacket();
packet.Write((byte)AssMessageType.ResetEmpoweringTimerpvp);
packet.Write((byte)Player.whoAmI);
packet.Send(); //send to server
}
}
}
/// <summary>
/// Decreases damage based on current shield level from the Shield Drone, spawns dust
/// </summary>
/// <param name="damage"></param>
public void DecreaseDroneShield(ref int damage)
{
if (shieldDroneReduction > 0)
{
for (int i = 0; i < shieldDroneReduction / 2; i++)
{
Dust dust = Dust.NewDustPerfect(Player.Center, 135, new Vector2(Main.rand.NextFloat(-3f, 3f), Main.rand.NextFloat(-3f, 3f)) + new Vector2(Main.rand.Next(-1, 1), Main.rand.Next(-1, 1)), 26, Color.White, Main.rand.NextFloat(1.5f, 2.4f));
dust.noLight = true;
dust.noGravity = true;
dust.fadeIn = Main.rand.NextFloat(1f, 2.3f);
}
damage = (int)(damage * ((100 - shieldDroneReduction) / 100f));
if (Main.netMode != NetmodeID.Server && Main.myPlayer == Player.whoAmI) shieldDroneReduction -= ShieldIncreaseAmount; //since this is only set clientside by the projectile and synced by packets
}
}
/// <summary>
/// Sets the isTemp on the projectile so it behaves differently
/// </summary>
private void PreSyncSoulTemp(Projectile proj)
{
if (!ContentConfig.Instance.Bosses)
{
return;
}
if (proj.ModProjectile is CompanionDungeonSoulMinionBase soul)
{
soul.isTemp = true;
}
}
/// <summary>
/// Spawns the temporary soul when wearing the accessory that allows it
/// </summary>
private void SpawnSoulTemp()
{
if (!ContentConfig.Instance.Bosses)
{
return;
}
if (tempSoulMinion != null && !tempSoulMinion.IsAir && Player.whoAmI == Main.myPlayer)
{
bool checkIfAlive = false;
int spawnedType = Main.hardMode ? ModContent.ProjectileType<CompanionDungeonSoulPostWOFMinion>() : ModContent.ProjectileType<CompanionDungeonSoulPreWOFMinion>();
int spawnedDamage = Main.hardMode ? (int)(EverhallowedLantern.BaseDmg * 1.1f * 2f) : ((EverhallowedLantern.BaseDmg / 2 - 1) * 2);
for (int i = 0; i < Main.maxProjectiles; i++)
{
if (Main.projectile[i].active && Main.projectile[i].owner == Player.whoAmI && Main.projectile[i].type == spawnedType)
{
if (Main.projectile[i].minionSlots == 0f) //criteria for temp, is set by isTemp
{
checkIfAlive = true;
break;
}
}
}
if (!checkIfAlive)
{
AssUtils.NewProjectile(Player.GetSource_Accessory(tempSoulMinion), Player.Center.X, Player.Center.Y, -Player.velocity.X, Player.velocity.Y - 6f, spawnedType, spawnedDamage, EverhallowedLantern.BaseKB, preSync: PreSyncSoulTemp);
}
}
}
/// <summary>
/// Upon Soul Harvester death, convert all inert souls in inventory
/// </summary>
public void ConvertInertSoulsInventory()
{
if (!ContentConfig.Instance.Bosses)
{
return;
}
//this gets called once on server side for all players, and then each player calls it on itself client side
int tempStackCount;
int itemTypeOld = ModContent.ItemType<CaughtDungeonSoul>();
int itemTypeNew = ModContent.ItemType<CaughtDungeonSoulFreed>(); //version that is used in crafting
Item[][] inventoryArray = { Player.inventory, Player.bank.item, Player.bank2.item, Player.bank3.item, Player.bank4.item }; //go though player inv
for (int y = 0; y < inventoryArray.Length; y++)
{
for (int e = 0; e < inventoryArray[y].Length; e++)
{
Item item = inventoryArray[y][e];
if (item.type == itemTypeOld) //find inert soul
{
tempStackCount = item.stack;
item.SetDefaults(itemTypeNew); //override with awakened
item.stack = tempStackCount;
}
}
}
//trash slot
Item trashItem = Player.trashItem;
if (trashItem.type == itemTypeOld)
{
tempStackCount = trashItem.stack;
trashItem.SetDefaults(itemTypeNew);
trashItem.stack = tempStackCount;
}
//mouse item
Item mouseItem = Main.mouseItem;
if (Main.netMode != NetmodeID.Server && mouseItem.type == itemTypeOld)
{
tempStackCount = mouseItem.stack;
mouseItem.SetDefaults(itemTypeNew);
mouseItem.stack = tempStackCount;
}
}
private void UpdateTeleportHomeWhenLow()
{
//this code runs even when the accessory is not equipped
canTeleportHome = teleportHomeTimer <= 0;
if (!canTeleportHome && Main.GameUpdateCount % 60 == 59)
{
teleportHomeTimer--;
}
}
private void UpdateGetDefenseWhenLow()
{
//this code runs even when the accessory is not equipped
canGetDefense = getDefenseTimer <= 0;
if (!canGetDefense && Main.GameUpdateCount % 60 == 59)
{
getDefenseTimer--;
}
if (getDefenseDuration != 0)
{
getDefenseDuration--;
}
}
/// <summary>
/// Sets some variables related to the Empowering Buff
/// </summary>
private void Empower()
{
if (empoweringBuff)
{
if (Main.GameUpdateCount % 60 == 0)
{
if (empoweringTimer < empoweringTimerMax)
{
empoweringTimer++;
empoweringStep = (empoweringTimer * empoweringTotal) / empoweringTimerMax;
}
}
}
else
{
empoweringStep = 0f;
empoweringTimer = 0;
}
}
private bool GetDefense(double damage)
{
if (getDefense)
{
if (canGetDefense)
{
Player.statLife += (int)damage;
Player.AddBuff(BuffID.RapidHealing, 600);
CombatText.NewText(Player.getRect(), CombatText.HealLife, "Defense increased");
getDefenseTimer = GetDefenseTimerMax;
getDefenseDuration = GetDefenseDurationMax;
return false;
}
}
return true;
}
private bool TeleportHome(double damage)
{
if (teleportHome)
{
if (canTeleportHome && Player.whoAmI == Main.myPlayer)
{
Player.RemoveAllGrapplingHooks();
//inserted before player.Spawn()
Player.statLife += (int)damage;
Player.Spawn(PlayerSpawnContext.RecallFromItem);
for (int i = 0; i < 70; i++)
{
Dust.NewDust(Player.position, Player.width, Player.height, 15, 0f, 0f, 150, default(Color), 1.5f);
}
//end
Player.AddBuff(BuffID.RapidHealing, 300, false);
NetMessage.SendData(MessageID.PlayerControls, number: Player.whoAmI);
teleportHomeTimer = TeleportHomeTimerMax;
return false;
}
}
return true;
}
private void ApplyCandleDebuffs(Entity victim)
{
if (victim is NPC npc)
{
if (everburningCandleBuff) npc.AddBuff(BuffID.OnFire, 120);
if (everburningCursedCandleBuff) npc.AddBuff(BuffID.CursedInferno, 120);
if (everfrozenCandleBuff) npc.AddBuff(BuffID.Frostburn, 120);
if (everburningShadowflameCandleBuff) npc.AddBuff(BuffID.ShadowFlame, 60);
}
//else if (victim is Player)
}
#region CircleUI
/// <summary>
/// Contains a list of CircleUIHandlers that are used in CircleUIStart/End in Mod
/// </summary>
public List<CircleUIHandler> CircleUIList;
public override void Initialize()
{
teleportHome = false;
teleportHomeTimer = 0;
getDefense = false;
getDefenseDuration = 0;
getDefenseTimer = 0;
lastSlainBossTimerSeconds = -1;
tempSoulMinion = null;
selectedSoulMinionType = SoulType.Dungeon;
selectedSlimePackMinionType = 0;
nextMagicSlimeSlingMinion = 0;
empoweringTimer = 0;
empoweringStep = 0f;
shieldDroneReduction = 0;
shieldDroneLerpVisual = 0;
drawEffectsCalledOnce = false;
//needs to call new List() since Initialize() is called per player in the player select screen
CircleUIList = new List<CircleUIHandler>();
if (ContentConfig.Instance.Weapons)
{
CircleUIList.AddRange(new List<CircleUIHandler>
{
new CircleUIHandler(
triggerItem: ModContent.ItemType<SlimeHandlerKnapsack>(),
condition: () => true,
uiConf: SlimeHandlerKnapsack.GetUIConf,
onUIStart: () => selectedSlimePackMinionType,
onUIEnd: delegate
{
selectedSlimePackMinionType = (byte)CircleUI.returned;
AssUtils.UIText("Selected: " + (selectedSlimePackMinionType == 0 ? "Default" : (selectedSlimePackMinionType == 1 ? "Assorted" : "Spiked")), CombatText.HealLife);
},
triggerLeft: false
),
new CircleUIHandler(
triggerItem: ModContent.ItemType<DroneController>(),
condition: () => true,
uiConf: DroneController.GetUIConf,
onUIStart: delegate
{
if (Utils.IsPowerOfTwo((int)selectedDroneControllerMinionType))
{
return (int)Math.Log((int)selectedDroneControllerMinionType, 2);
}
return 0;
},
onUIEnd: delegate
{
selectedDroneControllerMinionType = (DroneType)(byte)Math.Pow(2, CircleUI.returned);
AssUtils.UIText("Selected: " + DroneController.GetDroneData(selectedDroneControllerMinionType).Name, CombatText.HealLife);
},
triggerLeft: false
)}
);
}
if (ContentConfig.Instance.Bosses)
{
CircleUIList.Add(new CircleUIHandler(
triggerItem: ModContent.ItemType<EverhallowedLantern>(),
condition: () => true,
uiConf: EverhallowedLantern.GetUIConf,
onUIStart: delegate
{
if (Utils.IsPowerOfTwo((int)selectedSoulMinionType))
{
return (int)Math.Log((int)selectedSoulMinionType, 2);
}
return 0;
},
onUIEnd: delegate
{
selectedSoulMinionType = (SoulType)(byte)Math.Pow(2, CircleUI.returned);
AssUtils.UIText("Selected: " + EverhallowedLantern.GetSoulData(selectedSoulMinionType).Name, CombatText.HealLife);
},
triggerLeft: false
));
}
// after filling the list, set the trigger list
for (int i = 0; i < CircleUIList.Count; i++)
{
CircleUIList[i].AddTriggers();
}
}
#endregion
/// <summary>
/// Get proper SpriteEffects flags based on player status
/// </summary>
private static SpriteEffects GetSpriteEffects(Player player)
{
if (player.gravDir == 1f)
{
if (player.direction == 1)
{
return SpriteEffects.None;
}
else
{
return SpriteEffects.FlipHorizontally;
}
}
else
{
if (player.direction == 1)
{
return SpriteEffects.FlipVertically;
}
else
{
return SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically;
}
}
}
public void SlainBoss(int type)
{
lastSlainBossTimerSeconds = 0;
lastSlainBossType = type;
OnSlainBoss?.Invoke(Player, type);
if (Main.netMode == NetmodeID.Server)
{
ModPacket packet = Mod.GetPacket();
packet.Write((byte)AssMessageType.SlainBoss);
packet.WriteVarInt(lastSlainBossType);
packet.Send(Player.whoAmI);
}
}
public bool HasSlainBossSecondsAgo(int timeInSeconds)
{
return HasBossSlainTimer && lastSlainBossTimerSeconds < timeInSeconds;
}
public void UpdateSlainBossTimer()
{
if (HasBossSlainTimer)
{
lastSlainBossTimerInternal++;
if (lastSlainBossTimerInternal >= 60)
{
lastSlainBossTimerInternal = 0;
lastSlainBossTimerSeconds++;
}
}
}
public void UpdateNearbyEnemies()
{
float distSQ = 600 * 600;
if (nearbyEnemyTimer == 0)
{
nearbyEnemyNumber = 0;
nearbyEnemyTimer = 15;
for (int l = 0; l < Main.maxNPCs; l++)
{
NPC npc = Main.npc[l];
if (npc.active && !npc.friendly && npc.damage > 0 && npc.lifeMax > 5 && !npc.dontCountMe && (npc.Center - Player.Center).LengthSquared() < distSQ)
{
nearbyEnemyNumber++;
}
}
}
else
{
nearbyEnemyTimer--;
}
}
public override void DrawEffects(PlayerDrawSet drawInfo, ref float r, ref float g, ref float b, ref float a, ref bool fullBright)
{
Player drawPlayer = drawInfo.drawPlayer;
if (!drawEffectsCalledOnce)
{
drawEffectsCalledOnce = true;
}
else
{
return;
}
if (Main.gameMenu) return;
//Other code
//if (!PlayerLayer.MiscEffectsBack.visible) return;
if (shieldDroneReduction > 0)
{
Color outer = Color.White;
Color inner = new Color(0x03, 0xFE, 0xFE);
float ratio = shieldDroneReduction / 100f;
if (shieldDroneLerpVisual < ratio)
{
shieldDroneLerpVisual += 0.01f;
}
if (shieldDroneLerpVisual > ratio) shieldDroneLerpVisual = ratio;
outer *= shieldDroneLerpVisual;
inner *= shieldDroneLerpVisual;
Lighting.AddLight(drawPlayer.Center, inner.ToVector3());
float alpha = (255 - drawPlayer.immuneAlpha) / 255f;
outer *= alpha;
inner *= alpha;
Effect shader = ShaderManager.SetupCircleEffect(new Vector2((int)drawPlayer.Center.X, (int)drawPlayer.Center.Y + drawPlayer.gfxOffY), 2 * 16, outer, inner);
ShaderManager.ApplyToScreenOnce(Main.spriteBatch, shader);
}
}
public override void ModifyHitNPC(Item item, NPC target, ref int damage, ref float knockback, ref bool crit)
{
if (!Main.rand.NextBool(5)) return;
ApplyCandleDebuffs(target);
}
public override void ModifyHitNPCWithProj(Projectile proj, NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
{
if (!Main.rand.NextBool(5)) return;
if (proj.minion && !Main.rand.NextBool(5)) return;
ApplyCandleDebuffs(target);
}
public override void ModifyHitPvp(Item item, Player target, ref int damage, ref bool crit)
{
//ApplyCandleDebuffs(target);
AssPlayer assPlayer = target.GetModPlayer<AssPlayer>();
assPlayer.ResetEmpoweringTimer();
assPlayer.SpawnSoulTemp();
}
public override void ModifyHitPvpWithProj(Projectile proj, Player target, ref int damage, ref bool crit)
{
//ApplyCandleDebuffs(target);
AssPlayer assPlayer = target.GetModPlayer<AssPlayer>();
assPlayer.ResetEmpoweringTimer();
assPlayer.SpawnSoulTemp();
}
public override void ModifyWeaponDamage(Item item, ref StatModifier damage)
{
if (empoweringBuff && !item.CountsAsClass(DamageClass.Summon) && item.damage > 0) damage += empoweringStep; //summon damage gets handled in EmpoweringBuffGlobalProjectile
}
public override void ModifyWeaponCrit(Item item, ref float crit)
{
crit += 10 * empoweringStep;
}
public override bool PreKill(double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
{
//getDefense before teleportHome (so you don't teleport BEFORE you gain the defense)
if (!GetDefense(damage)) return false;
if (!TeleportHome(damage)) return false;
return base.PreKill(damage, hitDirection, pvp, ref playSound, ref genGore, ref damageSource);
}
public override bool PreHurt(bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
{
if (getDefenseDuration != 0) damage = 1;
DecreaseDroneShield(ref damage);
if (wyvernCampfire && damageSource.SourceProjectileType == ProjectileID.HarpyFeather)
{
hitDirection = 0; //this cancels knockback
}
return base.PreHurt(pvp, quiet, ref damage, ref hitDirection, ref crit, ref customDamage, ref playSound, ref genGore, ref damageSource);
}
public override void PostHurt(bool pvp, bool quiet, double damage, int hitDirection, bool crit)
{
ResetEmpoweringTimer();
SpawnSoulTemp();
}
public override void CatchFish(FishingAttempt attempt, ref int itemDrop, ref int npcSpawn, ref AdvancedPopupRequest sonar, ref Vector2 sonarPosition)
{
bool inWater = !attempt.inHoney && !attempt.inLava;
if (attempt.waterTilesCount < attempt.waterNeededToFish)
{
return;
}
if (ContentConfig.Instance.OtherPets)
{
//Match Zephyr Fish conditions
if (attempt.legendary && !attempt.crate && inWater)
{
if (((int)(Player.Center.X / 16) < Main.maxTilesX * 0.08f || (int)(Player.Center.X / 16) > Main.maxTilesX * 0.92f) && Main.rand.NextBool(5)) //2 times more likely than zephyr fish makes it about as rare as reaver shark
{
itemDrop = ModContent.ItemType<AnomalocarisItem>();
return;
}
}
}
}
public override void PostUpdateBuffs()
{
UpdateTeleportHomeWhenLow();
UpdateGetDefenseWhenLow();
Empower();
UpdateSlainBossTimer();
}
public override void PreUpdate()
{
if (Main.netMode != NetmodeID.Server)
{
if (drawEffectsCalledOnce)
{
drawEffectsCalledOnce = false;
}
if (Main.myPlayer == Player.whoAmI && ContentConfig.Instance.Weapons)
{
if (Player.ownedProjectileCounts[DroneController.GetDroneData(DroneType.Shield).ProjType] < 1) shieldDroneReduction = 0;
}
}
UpdateNearbyEnemies();
}
}
}