forked from swiftb/clicker-heroes-sw1ft-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch_sw1ft_bot.ahk
596 lines (481 loc) · 12.4 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
; -----------------------------------------------------------------------------------------
; Clicker Heroes Sw1ft Bot
; by Sw1ftb
; -----------------------------------------------------------------------------------------
#Persistent
#NoEnv
#InstallKeybdHook
#Include %A_ScriptDir%
#Include ch_bot_lib.ahk
SetWorkingDir %A_ScriptDir%
SetControlDelay, -1
scriptName=CH Troggobot (based on Sw1ft bot)
scriptVersion=2.41
minLibVersion=1.32
heroConfig := []
script := scriptName . " v" . scriptVersion
scheduleReload := false
scheduleStop := false
endRound := false
currentRoundTime := 0
; -----------------------------------------------------------------------------------------
; 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()
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
scrollToBottom()
return
; Abort speed/deep runs and auto ascensions with Alt+Pause
!Pause::
showSplashAlways("Aborting...")
monsterClickerOff()
exitThread := true
exitDRThread := true
return
+^k::
updateBuyColor()
return
+^up::
currentRoundTime := currentRoundTime + roundModifier
return
+^down::
newRoundTime := currentRoundTime - roundModifier
if (newRoundTime > 0) {
currentRoundTime := newRoundTime
} else {
showSplashAlways("Cannot decrease round time below 0")
}
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
; Autosave the game
^F11::
critical
monsterClickerTogglePause()
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
}
}
; Check if Iris is within a certain threshold that can cause a toggling behaviour between different settings
irisThreshold(lvl) {
global
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
showDebug()
DebugAppend("Starting speed runs")
monsterClickerOn()
monsterClickerTogglePause() ; pause
loop
{
getClickable()
sleep % coinPickUpDelay * 1000
initRun()
activateSkills(speedRunStartCombo[2])
speedRun()
if (saveBeforeAscending) {
save()
}
ascend(autoAscend)
handleScheduledStop()
handleScheduledReload(true)
}
}
speedRun() {
global
DebugAppend("Starting new speed run`r`n")
switchToCombatTab()
scrollToBottom()
toggleMode() ; toggle to progression mode
local i := duration * 60 ; seconds to run after we reach gilded ranger
local t := 0 ; total time
local heroCount := 0 ; increase when switching to next ranger
local y := yLvl + oLvl * (2 - 1) ; 2 is second button
local d := 0 ; duration on one hero
DebugAppend("duration = " duration ", heroCounter = " heroCounter)
monsterClickerTogglePause() ; resume
while ( i > 0 || heroCount <> heroCounter){
if (herCount <> heroCounter && d >= 900) { ; if we are not at last hero and spent more than 15 minutes we force move to next one
heroCount := heroCount + 1
d := 0
monsterClickerTogglePause()
scrollToTop()
scrollToBottom()
monsterClickerTogglePause()
}
if (mod(t, lvlUpDelay) = 0) {
monsterClickerTogglePause()
maxClick(xLvl, y)
if (heroCount <> heroCounter && isBuyVisible() = 0) {
heroCount := heroCount + 1
if (heroCount = heroCounter) {
DebugAppend("Reached last hero after " d // 60 " minutes")
} else {
DebugAppend("Moving to next hero: " heroCount " after " d // 60 " minutes")
}
d := 0
scrollToTop() ; in case scroll bar gets bugged
scrollToBottom()
}
monsterClickerTogglePause()
}
if (mod(t, clickableAndUpgradeDelay) = 0) {
monsterClickerTogglePause()
buyAvailableUpgrades()
if (i >= 1500) { ; pick only if more than 25 minutes are left
getClickable()
}
monsterClickerTogglePause()
}
sleep 1000
t := t + 1
updateProgress(t)
if (heroCount = heroCounter) { ; start counting down when we reach last gilded ranger
i := i - 1
updateRemaining(i)
} else {
d := d + 1 ; time spent on current hero
}
}
monsterClickerTogglePause() ; Pause
DebugAppend("Finished run in " t // 60 " minutes")
}
monsterClickerOn(isActive:=true) {
global
send {shift down}{f1 down}{f1 up}{shift up}
}
monsterClickerTogglePause() {
global
send {shift down}{f2 down}{f2 up}{shift up}
}
monsterClickerOff() {
global
send {shift down}{f3 down}{f3 up}{shift up}
}
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
}
; 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()
}
}
loadHeroConfig() {
global
FileRead, data, heroconfig.txt
heroConfig := StrSplit(data, ",")
}
saveHeroConfig() {
global
data := ""
for i, value in heroConfig {
data := data value ","
}
StringTrimRight, data, data, 1
FileDelete, heroconfig.txt
FileAppend, %data%, heroconfig.txt
}
; -----------------------------------------------------------------------------------------
; -- 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