forked from swiftb/clicker-heroes-sw1ft-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch_sw1ft_bot.ahk
737 lines (613 loc) · 16.6 KB
/
ch_sw1ft_bot.ahk
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
; -----------------------------------------------------------------------------------------
; Clicker Heroes Sw1ft Bot
; by Sw1ftb
; -----------------------------------------------------------------------------------------
#Persistent
#NoEnv
#InstallKeybdHook
#Include %A_ScriptDir%
#Include ch_bot_lib.ahk
SetControlDelay, -1
scriptName=CH Sw1ft Bot
scriptVersion=2.41
minLibVersion=1.32
script := scriptName . " v" . scriptVersion
scheduleReload := false
scheduleStop := false
; -----------------------------------------------------------------------------------------
; Load system default settings
#Include system\ch_bot_default_settings.ahk
IfNotExist, ch_bot_settings.ahk
{
FileCopy, system\ch_bot_default_settings.ahk, ch_bot_settings.ahk
}
; Load user settings
#Include *i ch_bot_settings.ahk
if (libVersion != minLibVersion) {
showWarningSplash("The bot lib version must be " . minLibVersion . "!")
ExitApp
}
if (useConfigurationAssistant) {
configurationAssistant()
}
clientCheck()
if (deepRunClicks) {
Run, monster_clicker.ahk,, UseErrorLevel
if (ErrorLevel != 0) {
playWarningSound()
msgbox,,% script,% "Failed to auto-start monster_clicker.ahk (system error code = " . A_LastError . ")!"
}
}
handleAutorun()
; -----------------------------------------------------------------------------------------
; -- Hotkeys (+=Shift, !=Alt, ^=Ctrl)
; -----------------------------------------------------------------------------------------
; Suspend/Unsuspend all other Hotkeys
^Esc::Suspend, Toggle
return
; Show the cursor position with Alt+Middle Mouse Button
!mbutton::
mousegetpos, xpos, ypos
msgbox,,% script,% "Cursor position: x" xpos-leftMarginOffset " y" ypos-topMarginOffset
return
; Pause/Unpause script
Pause::Pause
return
; Abort speed/deep runs and auto ascensions with Alt+Pause
!Pause::
showSplashAlways("Aborting...")
exitThread := true
exitDRThread := true
return
; Quick tests:
; Ctrl+Alt+F1 should scroll down to the bottom
; Ctrl+Alt+F2 should switch to the relics tab and then back
^!F1::
scrollToBottom()
return
^!F2::
switchToRelicTab()
switchToCombatTab()
return
; Alt+F1 to F4 are here to test the individual parts of the full speed run loop
!F1::
getClickable()
return
!F2::
initRun()
return
!F3::
switchToCombatTab()
speedRun()
return
!F4::
ascend(autoAscend)
return
; Reload script with Alt+F5
!F5::
global scheduleReload := true
handleScheduledReload()
return
; Speed run loop
^F1::
loopSpeedRun()
return
; Stop looping when current speed run finishes with Shift+Pause
+Pause::
toggleFlag("scheduleStop", scheduleStop)
return
; Deep run
; Use (after a speed run)
^F2::
deepRun()
return
; Set previous ranger as re-gild target
^F6::
reGildRanger := reGildRanger > rangers.MinIndex() ? reGildRanger-1 : reGildRanger
showSplashAlways("Re-gild ranger set to " . rangers[reGildRanger])
return
; Set next ranger as re-gild target
^F7::
reGildRanger := reGildRanger < rangers.MaxIndex() ? reGildRanger+1 : reGildRanger
showSplashAlways("Re-gild ranger set to " . rangers[reGildRanger])
return
; Move "reGildCount" gilds to the target ranger (will pause the monster clicker if running)
^F8::
critical
playNotificationSound()
msgbox, 4,% script,% "Move " . reGildCount . " gilds to " . rangers[reGildRanger] . "?"
ifmsgbox no
return
regild(reGildRanger, reGildCount) ; will pause the monster clicker if running
return
; Autosave the game
^F11::
critical
monsterClickerPause()
save()
return
; Toggle boolean (true/false) flags
+^F1::
toggleFlag("autoAscend", autoAscend)
return
+^F2::
toggleFlag("screenShotRelics", screenShotRelics)
return
+^F5::
toggleFlag("scheduleReload", scheduleReload)
return
+^F6::
toggleFlag("playNotificationSounds", playNotificationSounds)
return
+^F7::
toggleFlag("playWarningSounds", playWarningSounds)
return
+^F8::
toggleFlag("showSplashTexts", showSplashTexts)
return
+^F11::
toggleFlag("saveBeforeAscending", saveBeforeAscending)
return
+^F12::
toggleFlag("debug", debug)
return
; -----------------------------------------------------------------------------------------
; -- Functions
; -----------------------------------------------------------------------------------------
; Automatically configure initDownClicks and yLvlInit settings.
configurationAssistant() {
global
if (irisLevel < 145) {
playWarningSound()
msgbox,,% script,% "Your Iris do not fulfill the minimum level requirement of 145 or higher!"
exit
}
if (irisThreshold(2010)) { ; Astraea
initDownClicks := [6,5,6,5,6,3]
yLvlInit := 241
} else if (irisThreshold(1760)) { ; Alabaster
; [6,6,6,5,6,3], 227
; [6,5,6,6,6,3], 260
; [5,6,6,5,6,3], 293
initDownClicks := [6,6,6,5,6,3]
yLvlInit := 227
} else if (irisThreshold(1510)) { ; Cadmia
initDownClicks := [6,6,6,6,6,3]
yLvlInit := 240
} else if (irisThreshold(1260)) { ; Lilin
initDownClicks := [6,6,6,6,6,3]
yLvlInit := 285
} else if (irisThreshold(1010)) { ; Banana
initDownClicks := [6,7,6,7,6,3]
yLvlInit := 240
} else if (irisThreshold(760)) { ; Phthalo
initDownClicks := [6,7,7,6,7,3]
yLvlInit := 273
} else if (irisThreshold(510)) { ; Terra
initDownClicks := [7,7,7,7,7,3]
yLvlInit := 240
} else if (irisThreshold(260)) { ; Atlas
initDownClicks := [7,7,7,8,7,3]
yLvlInit := 273
} else { ; Dread Knight
initDownClicks := [7,8,7,8,7,4]
yLvlInit := 257
}
if (irisLevel < optimalLevel - 1001) {
local levels := optimalLevel - 1001 - irisLevel
playNotificationSound()
msgbox,,% script,% "Your Iris is " . levels . " levels below the recommended ""optimal level - 1001"" rule."
}
}
; Check if Iris is within a certain threshold that can cause a toggling behaviour between different settings
irisThreshold(lvl) {
global
local upperThreshold := lvl + 19
local lowerThreshold := lvl - 20
if (irisLevel >= lowerThreshold and irisLevel < upperThreshold) {
playWarningSound()
msgbox,,% script,% "Threshold proximity warning! You should level up your Iris to " . upperThreshold . " or higher."
}
return irisLevel > lvl
}
; Level up and upgrade all heroes
initRun() {
global
switchToCombatTab()
clickPos(xHero, yHero) ; prevent fails
upgrade(initDownClicks[1],2,,2) ; cid --> brittany
upgrade(initDownClicks[2]) ; fisherman --> leon
upgrade(initDownClicks[3]) ; seer --> mercedes
upgrade(initDownClicks[4],,,,2) ; bobby --> king
upgrade(initDownClicks[5],2,,,2) ; ice --> amenhotep
upgrade(initDownClicks[6],,,2) ; beastlord --> shinatobe
upgrade(0,,,,,true) ; grant & frostleaf
scrollToBottom()
buyAvailableUpgrades()
}
upgrade(times, cc1:=1, cc2:=1, cc3:=1, cc4:=1, skip:=false) {
global
if (!skip) {
ctrlClick(xLvl, yLvlInit, cc1)
ctrlClick(xLvl, yLvlInit + oLvl, cc2)
}
ctrlClick(xLvl, yLvlInit + oLvl*2, cc3)
ctrlClick(xLvl, yLvlInit + oLvl*3, cc4)
scrollDown(times)
}
loopSpeedRun() {
global
mode := hybridMode ? "hybrid" : "speed"
showSplashAlways("Starting " . mode . " runs...")
loop
{
getClickable()
sleep % coinPickUpDelay * 1000
initRun()
if (activateSkillsAtStart) {
activateSkills(speedRunStartCombo[2])
}
speedRun()
if (hybridMode) {
deepRun()
}
if (saveBeforeAscending) {
save()
}
ascend(autoAscend)
handleScheduledStop()
handleScheduledReload(true)
}
}
; All heroes/rangers are expected to "insta-kill" everything at max speed (i.e. around
; 7 minutes per 250 levels). Only the last 2-3 minutes should slow down slightly.
speedRun() {
global
local stint := 0
local stints := 0
local tMax := 7 * 60 ; seconds
local lMax := 250 ; zones
local lvlAdjustment := round(firstStintAdjustment * lMax / tMax)
local zoneLvl := gildedRanger * lMax + lvlAdjustment ; approx zone lvl where we can buy our gilded ranger @ lvl 150
local lvls := zoneLvl - irisLevel ; lvl's to get there
local firstStintButton := 1
local firstStintTime := 0
local midStintTime := 0
if (lvls > lMax + 2*60*lMax/tMax) ; add a mid stint if needed
{
midStintTime := tMax
lvls -= lMax
stints += 1
} else if (lvls > lMax) {
firstStintButton := 2
}
if (lvls > 0)
{
firstStintTime := ceil(lvls * tMax / lMax)
stints += 1
}
local srDuration := speedRunTime * 60
local totalClickDelay := ceil(srDuration / lvlUpDelay * zzz / 1000 + nextHeroDelay * stints)
local lastStintTime := srDuration - firstStintTime - midStintTime - totalClickDelay
stints += 1
local lastStintButton := gildedRanger = 9 ? 3 : 2 ; special case for Astraea
if (debug)
{
local nl := "`r`n"
local s := " " ; Reddit friendly formatting
local output := ""
output .= s . "irisLevel = " . irisLevel . nl
output .= s . "optimalLevel = " . optimalLevel . nl
output .= s . "speedRunTime = " . speedRunTime . nl
output .= s . "gildedRanger = " . rangers[gildedRanger] . nl
output .= s . "-----------------------------" . nl
output .= s . "initDownClicks = "
for i, e in initDownClicks {
output .= e " "
}
output .= nl
output .= s . "yLvlInit = " . yLvlInit . nl
output .= s . "firstStintAdjustment = " . firstStintAdjustment . "s" . nl
output .= s . "-----------------------------" . nl
output .= s . "lvlAdjustment = " . lvlAdjustment . nl
output .= s . "zoneLvl = " . zoneLvl . nl
output .= s . "lvls = " . lvls . nl
output .= s . "srDuration = " . formatSeconds(srDuration) . nl
output .= s . "firstStintButton = " . firstStintButton . nl
output .= s . "firstStintTime = " . formatSeconds(firstStintTime) . nl
output .= s . "midStintTime = " . formatSeconds(midStintTime) . nl
output .= s . "lastStintTime = " . formatSeconds(lastStintTime) . nl
output .= s . "totalClickDelay = " . formatSeconds(totalClickDelay) . nl
clipboard := % output
msgbox % output
return
}
showSplash("Starting speed run...")
if (irisLevel < 2 * lMax + 10) ; Iris high enough to start with a ranger?
{
switchToCombatTab()
scrollDown(initDownClicks[1])
toggleMode() ; toggle to progression mode
lvlUp(firstStintTime, 0, 3, ++stint, stints) ; nope, let's bridge with Samurai
scrollToBottom()
} else {
scrollToBottom()
toggleMode() ; toggle to progression mode
if (firstStintTime > 0) {
lvlUp(firstStintTime, 1, firstStintButton, ++stint, stints)
scrollWayDown(3)
}
}
if (midStintTime > 0) {
lvlUp(midStintTime, 1, 2, ++stint, stints)
scrollWayDown(2)
}
lvlUp(lastStintTime, 1, lastStintButton, ++stint, stints)
showSplash("Speed run completed.")
}
deepRun() {
global
exitDRThread := false
local drDuration := deepRunTime * 60
local button := gildedRanger = 9 ? 3 : 2 ; special case for Astraea
local y := yLvl + oLvl * (button - 1)
showSplash("Starting deep run...")
startMouseMonitoring()
startProgress("Deep Run Progress", 0, drDuration // barUpdateDelay)
monsterClickerOn()
local comboDelay := deepRunCombo[1]
local comboIndex := 2
local stopHuntIndex := drDuration - stopHuntThreshold * 60
local t := 0
loop % drDuration
{
if (exitDRThread) {
monsterClickerOff()
stopProgress()
stopMouseMonitoring()
showSplashAlways("Deep run aborted!")
exit
}
if (deepRunClicks) {
clickPos(xMonster, yMonster)
}
if (mod(t, comboDelay) = 0) {
activateSkills(deepRunCombo[comboIndex])
comboIndex := comboIndex < deepRunCombo.MaxIndex() ? comboIndex+1 : 2
}
if (mod(t, lvlUpDelay) = 0) {
ctrlClick(xLvl, y, 1, 0)
}
if (mod(t, clickableHuntDelay) = 0 and t < stopHuntIndex) {
getClickable()
}
t += 1
updateProgress(t // barUpdateDelay, drDuration - t)
sleep 1000
}
monsterClickerOff()
stopProgress()
stopMouseMonitoring()
showSplash("Deep run ended.")
sleep 1000
}
monsterClickerOn(isActive:=true) {
global
if (deepRunClicks) {
send {shift down}{f1 down}{f1 up}{shift up}
}
}
monsterClickerPause() {
global
if (deepRunClicks) {
send {shift down}{f2 down}{f2 up}{shift up}
}
}
monsterClickerOff() {
global
if (deepRunClicks) {
send {shift down}{f3 down}{f3 up}{shift up}
}
}
lvlUp(seconds, buyUpgrades, button, stint, stints) {
global
exitThread := false
local y := yLvl + oLvl * (button - 1)
local title := "Speed Run Progress (" . stint . "/" . stints . ")"
startMouseMonitoring()
startProgress(title, 0, seconds // barUpdateDelay)
if (buyUpgrades) {
ctrlClick(xLvl, y)
buyAvailableUpgrades()
}
maxClick(xLvl, y)
local t := 0
loop % seconds
{
if (exitThread) {
stopProgress()
stopMouseMonitoring()
showSplashAlways("Speed run aborted!")
exit
}
if (mod(t, lvlUpDelay) = 0) {
ctrlClick(xLvl, y)
}
t += 1
updateProgress(t // barUpdateDelay, seconds - t)
sleep 1000
}
stopProgress()
stopMouseMonitoring()
}
save() {
global
local fileName := "ch" . A_NowUTC . ".txt"
local newFileName := ""
clickPos(xSettings, ySettings)
sleep % zzz * 3
clickPos(xSave, ySave)
sleep % zzz * 4
; Change the file name...
if (saveMode = 1) {
ControlSetText, Edit1, %fileName%, ahk_class %dialogBoxClass%
} else {
ControlSend, Edit1, %fileName%, ahk_class %dialogBoxClass%
}
sleep % zzz * 4
; ... and double-check that it's correct
ControlGetText, newFileName, Edit1, ahk_class %dialogBoxClass%
if (newFileName = fileName) {
ControlClick, %saveButtonClassNN%, ahk_class %dialogBoxClass%,,,, NA
} else {
ControlSend,, {esc}, ahk_class %dialogBoxClass%
}
sleep % zzz * 3
clickPos(xSettingsClose, ySettingsClose)
}
ascend(autoYes:=false) {
global
exitThread := false
local extraClicks := 6
local y := yAsc - extraClicks * buttonSize
if (autoYes) {
if (autoAscendDelay > 0) {
showWarningSplash(autoAscendDelay . " seconds till ASCENSION! (Abort with Alt+Pause)", autoAscendDelay)
if (exitThread) {
exitThread := false
showSplashAlways("Ascension aborted!")
exit
}
}
} else {
playWarningSound()
msgbox, 260,% script,Salvage Junk Pile & Ascend? ; default no
ifmsgbox no
exit
}
salvageJunkPile() ; must salvage junk relics before ascending
switchToCombatTab()
scrollDown(ascDownClicks)
sleep % zzz * 2
; Scrolling is not an exact science, hence we click above, center and below
loop % 2 * extraClicks + 1
{
clickPos(xAsc, y)
y += buttonSize
}
sleep % zzz * 4
clickPos(xYes, yYes)
sleep % zzz * 2
}
salvageJunkPile() {
global
switchToRelicTab()
if (autoAscend) {
if (screenShotRelics || displayRelicsDuration > 0) {
clickPos(xRelic, yRelic) ; focus
}
if (screenShotRelics) {
screenShot()
}
if (displayRelicsDuration > 0) {
showWarningSplash("Salvaging junk in " . displayRelicsDuration . " seconds! (Abort with Alt+Pause)", displayRelicsDuration)
if (exitThread) {
exitThread := false
showSplashAlways("Salvage aborted!")
exit
}
}
if (screenShotRelics || displayRelicsDuration > 0) {
clickPos(xRelic+100, yRelic) ; remove focus
}
}
clickPos(xSalvageJunk, ySalvageJunk)
sleep % zzz * 4
clickPos(xDestroyYes, yDestroyYes)
sleep % zzz * 2
}
buyAvailableUpgrades() {
global
clickPos(xBuy, yBuy)
sleep % zzz * 3
}
; Move "gildCount" gilds to given ranger
regild(ranger, gildCount) {
global
monsterClickerPause()
switchToCombatTab()
scrollToBottom()
clickPos(xGilded, yGilded)
sleep % zzz * 2
ControlSend,, {shift down}, % winName
clickPos(rangerPositions[ranger].x, rangerPositions[ranger].y, gildCount)
sleep % 1000 * gildCount/100*5
ControlSend,, {shift up}, % winName
clickPos(xGildedClose, yGildedClose)
sleep % zzz * 2
}
; Toggle between farm and progression modes
toggleMode() {
global
ControlSend,, {a down}{a up}, % winName
sleep % zzz
}
activateSkills(skills) {
global
clickPos(xHero, yHero) ; prevent fails
loop,parse,skills,-
{
ControlSend,,% A_LoopField, % winName
sleep 100
}
sleep 1000
}
startMouseMonitoring() {
setTimer, checkMousePosition, 250
}
stopMouseMonitoring() {
setTimer, checkMousePosition, off
}
handleScheduledReload(autorun := false) {
global
if(scheduleReload) {
showSplashAlways("Reloading bot...", 1)
autorun_flag := autorun = true ? "/autorun" : ""
Run "%A_AhkPath%" /restart "%A_ScriptFullPath%" %autorun_flag%
}
}
handleScheduledStop() {
global
if(scheduleStop) {
showSplashAlways("Scheduled stop. Exiting...")
scheduleStop := false
exit
}
}
handleAutorun() {
global
param_1 = %1%
if(param_1 = "/autorun") {
showSplash("Autorun speedruns...", 1)
loopSpeedrun()
}
}
; -----------------------------------------------------------------------------------------
; -- Subroutines
; -----------------------------------------------------------------------------------------
; Safety zone around the in-game tabs (that triggers an automatic script pause when breached)
checkMousePosition:
MouseGetPos,,, window
if (window = WinExist(winName)) {
WinActivate
MouseGetPos, x, y
xL := getAdjustedX(xSafetyZoneL)
xR := getAdjustedX(xSafetyZoneR)
yT := getAdjustedY(ySafetyZoneT)
yB := getAdjustedY(ySafetyZoneB)
if (x > xL && x < xR && y > yT && y < yB) {
playNotificationSound()
msgbox,,% script,Click safety pause engaged. Continue?
}
}
return