This repository has been archived by the owner on Jul 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathautomator.user.js
2352 lines (2035 loc) · 79 KB
/
automator.user.js
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
// ==UserScript==
// @name [ensingm2] Steam Monster Game Script
// @namespace https://github.com/ensingm2/SteamMonsterGameScript
// @description A Javascript automator for the 2015 Summer Steam Monster Minigame
// @version 2.16
// @match http://steamcommunity.com/minigame/towerattack*
// @match http://steamcommunity.com//minigame/towerattack*
// @updateURL https://raw.githubusercontent.com/ensingm2/SteamMonsterGameScript/master/automator.user.js
// @downloadURL https://raw.githubusercontent.com/ensingm2/SteamMonsterGameScript/master/automator.user.js
// @require https://raw.githubusercontent.com/ensingm2/SteamMonsterGameScript/master/slaveWindows.js?ver=2_06
// @grant none
// ==/UserScript==
// Compiled and customized by https://github.com/ensingm2
// See a (hopefully) full list of contributors over at https://github.com/ensingm2/SteamMonsterGameScript#contributors
// Custom variables
var debug = false;
var clicksPerSecond = g_TuningData.abilities[1].max_num_clicks;
var autoClickerVariance = Math.floor(clicksPerSecond / 10);
clicksPerSecond -= Math.ceil(autoClickerVariance / 2);
var respawnCheckFreq = 5000;
var targetSwapperFreq = 1000;
var abilityUseCheckFreq = 2000;
var itemUseCheckFreq = 5000;
var seekHealingPercent = 20;
var upgradeManagerFreq = 5000;
var slowRenderingFreq = 1000;
var autoBuyAbilities = false;
var refreshDelay = 3600000; //Page refresh every 60min
var spamStatBoosters = true;
// Boss Nuke Variables
var useNukeOnBossAbovePercent = 40;
//Controls to sync us up with other scripts
var CONTROL = {
speedThreshold: 2000, // use gold rain every boss round after here
rainingRounds: 100, // use gold rain every x rounds
disableGoldRainLevels: 200 // min level to use gold rain on
};
//item use variables
var useMedicsAtPercent = 40;
var useMedicsAtLanePercent = 70;
var useMedicsAtLanePercentAliveReq = 30;
var useNukeOnSpawnerAbovePercent = 75;
var useMetalDetectorOnBossBelowPercent = 30;
var useStealHealthAtPercent = 15;
var useRainingGoldAbovePercent = 50;
var useLikeNewAboveCooldown = 14220000; // Need to save at least 14220s of cooldowns(60% of max)
var useResurrectToSaveCount = 150; // Use revive to save 150 people
var minutesBufferForConsumableDump = 10;
var survivalTime = 10; // check how long we would survive on a level and prioritize armour if needed
// You shouldn't need to ever change this, you only push to server every 1s anyway
var autoClickerFreq = 1000;
// Internal variables, you shouldn't need to touch these
var autoRespawner, autoClicker, autoTargetSwapper, autoTargetSwapperElementUpdate, autoAbilityUser, autoUpgradeManager, fpsThrottle, spammer;
var elementUpdateRate = 60000;
var autoUseConsumables = true;
var userElementMultipliers = [1, 1, 1, 1];
var userMaxElementMultiiplier = 1;
var swapReason;
var lastLootLevel = 0;
var lastLootCache = [];
var ABILITIES = {
FIRE_WEAPON: 1,
CHANGE_LANE: 2,
RESPAWN: 3,
CHANGE_TARGET: 4,
MORALE_BOOSTER: 5,
GOOD_LUCK_CHARMS: 6,
MEDICS: 7,
METAL_DETECTOR: 8,
DECREASE_COOLDOWNS: 9,
TACTICAL_NUKE: 10,
CLUSTER_BOMB: 11,
NAPALM: 12,
RESURRECTION: 13,
CRIPPLE_SPAWNER: 14,
CRIPPLE_MONSTER: 15,
MAX_ELEMENTAL_DAMAGE: 16,
RAINING_GOLD: 17,
CRIT: 18,
PUMPED_UP: 19,
THROW_MONEY_AT_SCREEN: 20,
GOD_MODE: 21,
TREASURE: 22,
STEAL_HEALTH: 23,
REFLECT_DAMAGE: 24,
FEELING_LUCKY: 25,
WORMHOLE: 26,
LIKE_NEW: 27
};
function startAllAutos() {
startAutoRespawner();
startAutoClicker();
startAutoTargetSwapper();
startAutoAbilityUser();
startAutoItemUser();
startAutoUpgradeManager();
}
function loadSettings() {
if(WebStorage.GetLocal('autoClickerEnabled') === false)
toggleAutoClicker();
if(WebStorage.GetLocal('autoTargetSwapperEnabled') === false)
toggleAutoTargetSwapper();
if(WebStorage.GetLocal('autoAbilityUserEnabled') === false)
toggleAutoAbilityUser();
if(WebStorage.GetLocal('autoConsumableUserEnabled') === false)
toggleAutoItemUser();
if(WebStorage.GetLocal('autoUpgraderEnabled') === false)
toggleAutoUpgradeManager();
if(WebStorage.GetLocal('particleSpamEnabled')){
spammer = setInterval(spamNoClick, 1000 / clicksPerSecond);
updateToggle("particles", false);
}
if (WebStorage.GetLocal('fpsThrottleEnabled') === true)
toggleFPS();
if(WebStorage.GetLocal('spamStatBoostersEnabled') === false)
toggleSpamStatBoosters();
if(WebStorage.GetLocal('survivalTime') !== null) {
survivalTime = WebStorage.GetLocal('survivalTime');
$J("#survival_time").html(survivalTime);
}
}
function stopAllAutos() {
stopAutoClicker();
stopAutoRespawner();
stopAutoTargetSwapper();
stopAutoAbilityUser();
stopAutoItemUser();
stopAutoUpgradeManager();
}
//Keep trying to start every second till success
var startAttempts = 0;
var startAll = setInterval(function() {
if (!gameRunning()) {
//Don't refresh if we're waiting on game to start
if (g_Minigame.m_CurrentScene.m_rgGameData.status != 1) {
//Refresh if the game still isn't running after 15s
if (startAttempts > 15)
location.reload();
startAttempts++;
}
return;
}
clearInterval(startAll);
startAllAutos();
initGUI();
loadSettings();
//Start leaderboard (if user is running userscript)
if (typeof unsafeWindow != 'undefined')
initLeaderboard();
if (typeof runMaster == 'function') {
//Setup for slave windows
if (location.search.match(/slave/))
runSlave();
else
runMaster();
}
//Keep Playing while minimized - http://www.reddit.com/r/SteamMonsterGame/comments/39yng9/keep_autoclicking_after_minimizingchanging_tabs/
setInterval(function(p) {
return p.Tick = eval("(" + ("" + p.Tick).replace(/document\.(hidden|webkitHidden|mozHidden|msHidden)/g, !1) + ")"),
function() {
p = g_Minigame.m_CurrentScene, p && document.hidden && p.Tick();
};
}(CSceneGame.prototype), 1000);
setTimeout(function() {
//Try to reload every 15s
var reloader = setInterval(function() {
//No raining gold, treasure mob, boss, or miniboss
var target = getTarget();
var reload = !currentLaneHasAbility(ABILITIES.RAINING_GOLD) && target.m_data.type != 4 && target.m_data.type != 2 && target.m_data.type != 3 && target.m_data.type !== false;
if (reload) {
clearInterval(reloader);
location.reload();
}
}, 15000);
}, refreshDelay);
}, 1000);
//Expose functions if running in userscript
if (typeof unsafeWindow != 'undefined') {
// Variables
unsafeWindow.debug = debug;
unsafeWindow.clicksPerSecond = clicksPerSecond;
unsafeWindow.autoClickerVariance = autoClickerVariance;
unsafeWindow.respawnCheckFreq = respawnCheckFreq;
unsafeWindow.targetSwapperFreq = targetSwapperFreq;
unsafeWindow.abilityUseCheckFreq = abilityUseCheckFreq;
unsafeWindow.itemUseCheckFreq = itemUseCheckFreq;
unsafeWindow.seekHealingPercent = seekHealingPercent;
unsafeWindow.upgradeManagerFreq = upgradeManagerFreq;
unsafeWindow.autoBuyAbilities = autoBuyAbilities;
unsafeWindow.fpsThrottle = fpsThrottle;
//item use variables
unsafeWindow.useMedicsAtPercent = useMedicsAtPercent;
unsafeWindow.useMedicsAtLanePercent = useMedicsAtLanePercent;
unsafeWindow.useMedicsAtLanePercentAliveReq = useMedicsAtLanePercentAliveReq;
unsafeWindow.useNukeOnSpawnerAbovePercent = useNukeOnSpawnerAbovePercent;
unsafeWindow.useMetalDetectorOnBossBelowPercent = useMetalDetectorOnBossBelowPercent;
unsafeWindow.useStealHealthAtPercent = useStealHealthAtPercent;
unsafeWindow.useRainingGoldAbovePercent = useRainingGoldAbovePercent;
unsafeWindow.autoUseConsumables = autoUseConsumables;
unsafeWindow.useResurrectToSaveCount = useResurrectToSaveCount;
unsafeWindow.spamStatBoosters = spamStatBoosters;
//Slave window variables
unsafeWindow.slaveWindowUICleanup = slaveWindowUICleanup;
unsafeWindow.slaveWindowPeriodicRestart = slaveWindowPeriodicRestart;
unsafeWindow.slaveWindowPeriodicRestartInterval = slaveWindowPeriodicRestartInterval;
//Boss nuke vars
unsafeWindow.useNukeOnBossAbovePercent = useNukeOnBossAbovePercent;
// Functions
unsafeWindow.startAutoClicker = startAutoClicker;
unsafeWindow.startAutoRespawner = startAutoRespawner;
unsafeWindow.startAutoTargetSwapper = startAutoTargetSwapper;
unsafeWindow.startAutoAbilityUser = startAutoAbilityUser;
unsafeWindow.startAutoItemUser = startAutoItemUser;
unsafeWindow.startAllAutos = startAllAutos;
unsafeWindow.startAutoUpgradeManager = startAutoUpgradeManager;
unsafeWindow.stopAutoClicker = stopAutoClicker;
unsafeWindow.stopAutoRespawner = stopAutoRespawner;
unsafeWindow.stopAutoTargetSwapper = stopAutoTargetSwapper;
unsafeWindow.stopAutoAbilityUser = stopAutoAbilityUser;
unsafeWindow.stopAutoItemUser = stopAutoItemUser;
unsafeWindow.stopAutoUpgradeManager = stopAutoUpgradeManager;
unsafeWindow.stopAllAutos = stopAllAutos;
unsafeWindow.disableAutoNukes = disableAutoNukes;
unsafeWindow.castAbility = castAbility;
unsafeWindow.hasAbility = hasAbility;
unsafeWindow.abilityIsUnlocked = abilityIsUnlocked;
unsafeWindow.abilityCooldown = abilityCooldown;
unsafeWindow.toggleAutoClicker = toggleAutoClicker;
unsafeWindow.toggleAutoTargetSwapper = toggleAutoTargetSwapper;
unsafeWindow.toggleAutoAbilityUser = toggleAutoAbilityUser;
unsafeWindow.toggleAutoItemUser = toggleAutoItemUser;
unsafeWindow.toggleAutoUpgradeManager = toggleAutoUpgradeManager;
unsafeWindow.spamNoClick = spamNoClick;
unsafeWindow.toggleSpammer = toggleSpammer;
unsafeWindow.getTarget = getTarget;
unsafeWindow.currentLaneHasAbility = currentLaneHasAbility;
unsafeWindow.laneHasAbility = laneHasAbility;
unsafeWindow.getMobTypePriority = getMobTypePriority;
unsafeWindow.updateStats = updateStats;
//Hacky way to let people change vars using userscript before I set up getter/setter fns tomorrow
var varSetter = setInterval(function() {
if (debug)
console.log('updating options');
// Main vars
debug = unsafeWindow.debug;
clicksPerSecond = unsafeWindow.clicksPerSecond;
autoClickerVariance = unsafeWindow.autoClickerVariance;
respawnCheckFreq = unsafeWindow.respawnCheckFreq;
targetSwapperFreq = unsafeWindow.targetSwapperFreq;
abilityUseCheckFreq = unsafeWindow.abilityUseCheckFreq;
itemUseCheckFreq = unsafeWindow.itemUseCheckFreq;
seekHealingPercent = unsafeWindow.seekHealingPercent;
upgradeManagerFreq = unsafeWindow.upgradeManagerFreq;
autoBuyAbilities = unsafeWindow.autoBuyAbilities;
fpsThrottle = unsafeWindow.fpsThrottle;
//item use variables
useMedicsAtPercent = unsafeWindow.useMedicsAtPercent;
useMedicsAtLanePercent = unsafeWindow.useMedicsAtLanePercent;
useMedicsAtLanePercentAliveReq = unsafeWindow.useMedicsAtLanePercentAliveReq;
useNukeOnSpawnerAbovePercent = unsafeWindow.useNukeOnSpawnerAbovePercent;
useMetalDetectorOnBossBelowPercent = unsafeWindow.useMetalDetectorOnBossBelowPercent;
useStealHealthAtPercent = unsafeWindow.useStealHealthAtPercent;
useRainingGoldAbovePercent = unsafeWindow.useRainingGoldAbovePercent;
useResurrectToSaveCount = unsafeWindow.useResurrectToSaveCount;
spamStatBoosters = unsafeWindow.spamStatBoosters;
//Boss nuke vars
useNukeOnBossAbovePercent = unsafeWindow.useNukeOnBossAbovePercent;
}, 5000);
//Add closure 'debug' getter and setter
unsafeWindow.getDebug = function() {
return debug;
};
unsafeWindow.setDebug = function(state) {
debug = state;
};
}
// ================ AUTO CLICKER ================
function startAutoClicker() {
if (autoClicker) {
console.log("Autoclicker is already running!");
return;
}
autoClicker = setInterval(function() {
if (!gameRunning()) return;
//Vary the number of clicks by up to the autoClickerVariance variable (plus or minus)
var randomVariance = Math.floor(Math.random() * autoClickerVariance * 2) - (autoClickerVariance);
var clicks = clicksPerSecond + randomVariance;
// Set the variable to be sent to the server
g_Minigame.m_CurrentScene.m_nClicks += clicks;
// Anti-anti-clicker countermeasure
g_msTickRate = 1100;
// Update Gold Counter
var nClickGoldPct = g_Minigame.m_CurrentScene.m_rgGameData.lanes[g_Minigame.m_CurrentScene.m_rgPlayerData.current_lane].active_player_ability_gold_per_click;
var enemy = getTarget();
if (enemy && nClickGoldPct > 0 && enemy.m_data.hp > 0) {
var nClickGold = enemy.m_data.gold * nClickGoldPct * g_Minigame.m_CurrentScene.m_nClicks;
g_Minigame.m_CurrentScene.ClientOverride('player_data', 'gold', g_Minigame.m_CurrentScene.m_rgPlayerData.gold + nClickGold);
g_Minigame.m_CurrentScene.ApplyClientOverrides('player_data', true);
}
//Clear out the crits
var numCrits = g_Minigame.m_CurrentScene.m_rgStoredCrits.length;
g_Minigame.m_CurrentScene.m_rgStoredCrits = [];
if (debug) {
if (numCrits > 1)
console.log('Clicking ' + g_Minigame.m_CurrentScene.m_nClicks + ' times this second. (' + numCrits + ' crits).');
if (numCrits == 1)
console.log('Clicking ' + g_Minigame.m_CurrentScene.m_nClicks + ' times this second. (1 crit).');
else
console.log('Clicking ' + g_Minigame.m_CurrentScene.m_nClicks + ' times this second.');
//Calculate Damage done
var damage = g_Minigame.m_CurrentScene.CalculateDamage(g_Minigame.m_CurrentScene.m_rgPlayerTechTree.damage_per_click * userMaxElementMultiiplier * g_Minigame.m_CurrentScene.m_nClicks);
var damageStr = "(unknown)";
if (damage > 1000000000)
damageStr = (damage / 1000000000) + "B";
else if (damage > 1000000)
damageStr = (damage / 1000000) + "M";
else if (damage > 1000)
damageStr = (damage / 1000) + "K";
console.log('We did roughly ' + damageStr + ' damage in the last second.');
}
}, autoClickerFreq);
console.log("autoClicker has been started.");
}
function stopAutoClicker() {
if (autoClicker) {
clearInterval(autoClicker);
autoClicker = null;
console.log("autoClicker has been stopped.");
} else
console.log("No autoClicker is running to stop.");
}
// ================ AUTO ABILITY ITEM USE ================
function startAutoAbilityUser() {
if (autoAbilityUser) {
console.log("autoAbilityUser is already running!");
return;
}
autoAbilityUser = setInterval(function() {
if (debug)
console.log("Checking if it's useful to use an ability.");
var percentHPRemaining = g_Minigame.CurrentScene().m_rgPlayerData.hp / g_Minigame.CurrentScene().m_rgPlayerTechTree.max_hp * 100;
var target = getTarget();
var currentLane = g_Minigame.m_CurrentScene.m_rgGameData.lanes[g_Minigame.CurrentScene().m_rgPlayerData.current_lane];
var lvl = getGameLevel();
// Use any consumables that you won't run out of before round end
for (var key in ABILITIES) {
if (ABILITIES.hasOwnProperty(key)) {
var abilityID = ABILITIES[key];
//Only check consumables
if (abilityID >= ABILITIES.RESURRECTION) {
var ignoreBufferPeriod = (abilityID == ABILITIES.THROW_MONEY_AT_SCREEN);
if(hasTimeLeftToUseConsumable(abilityID, ignoreBufferPeriod))
castAbility(abilityID);
}
}
}
// Wormholes -- use before wasting items on lanes
if (hasAbility(ABILITIES.WORMHOLE) && autoUseConsumables) {
if ((lvl % CONTROL.rainingRounds === 0 && lvl > CONTROL.speedThreshold) || hasTimeLeftToUseConsumable(ABILITIES.WORMHOLE, false)) { // Use wormhole as close to the end on every 100th level (causes a 10 level jump instead of a 1)
if (debug)
console.log("Casting Wormhole! Allons-y!!!");
castAbility(ABILITIES.WORMHOLE);
}
}
// Spam permanent stat boosters if set
if(spamStatBoosters){
// Crit
if(getAbilityItemQuantity(18))
castAbility(18);
// Pumped Up
if(getAbilityItemQuantity(19))
castAbility(19);
}
// Abilities only used on targets
if (target) {
var targetPercentHPRemaining = target.m_data.hp / target.m_data.max_hp * 100;
var laneDPS = g_Minigame.m_CurrentScene.m_rgLaneData[g_Minigame.CurrentScene().m_rgPlayerData.current_lane].friendly_dps;
var timeToTargetDeath = target.m_data.hp / laneDPS;
// First priority since it can use Decrease Cooldowns
//Nuke bosses after the 1000th level and not every 200th level thereafter
var nukeBosses = (g_Minigame.m_CurrentScene.m_nCurrentLevel + 1 >= CONTROL.speedThreshold) && ((g_Minigame.m_CurrentScene.m_nCurrentLevel + 1) % CONTROL.rainingRounds !== 0);
var isBoss = (target.m_data.type == 2 || target.m_data.type === false); // Assume false is a boss
//Use Decrease Cooldowns on bosses
if(isBoss)
if(targetPercentHPRemaining > 75 && !currentLaneHasAbility(9) && hasAbility(9))
castAbility(9);
// Abilities only used when targeting Spawners (sub lvl 1000) or nuking bosses (above level 1k)
if ((target.m_data.type === 0 && g_Minigame.m_CurrentScene.m_nCurrentLevel + 1 >= CONTROL.speedThreshold) || (isBoss && nukeBosses)) {
// Morale Booster, Good Luck Charm, and Decrease Cooldowns
var moraleBoosterReady = hasAbility(ABILITIES.MORALE_BOOSTER);
var goodLuckCharmReady = hasAbility(ABILITIES.GOOD_LUCK_CHARMS);
var critReady = (hasAbility(ABILITIES.CRIT) && autoUseConsumables);
// Only use items on targets that are spawners and have nearly full health
if (targetPercentHPRemaining >= 90 && autoUseConsumables && (hasAbility(ABILITIES.CRIPPLE_SPAWNER) || hasAbility(ABILITIES.CRIPPLE_MONSTER))) {
// Check to see if Cripple Spawner and Cripple Monster items are ready to use
if (hasAbility(ABILITIES.CRIPPLE_SPAWNER)) {
castAbility(ABILITIES.CRIPPLE_SPAWNER);
} else if (hasAbility(ABILITIES.CRIPPLE_MONSTER)) {
castAbility(ABILITIES.CRIPPLE_MONSTER);
}
} else if (moraleBoosterReady || critReady || goodLuckCharmReady) {
// If we have both we want to combo them
var moraleBoosterUnlocked = abilityIsUnlocked(ABILITIES.MORALE_BOOSTER);
var goodLuckCharmUnlocked = abilityIsUnlocked(ABILITIES.GOOD_LUCK_CHARMS);
// "if Moral Booster isn't unlocked or Good Luck Charm isn't unlocked, or both are ready"
if ((!moraleBoosterUnlocked && !critReady) || !goodLuckCharmUnlocked || ((moraleBoosterReady || critReady) && (goodLuckCharmReady || !goodLuckCharmUnlocked))) {
var currentLaneHasCooldown = currentLaneHasAbility(ABILITIES.DECREASE_COOLDOWNS);
// Only use on targets that are spawners and have nearly full health
if (targetPercentHPRemaining >= 70 || (currentLaneHasCooldown && targetPercentHPRemaining >= 60)) {
// Combo these with Decrease Cooldowns ability
// If Decreased Cooldowns will be available soon, wait
if (
currentLaneHasCooldown || // If current lane already has Decreased Cooldown, or
hasAbility(ABILITIES.DECREASE_COOLDOWNS) || // If we have the ability ready
!abilityIsUnlocked(ABILITIES.DECREASE_COOLDOWNS) || // if we haven't unlocked the ability yet, or
(abilityCooldown(ABILITIES.DECREASE_COOLDOWNS) > 60) // if cooldown > 60
) {
if (hasAbility(ABILITIES.DECREASE_COOLDOWNS) && !currentLaneHasAbility(ABILITIES.DECREASE_COOLDOWNS)) {
// Other abilities won't benifit if used at the same time
if (debug)
console.log('Triggering Decrease Cooldown!');
castAbility(ABILITIES.DECREASE_COOLDOWNS);
} else {
// Use these abilities next pass
//Use crit if one's available
if (critReady) {
if (debug)
console.log("Using Crit!");
castAbility(ABILITIES.CRIT);
} else if (moraleBoosterReady) {
if (debug)
console.log("Casting Morale Booster!");
castAbility(ABILITIES.MORALE_BOOSTER);
}
if (goodLuckCharmReady) {
if (debug)
console.log("Casting Good Luck Charm!");
castAbility(ABILITIES.GOOD_LUCK_CHARMS);
}
}
}
}
}
}
// Tactical Nuke
if (hasAbility(ABILITIES.TACTICAL_NUKE) && (targetPercentHPRemaining >= useNukeOnSpawnerAbovePercent || (target.m_data.type == 2 && targetPercentHPRemaining >= useNukeOnBossAbovePercent))) {
if (debug)
console.log('Nuclear launch detected.');
castAbility(ABILITIES.TACTICAL_NUKE);
}
// Napalm
else if (target.m_data.type === 0 && hasAbility(ABILITIES.NAPALM) && targetPercentHPRemaining >= useNukeOnSpawnerAbovePercent && currentLane.enemies.length >= 4) {
if (debug)
console.log('Triggering napalm!');
castAbility(ABILITIES.NAPALM);
}
// Cluster Bomb
else if (target.m_data.type === 0 && hasAbility(ABILITIES.CLUSTER_BOMB) && targetPercentHPRemaining >= useNukeOnSpawnerAbovePercent && currentLane.enemies.length >= 4) {
if (debug)
console.log('Triggering cluster bomb!');
castAbility(ABILITIES.CLUSTER_BOMB);
}
// Boss Nuke Rounds
if (isBoss) {
// Max Elemental Damage
if (hasAbility(ABILITIES.MAX_ELEMENTAL_DAMAGE) && autoUseConsumables && targetPercentHPRemaining > useNukeOnBossAbovePercent) {
if (debug)
console.log('Using Max Elemental Damage on boss.');
castAbility(ABILITIES.MAX_ELEMENTAL_DAMAGE);
}
// Reflect Damage
if (hasAbility(ABILITIES.REFLECT_DAMAGE) && autoUseConsumables && targetPercentHPRemaining > useNukeOnBossAbovePercent) {
if (debug)
console.log('Using Reflect Damage on boss.');
castAbility(ABILITIES.REFLECT_DAMAGE);
}
}
}
//Use cases for bosses
else if (!nukeBosses && isBoss) {
if(!nukeBosses) {
//Raining Gold
if (hasAbility(ABILITIES.RAINING_GOLD) && autoUseConsumables && targetPercentHPRemaining > useRainingGoldAbovePercent && timeToTargetDeath > 30 && lvl > CONTROL.disableGoldRainLevels && (lvl <= CONTROL.speedThreshold || lvl % CONTROL.rainingRounds === 0)) {
if (debug)
console.log('Using Raining Gold on boss.');
castAbility(ABILITIES.RAINING_GOLD);
}
}
}
// Metal Detector
var treasureReady = hasAbility(ABILITIES.TREASURE) && autoUseConsumables;
if ((isBoss || target.m_data.type == 4) && timeToTargetDeath < 10) {
if (hasAbility(ABILITIES.METAL_DETECTOR) || treasureReady) {
if (treasureReady) {
if (debug)
console.log('Using Metal Detector via Treasure.');
castAbility(ABILITIES.TREASURE);
} else {
if (debug)
console.log('Using Metal Detector.');
castAbility(ABILITIES.METAL_DETECTOR);
}
}
}
}
//Estimate average player HP Percent in lane
var laneTotalPctHP = 0;
var laneTotalCount = 0;
for (var i = 1; i < 10; i++) {
var HPGuess = ((i - 1) * 10 + 5);
laneTotalPctHP += HPGuess * currentLane.player_hp_buckets[i];
laneTotalCount += currentLane.player_hp_buckets[i];
}
var avgLanePercentHP = laneTotalPctHP / laneTotalCount;
var percentAlive = laneTotalCount / (laneTotalCount + currentLane.player_hp_buckets[0]) * 100;
// Medics
if ((percentHPRemaining <= useMedicsAtPercent || (avgLanePercentHP <= useMedicsAtLanePercent && percentAlive > useMedicsAtLanePercentAliveReq)) && !g_Minigame.m_CurrentScene.m_bIsDead) {
if (debug) {
if (percentHPRemaining <= useMedicsAtPercent)
console.log("Health below threshold. Need medics!");
if (avgLanePercentHP <= useMedicsAtLanePercent && percentAlive > useMedicsAtLanePercentAliveReq)
console.log("Average lane below threshold. Need medics!");
}
// Only use if there isn't already a Medics active?
var pumpedUpReady = hasAbility(ABILITIES.PUMPED_UP) && autoUseConsumables;
var stealHealthReady = hasAbility(ABILITIES.STEAL_HEALTH) && autoUseConsumables;
if ((hasAbility(ABILITIES.MEDICS) || pumpedUpReady) && currentLaneHasAbility(ABILITIES.MEDICS) < 2) {
if (pumpedUpReady) {
if (debug)
console.log("Using Medics via Pumped Up!");
castAbility(ABILITIES.PUMPED_UP);
} else {
if (debug)
console.log("Using Medics!");
castAbility(ABILITIES.MEDICS);
}
} else if (stealHealthReady && percentHPRemaining <= useMedicsAtPercent) {
if (debug)
console.log("Using Steal Health in place of Medics!");
castAbility(ABILITIES.STEAL_HEALTH);
} else if (debug)
console.log("No medics to unleash!");
}
// Resurrect
if (hasAbility(ABILITIES.RESURRECTION) && autoUseConsumables) {
if (currentLane.player_hp_buckets[0] >= useResurrectToSaveCount) {
if (debug)
console.log('Using resurrection to save ' + currentLane.player_hp_buckets[0] + ' lane allies.');
castAbility(ABILITIES.RESURRECTION);
}
}
// Like New
if (hasAbility(ABILITIES.LIKE_NEW) && autoUseConsumables) {
var totalCD = 0;
for (i = 5; i <= 12; i++) {
if (abilityIsUnlocked(i))
totalCD += abilityCooldown(i);
}
if (totalCD * 1000 >= useLikeNewAboveCooldown) {
if (debug)
console.log('Using like new to save a total of ' + totalCD + ' seconds of cooldown.');
castAbility(ABILITIES.LIKE_NEW);
}
}
}, abilityUseCheckFreq);
console.log("autoAbilityUser has been started.");
}
function startAutoItemUser() {
autoUseConsumables = true;
console.log("Automatic use of consumables has been enabled.");
}
function stopAutoAbilityUser() {
if (autoAbilityUser) {
clearInterval(autoAbilityUser);
autoAbilityUser = null;
console.log("autoAbilityUser has been stopped.");
} else
console.log("No autoAbilityUser is running to stop.");
}
function stopAutoItemUser() {
autoUseConsumables = false;
console.log("Automatic use of consumables has been disabled.");
}
function disableAutoNukes() {
useNukeOnSpawnerAbovePercent = 200;
console.log('Automatic nukes have been disabled');
}
// ================ AUTO RESPAWNER ================
function startAutoRespawner() {
if (autoRespawner) {
console.log("autoRespawner is already running!");
return;
}
autoRespawner = setInterval(function() {
if (debug)
console.log('Checking if the player is dead.');
// Credit to /u/kolodz for base code. http://www.reddit.com/r/SteamMonsterGame/comments/39joz2/javascript_auto_respawn/
if (g_Minigame.m_CurrentScene.m_bIsDead) {
if (debug)
console.log('Player is dead. Respawning.');
RespawnPlayer();
}
}, respawnCheckFreq);
console.log("autoRespawner has been started.");
}
function stopAutoRespawner() {
if (autoRespawner) {
clearInterval(autoRespawner);
autoRespawner = null;
console.log("autoRespawner has been stopped.");
} else
console.log("No autoRespawner is running to stop.");
}
// ================ AUTO TARGET SWAPPER ================
function startAutoTargetSwapper() {
if (autoTargetSwapper) {
console.log("autoTargetSwapper is already running!");
return;
}
updateUserElementMultipliers();
autoTargetSwapperElementUpdate = setInterval(updateUserElementMultipliers, elementUpdateRate);
autoTargetSwapper = setInterval(function() {
if (debug)
console.log('Looking for a new target.');
var currentTarget = getTarget();
g_Minigame.m_CurrentScene.m_rgEnemies.each(function(potentialTarget) {
if (compareMobPriority(potentialTarget, currentTarget))
currentTarget = potentialTarget;
});
//Switch to that target
var oldTarget = getTarget();
if (currentTarget.m_data && oldTarget.m_data && currentTarget.m_data.id != oldTarget.m_data.id) {
if (debug && swapReason !== null) {
console.log(swapReason);
swapReason = null;
}
if (g_Minigame.m_CurrentScene.m_rgPlayerData.current_lane != currentTarget.m_nLane)
g_Minigame.m_CurrentScene.TryChangeLane(currentTarget.m_nLane);
g_Minigame.m_CurrentScene.TryChangeTarget(currentTarget.m_nID);
}
//Move back to lane if still targetting
else if (currentTarget.m_data && g_Minigame.m_CurrentScene.m_rgPlayerData.current_lane != currentTarget.m_nLane) {
g_Minigame.m_CurrentScene.TryChangeLane(currentTarget.m_nLane);
}
}, targetSwapperFreq);
console.log("autoTargetSwapper has been started.");
}
function stopAutoTargetSwapper() {
if (autoTargetSwapper) {
clearInterval(autoTargetSwapper);
autoTargetSwapper = null;
console.log("autoTargetSwapper has been stopped.");
} else
console.log("No autoTargetSwapper is running to stop.");
}
// ================ AUTO UPGRADE MANAGER ================
var upgradeManagerPrefilter;
if (!upgradeManagerPrefilter) {
// add prefilter on first run
$J.ajaxPrefilter(function() {
// this will be defined by the end of the script
if (upgradeManagerPrefilter !== undefined) {
upgradeManagerPrefilter.apply(this, arguments);
}
});
}
function startAutoUpgradeManager() {
if (autoUpgradeManager) {
console.log("UpgradeManager is already running!");
return;
}
/************
* SETTINGS *
************/
// Should we highlight the item we're going for next?
var highlightNext = true;
// Should we automatically by the next item?
var autoBuyNext = true;
// How many elements do you want to upgrade? If we decide to upgrade an
// element, we'll try to always keep this many as close in levels as we
// can, and ignore the rest.
var elementalSpecializations = 1;
// To estimate the overall boost in damage from upgrading an element,
// we sort the elements from highest level to lowest, then multiply
// each one's level by the number in the corresponding spot to get a
// weighted average of their effects on your overall damage per click.
// If you don't prioritize lanes that you're strongest against, this
// will be [0.25, 0.25, 0.25, 0.25], giving each element an equal
// scaling. However, this defaults to [0.4, 0.3, 0.2, 0.1] under the
// assumption that you will spend much more time in lanes with your
// strongest elements.
var elementalCoefficients = [0.4, 0.3, 0.2, 0.1];
// To include passive DPS upgrades (Auto-fire, etc.) we have to scale
// down their DPS boosts for an accurate comparison to clicking. This
// is approximately how many clicks per second we should assume you are
// consistently doing. If you have an autoclicker, this is easy to set.
var clickFrequency = clicksPerSecond + Math.ceil(autoClickerVariance / 2);
/***********
* GLOBALS *
***********/
var scene = g_Minigame.CurrentScene();
var waitingForUpdate = false;
var next = {
id: -1,
cost: 0
};
var necessary = [
{
id: 0,
level: 1
}, // Light Armor
{
id: 11,
level: 1
}, // Medics
{
id: 2,
level: 10
}, // Armor Piercing Round
{
id: 1,
level: 10
}, // Auto-fire Cannon
];
var gAbilities = [
11, // Medics
13, // Good Luck Charms
16, // Tactical Nuke
18, // Napalm
17, // Cluster Bomb
14, // Metal Detector
15, // Decrease Cooldowns
12, // Morale Booster
];
var gLuckyShot = 7;
var gBossLoot = 19;
var gElementalUpgrades = [3, 4, 5, 6]; // Fire, Water, Earth, Air
var gHealthUpgrades = [];
var gAutoUpgrades = [];
var gDamageUpgrades = [];
Object.keys(scene.m_rgTuningData.upgrades)
.sort(function(a, b) {
return a - b;
}) // why is default sort string comparison
.forEach(function(id) {
var upgrade = scene.m_rgTuningData.upgrades[id];
switch (upgrade.type) {
case 0:
gHealthUpgrades.push(+id);
break;
case 1:
gAutoUpgrades.push(+id);
break;
case 2:
gDamageUpgrades.push(+id);
break;
}
});
/***********
* HELPERS *
***********/
var getElementals = (function() {
var cache = false;
return function(refresh) {
if (!cache || refresh) {
cache = gElementalUpgrades
.map(function(id) {
return {
id: id,
level: scene.GetUpgradeLevel(id)
};
})
.sort(function(a, b) {
return b.level - a.level;
});
}
return cache;
};
})();
var getElementalCoefficient = function(elementals) {
elementals = elementals || getElementals();
return scene.m_rgTuningData.upgrades[4].multiplier *
elementals.reduce(function(sum, elemental, i) {
return sum + elemental.level * elementalCoefficients[i];
}, 0);
};
var canUpgrade = function(id) {
// do we even have the upgrade?
if (!scene.bHaveUpgrade(id)) return false;
// does it have a required upgrade?
var data = scene.m_rgTuningData.upgrades[id];
var required = data.required_upgrade;
if (required !== undefined) {
// is it at the required level to unlock?
var level = data.required_upgrade_level || 1;
return (level <= scene.GetUpgradeLevel(required));
}
// otherwise, we're good to go!
return true;
};
var calculateUpgradeTree = function(id, level) {
var data = scene.m_rgTuningData.upgrades[id];
var boost = 0;
var cost = 0;
var parent;
var cur_level = scene.GetUpgradeLevel(id);
if (level === undefined) level = cur_level + 1;
// for each missing level, add boost and cost
for (var level_diff = level - cur_level; level_diff > 0; level_diff--) {
boost += data.multiplier;
cost += data.cost * Math.pow(data.cost_exponential_base, level - level_diff);
}
// recurse for required upgrades
var required = data.required_upgrade;
if (required !== undefined) {
var parents = calculateUpgradeTree(required, data.required_upgrade_level || 1);
if (parents.cost > 0) {
boost += parents.boost;
cost += parents.cost;
parent = parents.required || required;
}
}
return {
boost: boost,
cost: cost,
required: parent
};
};
var necessaryUpgrade = function() {
var best = {
id: -1,
cost: 0
};
var wanted, id;
while (necessary.length > 0) {
wanted = necessary[0];
id = wanted.id;
if (scene.GetUpgradeLevel(id) < wanted.level) {
best = {
id: id,
cost: scene.GetUpgradeCost(id)
};
break;
}
necessary.shift();
}
return best;
};
var nextAbilityUpgrade = function() {
var best = {
id: -1,
cost: 0
};
if (autoBuyAbilities) {