-
Notifications
You must be signed in to change notification settings - Fork 10
/
ClickerPlayer.cs
1844 lines (1631 loc) · 53.5 KB
/
ClickerPlayer.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
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using ClickerClass.Buffs;
using ClickerClass.Core.Netcode.Packets;
using ClickerClass.Items;
using ClickerClass.Items.Accessories;
using ClickerClass.Items.Consumables;
using ClickerClass.Items.Misc;
using ClickerClass.Projectiles;
using ClickerClass.Utilities;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.GameContent.Drawing;
using Terraria.GameInput;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace ClickerClass
{
public partial class ClickerPlayer : ModPlayer
{
//Key presses
public double pressedAutoClick;
public int clickerClassTime = 0;
//-Clicker-
//Misc
public Color clickerRadiusColor = Color.White;
/// <summary>
/// Cached clickerRadiusColor for draw
/// </summary>
public Color clickerRadiusColorDraw = Color.Transparent;
public float ClickerRadiusColorMultiplier => clickerRadiusRangeAlpha * clickerRadiusSwitchAlpha;
/// <summary>
/// Visual (clientside) indicator that the cursor is inside clicker radius
/// </summary>
public bool clickerInRange = false;
/// <summary>
/// Visual (clientside) indicator that the cursor is inside Motherboard radius
/// </summary>
public bool clickerInRangeMotherboard = false;
public bool GlowVisual => clickerInRange || clickerInRangeMotherboard;
public bool clickerSelected = false;
/// <summary>
/// False if phase reach
/// </summary>
public bool clickerDrawRadius = false;
public const float clickerRadiusSwitchAlphaMin = 0f;
public const float clickerRadiusSwitchAlphaMax = 1f;
public const float clickerRadiusSwitchAlphaStep = clickerRadiusSwitchAlphaMax / 40f;
public float clickerRadiusSwitchAlpha = clickerRadiusSwitchAlphaMin;
//Gameplay only: not related to player select screen
public bool CanDrawRadius => !Main.gameMenu && !Player.dead && clickerRadiusSwitchAlpha > clickerRadiusSwitchAlphaMin;
public const float clickerRadiusRangeAlphaMin = 0.2f;
public const float clickerRadiusRangeAlphaMax = 0.8f;
public const float clickerRadiusRangeAlphaStep = clickerRadiusRangeAlphaMax / 20f;
public float clickerRadiusRangeAlpha = clickerRadiusRangeAlphaMin;
/// <summary>
/// Set via hotkey, reset if no autoclick-giving effects are applied (i.e. Hand Cream)
/// <br/>Synced whenever changed
/// </summary>
public bool clickerAutoClick = false;
/// <summary>
/// Saved amount of clicks done with any clicker, accumulated, fluff
/// </summary>
public int clickerTotal = 0;
/// <summary>
/// Amount of clicks done, constantly incremented. Used for click effect proccing
/// </summary>
public int clickAmount = 0;
/// <summary>
/// cps, use Math.Floor if you need as integer
/// </summary>
public float clickerPerSecond = 0;
private const int ClickTimerCount = 60;
/// <summary>
/// Keeps track of clicks done in the last <see cref="ClickTimerCount"/> ticks, tracked as separate timers
/// </summary>
private List<Ref<float>> clickTimers = new List<Ref<float>>();
/// <summary>
/// Amount of money generated by clicker items
/// </summary>
public int clickerMoneyGenerated = 0;
/// <summary>
/// Used for double tap dash effects
/// </summary>
public int clickerDoubleTap = 0;
/// <summary>
/// Used for cursor positioning and the Aimbot Module effect (and similar). Defaults to Main.MouseWorld otherwise
/// </summary>
public Vector2 clickerPosition = Main.MouseWorld;
/// <summary>
/// Represents the currently active (fastest) auto-reuse effect applied to the player
/// </summary>
public AutoReuseEffect ActiveAutoReuseEffect { get; private set; }
/// <summary>
/// Represents all auto-reuse effects applied this tick
/// </summary>
private List<AutoReuseEffect> AutoReuseEffects { get; set; } = new List<AutoReuseEffect>();
//Click effects
/// <summary>
/// Used to track effect names that are currently active. Resets every tick
/// </summary>
private Dictionary<string, bool> ClickEffectActive = new Dictionary<string, bool>();
public bool effectTranscend = false;
public bool effectHotWings = false;
public const int EffectHotWingsTimerMax = 70; //Full duration. Damage part excludes the fade time
public const int EffectHotWingsTimerFadeStart = 30;
public int effectHotWingsTimer = 0; //Gets set to max, counts down
public const int EffectHotWingsFrameMax = 4;
public int effectHotWingsFrame = 0;
public bool DrawHotWings => effectHotWingsTimer > 0;
//Out of combat
public const int OutOfCombatTimeMax = 300;
public bool OutOfCombat => outOfCombatTimer <= 0;
public int outOfCombatTimer = 0;
//Item
public bool itemBurningSuperDeath = false;
public bool itemDreamClicker = false;
public int itemSeafoamClickerTimer = 0;
public int itemSeafoamClickerHPS = 0;
//Armor
public int setAbilityDelayTimer = 0;
public float setMotherboardRatio = 0f;
public float setMotherboardAngle = 0f;
/// <summary>
/// Calculated after clickerRadius is calculated, and if the Motherboard set is worn
/// </summary>
public Vector2 setMotherboardPosition = Vector2.Zero;
public float setMotherboardAlpha = 0f;
public int setMotherboardFrame = 0;
public bool setMotherboardFrameShift = false;
public bool setMotherboard = false;
public bool SetMotherboardPlaced => setMotherboard && setMotherboardRatio > 0;
public bool setMice = false;
public bool setPrecursor = false;
public bool setOverclock = false;
public bool setRGB = false;
public int setPrecursorTimer = 0;
//Acc
public bool accEnchantedLED = false;
public bool accEnchantedLED2 = false; //different visuals
public Item accAMedalItem = null;
public bool AccAMedal => accAMedalItem != null && !accAMedalItem.IsAir;
public Item accFMedalItem = null;
public bool AccFMedal => accFMedalItem != null && !accFMedalItem.IsAir;
public Item accSMedalItem = null;
public bool AccSMedal => accSMedalItem != null && !accSMedalItem.IsAir;
public bool accGlassOfMilk = false;
public Item accCookieItem = null;
public bool accCookie = false;
public bool accCookie2 = false; //different visuals
public bool accClickingGlove = false;
public bool accAncientClickingGlove = false;
public bool accRegalClickingGlove = false;
public bool accPortableParticleAccelerator = false; //"is wearing"
public bool accPortableParticleAccelerator2 = false; //"is active", client only
public bool IsPortableParticleAcceleratorActive => accPortableParticleAccelerator && accPortableParticleAccelerator2;
public Item accGoldenTicketItem = null;
public bool AccGoldenTicket => accGoldenTicketItem != null && !accGoldenTicketItem.IsAir;
public bool accTriggerFinger = false;
public bool accMouseTrap = false;
public Item accPaperclipsItem = null;
public bool AccPaperclips => accPaperclipsItem != null && !accPaperclipsItem.IsAir;
public bool accHotKeychain = false;
public bool accHotKeychain2 = false;
public bool accButtonMasher = false;
public bool accAimbotModule = false;
public bool accAimbotModule2 = false;
public bool accAimbotModule2Toggle = false; //If enabled, automatically seeks enemies
public int accAimbotModule2ToggleTimer = 0; //To not do it every tick
public bool accEnlarge = false;
public bool accSFXButtonSoundboard = false;
public int accAimbotModuleTarget = -1;
public int accAimbotModuleFailsafe = 0;
public float accAimbotModuleScale = 1f;
public bool accAimbotModuleTargetInRange = false; //Controls the target being drawn greyed out
public bool HasAimbotModuleTarget => accAimbotModuleTarget > -1 && accAimbotModuleFailsafe >= 10;
public int accClickingGloveTimer = 0;
public int accCookieTimer = 0;
public int accAMedalAmount = 0; //Only updated clientside
public int accFMedalAmount = 0; //Only updated clientside
public int accSMedalAmount = 0; //Only updated clientside
public float accMedalRot = 0f; //Unified rotation for all medals
public int accPaperclipsAmount = 0;
public int accHotKeychainTimer = 0;
public int accHotKeychainAmount = 0;
//Store item type mapped to stack
private Dictionary<int, int> sfxButtons;
//Stats
/// <summary>
/// How many less clicks are required to trigger an effect
/// </summary>
public int clickerBonus = 0;
/// <summary>
/// Multiplier to clicks required to trigger an effect
/// </summary>
public float clickerBonusPercent = 1f;
/// <summary>
/// Effective clicker radius in pixels when multiplied by 100
/// </summary>
public float clickerRadius = 1f;
/// <summary>
/// Cached clickerRadius for draw
/// </summary>
public float clickerRadiusDraw = 1f;
/// <summary>
/// Clicker radius in pixels
/// </summary>
public float ClickerRadiusReal => clickerRadius * 100;
/// <summary>
/// Clicker draw radius in pixels
/// </summary>
public float ClickerRadiusRealDraw => clickerRadiusDraw * 100;
/// <summary>
/// Motherboard radius in pixels
/// </summary>
public float ClickerRadiusMotherboard => ClickerRadiusReal * 0.5f;
/// <summary>
/// Motherboard draw radius in pixels
/// </summary>
public float ClickerRadiusMotherboardDraw => ClickerRadiusRealDraw * 0.5f;
/// <summary>
/// If player has consumed a Heavenly Chip and has its bonus clicker radius
/// </summary>
public bool consumedHeavenlyChip;
//Need to be synced
public bool paintingCondition_MoonLordDefeatedWithClicker;
public bool paintingCondition_Clicked100Cookies; //Instead of server having to keep track of every clicked cookie, only set it once
public int paintingCondition_ClickedCookiesCount;
//Helper methods
/// <summary>
/// Enables the use of a click effect for this player
/// </summary>
/// <param name="name">The unique effect name</param>
public void EnableClickEffect(string name)
{
if (ClickEffectActive.TryGetValue(name, out _))
{
ClickEffectActive[name] = true;
}
}
/// <summary>
/// Enables the use of click effects for this player
/// </summary>
/// <param name="names">The unique effect names</param>
public void EnableClickEffect(IEnumerable<string> names)
{
foreach (var name in names)
{
EnableClickEffect(name);
}
}
/// <summary>
/// Checks if the player has a click effect enabled
/// </summary>
/// <param name="name">The unique effect name</param>
/// <returns><see langword="true"/> if enabled</returns>
public bool HasClickEffect(string name)
{
if (ClickEffectActive.TryGetValue(name, out _))
{
return ClickEffectActive[name];
}
return false;
}
/// <summary>
/// Checks if the player has a click effect enabled
/// </summary>
/// <param name="name">The unique effect name</param>
/// <param name="effect">The effect associated with the name</param>
/// <returns><see langword="true"/> if enabled</returns>
public bool HasClickEffect(string name, out ClickEffect effect)
{
effect = null;
if (HasClickEffect(name))
{
return ClickerSystem.IsClickEffect(name, out effect);
}
return false;
}
//Unused yet
public bool HasAnyClickEffect()
{
foreach (var value in ClickEffectActive.Values)
{
if (value) return true;
}
return false;
}
internal void ResetAllClickEffects()
{
//Stupid trick to be able to write to a value in a dictionary
foreach (var key in ClickEffectActive.Keys.ToList())
{
ClickEffectActive[key] = false;
}
}
/// <summary>
/// Adds the given auto-reuse effect to the list of available effects applicable this tick, aswell as deciding on the fastest one to use
/// </summary>
internal void SetAutoReuseEffect(AutoReuseEffect effect)
{
AutoReuseEffects.Add(effect);
//Pick the fastest one available
for (int i = 0; i < AutoReuseEffects.Count; i++)
{
var iter = AutoReuseEffects[i];
if (iter.ControlledByKeyBind && !clickerAutoClick)
{
//"Not enabled", skip
continue;
}
//Pick if none, or faster than current
if (ActiveAutoReuseEffect == default || iter.SpeedFactor < ActiveAutoReuseEffect.SpeedFactor)
{
ActiveAutoReuseEffect = iter;
}
}
}
internal void ResetAutoClickToggle()
{
if (!AutoReuseEffects.Any(effect => effect.ControlledByKeyBind))
{
//If no reuse effects need the keybind, unset the toggle
clickerAutoClick = false;
}
}
/// <summary>
/// Call to register a click towards the "clicks per second" and total calculations
/// </summary>
internal void AddClick()
{
clickTimers.Add(new Ref<float>(1f));
clickerTotal++;
}
/// <summary>
/// Call to increment the click amount counter used for proccing click effects
/// </summary>
internal void AddClickAmount()
{
clickAmount++;
int sMedalStep = SMedal.ChargeMeterStep;
if (accSMedalAmount >= sMedalStep)
{
accSMedalAmount -= sMedalStep;
}
}
/// <summary>
/// Manages the click queue and calculates <see cref="clickerPerSecond"/>
/// </summary>
private void HandleCPS()
{
clickerPerSecond = 0f; //Recalculates every tick
//Loop from back to front, removing ran out timers and adding existing timers
for (int i = clickTimers.Count - 1; i >= 0; i--)
{
clickTimers[i].Value -= 1f / ClickTimerCount; //Decrement timer
if (clickTimers[i].Value <= 0f)
{
clickTimers.RemoveAt(i);
}
else
{
float value = clickTimers[i].Value;
value = Math.Clamp(value, 0.3f, 0.75f); //Smooths out the values, with slight bias towards > 0.5f, so that the cps stays on a given value longer if clicks are regular (i.e. autoswing)
clickerPerSecond += value * 2; //* 2 is because the average click timer "state" is 0.5f
}
}
clickerPerSecond = Math.Clamp(clickerPerSecond, 0, 60);
}
private void HandleRadiusAlphas()
{
if (clickerDrawRadius)
{
if (clickerRadiusSwitchAlpha < clickerRadiusSwitchAlphaMax)
{
clickerRadiusSwitchAlpha += clickerRadiusSwitchAlphaStep;
}
else
{
clickerRadiusSwitchAlpha = clickerRadiusSwitchAlphaMax;
}
}
else
{
if (clickerRadiusSwitchAlpha > clickerRadiusSwitchAlphaMin)
{
clickerRadiusSwitchAlpha -= clickerRadiusSwitchAlphaStep;
}
else
{
clickerRadiusSwitchAlpha = clickerRadiusSwitchAlphaMin;
}
}
if (GlowVisual)
{
if (clickerRadiusRangeAlpha < clickerRadiusRangeAlphaMax)
{
clickerRadiusRangeAlpha += clickerRadiusRangeAlphaStep;
}
else
{
clickerRadiusRangeAlpha = clickerRadiusRangeAlphaMax;
}
}
else
{
if (clickerRadiusRangeAlpha > clickerRadiusRangeAlphaMin)
{
clickerRadiusRangeAlpha -= clickerRadiusRangeAlphaStep;
}
else
{
clickerRadiusRangeAlpha = clickerRadiusRangeAlphaMin;
}
}
}
private void HandleAimbotModuleTargeting()
{
if (accAimbotModuleFailsafe < 10)
{
ResetAimbotModuleTarget();
accAimbotModuleFailsafe++;
}
if (accAimbotModuleScale > 1f)
{
accAimbotModuleScale -= 0.05f;
}
if (accAimbotModule2)
{
if (accAimbotModule2Toggle && !HasAimbotModuleTarget && clickerSelected)
{
accAimbotModule2ToggleTimer++;
if (accAimbotModule2ToggleTimer > 5)
{
accAimbotModule2ToggleTimer = 0;
AimbotModuleTargestClosest();
}
}
}
else
{
accAimbotModule2Toggle = false;
}
//No target: return
if (!HasAimbotModuleTarget)
{
return;
}
//No aimbot giving accessories equipped: reset and return
if (!(accAimbotModule || accAimbotModule2))
{
ResetAimbotModuleTarget();
return;
}
accAimbotModuleTargetInRange = clickerSelected;
NPC target = Main.npc[accAimbotModuleTarget];
clickerPosition = target.Center;
CheckPositionInRange(target.Center, out bool targetInRange, out bool targetInRangeMotherboard);
bool targetInRangeCombined = targetInRange || targetInRangeMotherboard;
//If target still alive (keeps target until death)
bool keepTargetCheck = target.active;
if (accAimbotModule2)
{
//Or if target still targetable (moonlord hand, granite golem etc.)
keepTargetCheck = target.CanBeChasedBy();
}
if (keepTargetCheck && targetInRangeCombined)
{
return;
}
if (!keepTargetCheck)
{
ResetAimbotModuleTarget();
}
bool canRetarget = accAimbotModule2 && clickerSelected;
if (!targetInRangeCombined)
{
accAimbotModuleTargetInRange = false; //Target out of range, go inactive
float radiusSQ = 1920; //Use doubled screen width check for hardcoded retargeting if outside
radiusSQ *= radiusSQ;
if (target.DistanceSQ(Player.Center) >= radiusSQ)
{
ResetAimbotModuleTarget(); //Target too far away, reset
canRetarget = false;
}
}
if (!canRetarget)
{
return;
}
AimbotModuleTargestClosest();
}
private void AimbotModuleTargestClosest()
{
//Retarget to closest enemy to either the old target or the player
NPC nearOldTarget = null;
float oldToDistSQMax = float.MaxValue;
NPC nearPlayerTarget = null;
float playerToDistSQMax = float.MaxValue;
for (int i = 0; i < Main.maxNPCs; i++)
{
NPC newTarget = Main.npc[i];
if (newTarget.CanBeChasedBy())
{
CheckPositionInRange(newTarget.Center, out bool newTargetInRange, out bool newTargetInRangeMotherboard);
bool newTargetInRangeCombined = newTargetInRange || newTargetInRangeMotherboard;
if (!newTargetInRangeCombined)
{
//Skip enemies not clicker radius
continue;
}
float toOldDistSQ = newTarget.DistanceSQ(clickerPosition);
if (toOldDistSQ < oldToDistSQMax)
{
oldToDistSQMax = toOldDistSQ;
nearOldTarget = newTarget;
}
float toPlayerDistSQ = newTarget.DistanceSQ(Player.Center);
if (toPlayerDistSQ < playerToDistSQMax)
{
playerToDistSQMax = toPlayerDistSQ;
nearPlayerTarget = newTarget;
}
}
}
NPC preferredTarget = null;
if (nearPlayerTarget != null)
{
preferredTarget = nearPlayerTarget;
}
if (nearOldTarget != null && oldToDistSQMax < playerToDistSQMax)
{
preferredTarget = nearOldTarget;
}
if (preferredTarget != null)
{
SetAimbotModuleTarget(preferredTarget);
}
}
/// <summary>
/// Returns the position from the ratio and angle, given the radius in pixels
/// </summary>
/// <param name="realRadius">The reference radius</param>
public Vector2 CalculateMotherboardPosition(float realRadius)
{
float length = setMotherboardRatio * realRadius;
Vector2 direction = setMotherboardAngle.ToRotationVector2();
return direction * length;
}
/// <summary>
/// Construct ratio and angle from position
/// </summary>
public void SetMotherboardRelativePosition(Vector2 position)
{
Vector2 toPosition = position - Player.Center;
float length = toPosition.Length();
float radius = ClickerRadiusReal;
float ratio = length / radius;
if (ratio < 0.6f)
{
//Enforce minimal range
ratio = 0.6f;
}
setMotherboardRatio = ratio;
setMotherboardAngle = toPosition.ToRotation();
}
/// <summary>
/// Dispels the motherboard position
/// </summary>
public void ResetMotherboardPosition()
{
setMotherboardPosition = Vector2.Zero;
setMotherboardRatio = 0f;
setMotherboardAngle = 0f;
}
/// <summary>
/// For checking if the given position is in range of the clicker radius (and by default, the motherboard set position)
/// </summary>
public void CheckPositionInRange(Vector2 position, out bool inRange, out bool inRangeMotherboard, bool checkMotherboard = true)
{
inRange = false;
inRangeMotherboard = false;
float radiusSQ = ClickerRadiusReal * ClickerRadiusReal;
bool? collision = null; //Since it uses the same collision check twice, but it shouldn't just be calculated twice too
if (Vector2.DistanceSquared(position, Player.Center) < radiusSQ)
{
collision = Collision.CanHit(new Vector2(Player.Center.X, Player.Center.Y - 12), 1, 1, position, 1, 1);
if (collision == true)
{
inRange = true;
}
}
if (!checkMotherboard || !SetMotherboardPlaced)
{
return;
}
radiusSQ = ClickerRadiusMotherboard * ClickerRadiusMotherboard;
if (Vector2.DistanceSquared(position, setMotherboardPosition) < radiusSQ)
{
collision ??= Collision.CanHit(new Vector2(Player.Center.X, Player.Center.Y - 12), 1, 1, position, 1, 1);
if (collision == true)
{
inRangeMotherboard = true;
}
}
}
public void SetAimbotModuleTarget(NPC target)
{
accAimbotModuleTarget = target.whoAmI;
accAimbotModuleScale = 2f;
accAimbotModuleTargetInRange = true;
}
public void ResetAimbotModuleTarget()
{
accAimbotModuleTarget = -1;
accAimbotModuleTargetInRange = false;
}
internal int originalSelectedItem;
internal bool autoRevertSelectedItem = false;
/// <summary>
/// Uses the item in the specified index from the players inventory
/// </summary>
public void QuickUseItemInSlot(int index)
{
if (index > -1 && index < Main.InventorySlotsTotal && Player.inventory[index].type != ItemID.None)
{
if (Player.CheckMana(Player.inventory[index], -1, false, false))
{
originalSelectedItem = Player.selectedItem;
autoRevertSelectedItem = true;
Player.selectedItem = index;
Player.controlUseItem = true;
Player.ItemCheck();
}
else
{
SoundEngine.PlaySound(SoundID.Drip with { Variants = stackalloc int[] { 0, 1, 2 } }, Player.Center);
}
}
}
/// <summary>
/// Returns the amount of clicks required for an effect of the given name to trigger (defaults to the item's assigned effect). Includes various bonuses
/// </summary>
public int GetClickAmountTotal(ClickerItemCore clickerItem, string name)
{
//Doesn't go below 1
int amount = 1;
if (ClickerSystem.IsClickEffect(name, out ClickEffect effect))
{
amount = effect.Amount;
}
float percent = Math.Max(0f, clickerBonusPercent);
int prePercentAmount = Math.Max(1, amount + clickerItem.clickBoostPrefix - clickerBonus);
return Math.Max(1, (int)(prePercentAmount * percent));
}
/// <summary>
/// Returns the amount of clicks required for the effect of this item to trigger. Includes various bonuses
/// </summary>
public int GetClickAmountTotal(Item item, string name)
{
if (item.TryGetGlobalItem(out ClickerItemCore clickerItem))
{
return GetClickAmountTotal(clickerItem, name);
}
return 1;
}
/// <summary>
/// Counts the stack of the given <paramref name="item"/> up by its stack<br/>
/// Returns true if reached <see cref="SFXButtonBase.StackAmount"/>
/// </summary>
public bool AddSFXButtonStack(Item item)
{
return AddSFXButtonStack(item.type, item.stack);
}
/// <summary>
/// Counts the stack of the given item type up by <paramref name="stack"/><br/>
/// Returns true if reached <see cref="SFXButtonBase.StackAmount"/>
/// </summary>
public bool AddSFXButtonStack(int type, int stack)
{
if (!ClickerSystem.IsSFXButton(type))
{
return false;
}
if (!sfxButtons.ContainsKey(type))
{
sfxButtons[type] = 0;
}
sfxButtons[type] = Math.Min(SFXButtonBase.StackAmount, sfxButtons[type] + stack);
return sfxButtons[type] == SFXButtonBase.StackAmount;
}
/// <summary>
/// Assigns <paramref name="stack"/> of the given type, if returning true<br/>
/// </summary>
public bool GetSFXButtonStack(int type, out int stack)
{
return sfxButtons.TryGetValue(type, out stack);
}
/// <summary>
/// Returns all currently active "sfx button" stacks.<br/>
/// Use with <see cref="ClickerSystem.IsSFXButton"/> to get the sound
/// </summary>
public IReadOnlyDictionary<int, int> GetAllSFXButtonStacks()
{
return sfxButtons;
}
public override void ResetEffects()
{
//-Clicker-
//Misc
clickerRadiusColor = Color.White;
clickerInRange = false;
clickerInRangeMotherboard = false;
clickerSelected = false;
clickerDrawRadius = false;
ActiveAutoReuseEffect = default;
AutoReuseEffects.Clear();
//Click Effects
ResetAllClickEffects();
effectHotWings = false;
effectTranscend = false;
//Item
itemBurningSuperDeath = false;
itemDreamClicker = false;
//Armor
setMotherboard = false;
setMice = false;
setPrecursor = false;
setOverclock = false;
setRGB = false;
//Acc
accEnchantedLED = false;
accEnchantedLED2 = false;
accAMedalItem = null;
accFMedalItem = null;
accSMedalItem = null;
accGlassOfMilk = false;
accCookieItem = null;
accCookie = false;
accCookie2 = false;
accClickingGlove = false;
accAncientClickingGlove = false;
accRegalClickingGlove = false;
accPortableParticleAccelerator = false;
accPortableParticleAccelerator2 = false;
accGoldenTicketItem = null;
accTriggerFinger = false;
accMouseTrap = false;
accPaperclipsItem = null;
accHotKeychain = false;
accHotKeychain2 = false;
accAimbotModule = false;
accAimbotModule2 = false;
accAimbotModuleTargetInRange = false;
accEnlarge = false;
accSFXButtonSoundboard = false;
sfxButtons.Clear();
//Stats
clickerBonus = 0;
clickerBonusPercent = 1f;
clickerRadius = 1f;
}
public override void ResetInfoAccessories()
{
accButtonMasher = false;
}
public override void UpdateAutopause()
{
clickerRadius = 1f;
}
public override void Initialize()
{
clickerTotal = 0;
clickerMoneyGenerated = 0;
paintingCondition_MoonLordDefeatedWithClicker = false;
paintingCondition_Clicked100Cookies = false;
paintingCondition_ClickedCookiesCount = 0;
AutoReuseEffects = new List<AutoReuseEffect>();
ClickEffectActive = new Dictionary<string, bool>();
foreach (var name in ClickerSystem.GetAllEffectNames())
{
ClickEffectActive.Add(name, false);
}
clickTimers = new List<Ref<float>>();
sfxButtons = new Dictionary<int, int>();
}
public override void SaveData(TagCompound tag)
{
tag.Add("clickerTotal", clickerTotal);
tag.Add("clickerMoneyGenerated", clickerMoneyGenerated);
tag.Add("consumedHeavenlyChip", consumedHeavenlyChip);
tag.Add("paintingCondition_MoonLordDefeatedWithClicker", paintingCondition_MoonLordDefeatedWithClicker);
tag.Add("paintingCondition_Clicked100Cookies", paintingCondition_Clicked100Cookies);
tag.Add("paintingCondition_ClickedCookiesCount", paintingCondition_ClickedCookiesCount);
}
public override void LoadData(TagCompound tag)
{
clickerTotal = tag.GetInt("clickerTotal");
clickerMoneyGenerated = tag.GetInt("clickerMoneyGenerated");
consumedHeavenlyChip = tag.GetBool("consumedHeavenlyChip");
paintingCondition_MoonLordDefeatedWithClicker = tag.GetBool("paintingCondition_MoonLordDefeatedWithClicker");
paintingCondition_Clicked100Cookies = tag.GetBool("paintingCondition_Clicked100Cookies");
paintingCondition_ClickedCookiesCount = tag.GetInt("paintingCondition_ClickedCookiesCount");
}
public override void CopyClientState(ModPlayer clientClone)
{
var clickerClone = clientClone as ClickerPlayer;
clickerClone.clickerAutoClick = clickerAutoClick;
}
public override void SendClientChanges(ModPlayer clientPlayer)
{
var clickerClone = clientPlayer as ClickerPlayer;
if (clickerClone.clickerAutoClick != clickerAutoClick)
{
new ClickerAutoClickPacket(Player, clickerAutoClick).Send();
}
}
public override void SyncPlayer(int toWho, int fromWho, bool newPlayer)
{
new SyncClickerPlayerPacket(this).Send(toWho, fromWho);
}
public override void RefreshInfoAccessoriesFromTeamPlayers(Player otherPlayer)
{
ClickerPlayer clickerOther = otherPlayer.GetModPlayer<ClickerPlayer>();
if (clickerOther.accButtonMasher)
{
accButtonMasher = true;
}
}
public override void ProcessTriggers(TriggersSet triggersSet)
{
// checks for frozen, webbed and stoned
if (Player.CCed)
{
return;
}
if (ClickerClass.AutoClickKey.JustPressed)
{
if (Math.Abs(clickerClassTime - pressedAutoClick) > 20)
{
pressedAutoClick = clickerClassTime;
if (AutoReuseEffects.Any(effect => effect.ControlledByKeyBind))
{
SoundEngine.PlaySound(SoundID.MenuTick, Player.position);
clickerAutoClick = !clickerAutoClick;
}
}
}
if (ClickerClass.AimAssistKey.JustPressed)
{
if (accAimbotModule)
{
SoundEngine.PlaySound(SoundID.MenuTick, Player.position);
if (accAimbotModule2)
{
if (accAimbotModule2Toggle)
{
accAimbotModule2Toggle = false;
ResetAimbotModuleTarget();
}
else
{
accAimbotModule2Toggle = true;
}
}
else
{
for (int i = 0; i < Main.maxNPCs; i++)
{
NPC target = Main.npc[i];
if (target.CanBeChasedBy())
{
Rectangle inflatedHitbox = target.getRect();
inflatedHitbox.Inflate(50, 50);
if (inflatedHitbox.Contains(Main.MouseWorld.ToPoint()))
{
SetAimbotModuleTarget(target);
break;
}
}