-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathch_sw1ft_bot.ahk
1387 lines (1183 loc) · 30.7 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
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
; -----------------------------------------------------------------------------------------
; Clicker Heroes Sw1ft Bot
; by Sw1ftb
; -----------------------------------------------------------------------------------------
; #Warn All
#Persistent
#NoEnv
#InstallKeybdHook
#Include %A_ScriptDir%
#Include ch_bot_lib.ahk
SetControlDelay, -1
scriptName=CH Sw1ft Bot
scriptVersion=4.3.0
minLibVersion=4.0
script := scriptName . " v" . scriptVersion
clickerScript := "monster_clicker.ahk"
clickerName := clickerScript . " - AutoHotkey"
scheduleReload := false
scheduleStop := false
manualProgression := false
elapsedTime := 0.0
; -----------------------------------------------------------------------------------------
#Include system\wm_messages.ahk
; 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
}
SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79
logVariable("A_AhkVersion", A_AhkVersion)
logVariable("A_OSVersion", A_OSVersion)
logVariable("A_ScreenWidth", A_ScreenWidth)
logVariable("A_ScreenHeight", A_ScreenHeight)
if (VirtualScreenWidth > A_ScreenHeight) {
logVariable("VirtualScreenWidth", VirtualScreenWidth)
logVariable("VirtualScreenHeight", VirtualScreenHeight)
}
logVariable("A_ScreenDPI", A_ScreenDPI )
logVariable("script", script)
clientCheck()
Run, "%A_ScriptDir%\%clickerScript%",, UseErrorLevel
if (ErrorLevel != 0) {
playWarningSound()
msgbox,,% script,% "Failed to auto-start " . clickerScript . " (system error code = " . A_LastError . ")!"
}
handleAutorun()
; -----------------------------------------------------------------------------------------
; -- Hotkeys (+=Shift, !=Alt, ^=Ctrl, #=Win)
; -----------------------------------------------------------------------------------------
; Show the cursor position with Alt+Middle Mouse Button
!mbutton::
mousegetpos, xpos, ypos
msgbox,,% script,% "Cursor position: x" xpos-leftMarginOffset " y" ypos-topMarginOffset
return
; Top margin calculation when clicking in the center of the ancient tab eye
^mbutton::
mousegetpos, xpos, ypos
msgbox,,% script,% "Set browserTopMargin to: " . ypos-102
return
; -- Main Hotkeys -------------------------------------------------------------------------
; Start a Vision Run loop with Ctrl+F1
^F1::
loopVisionRun()
return
; Reload and restart Vision Run loop with Ctrl+F3
^F3::
global scheduleReload := true
handleScheduledReload("loopVisionRun")
return
; Pause/unpause the script
~Pause::Pause
return
; Abort any active run or initiated ascension with Alt+Pause
!Pause::
showUserSplash("Aborting...")
exitThread := true
return
Hotkey, !Pause, , P10
; Schedule a stop after finishing the current run with Shift+Pause
+Pause::
toggleFlag("scheduleStop", scheduleStop)
return
; Reload the script (needed after configuration changes)
!F5::
global scheduleReload := true
handleScheduledReload()
return
Hotkey, !F5, , P10
; Schedule a script reload after finishing the current run, then restart it
+^F5::
toggleFlag("scheduleReload", scheduleReload)
return
; Re-initialize coordinates (needed after moving or re-sizing the client window)
!F6::
showUserSplash("Re-initialize coordinates... ")
clientCheck()
clickerInitialize()
return
Hotkey, !F6, , P10
; -- Supplementary Hotkeys ----------------------------------------------------------------
; Suspend/Unsuspend all other Hotkeys with Ctrl+Esc
~^Esc::Suspend, Toggle
return
; Autosave the game
^F11::
save()
return
Hotkey, ^F11, , P5
; Raid once for free with Win+F6
#F6::
raid()
return
Hotkey, #F6, , P5
; One paid raid
#F7::
raid(1)
return
Hotkey, #F7, , P5
; Paid raids
#F8::
raid(1, raidAttempts)
return
Hotkey, #F8, , P5
; Toggle boolean (true/false) flags with Shift+Ctrl+Fx
+^F1::
toggleFlag("autoAscend", autoAscend)
return
+^F6::
toggleFlag("playNotificationSounds", playNotificationSounds)
return
Hotkey, +^F6, , P5
+^F7::
toggleFlag("playWarningSounds", playWarningSounds)
return
+^F11::
toggleFlag("saveBeforeAscending", saveBeforeAscending)
return
; -- Test Hotkeys -------------------------------------------------------------------------
; Ctrl+Alt+F1 should scroll down to the bottom, then back up
^!F1::
scrollToBottom()
scrollToTop()
return
; Ctrl+Alt+F2 should switch between all used tabs
^!F2::
switchToAncientTab()
switchToRelicTab()
switchToClanTab()
switchToCombatTab()
return
; -----------------------------------------------------------------------------------------
; -- Functions
; -----------------------------------------------------------------------------------------
getClickable(active:=1) {
global
local xPos, yPos
if (active = 1) {
clickPos(524, 487)
clickPos(747, 431)
clickPos(760, 380)
clickPos(873, 512)
clickPos(1005, 453)
clickPos(1053, 443)
} else {
loop % clickableImageFiles.Length()
{
imgClickable.file := clickableImageFiles[A_Index]
if (locateImage(imgClickable, xPos, yPos)) {
clickPos(xPos, yPos, 1, 1) ; absolute pos
break
}
}
}
}
; Level up and upgrade all heroes
initRun(initMode:=0) {
global
local hasAscendButton := false
local hasSkillBar := false
local hasNoSkillLocked := false
showDebugSplash("Init Run @ Lvl " . getCurrentZone())
switchToCombatTab()
scrollToTop()
reFocus()
local foundDK := false
local xButton, yButton, xDK, yDK, x
local clickCount := initMode = 1 ? 1 : 2
locateImage(imgCoin, xButton, yButton) ; get a x coordinate for the hire/lvl up buttons
loop 10 ; pages
{
if (locateImage(imgDK, xDK, yDK) or locateImage(imgDKG, xDK, yDK)) {
foundDK := true
}
loop 5 ; attempts per page
{
if (locateImage(imgDimmedSkill, x, yButton)
or locateImage(imgHire, x, yButton)) {
if (foundDK and yButton > yDK) {
; Don't level anything below Frostleaf
continue
}
ctrlClick(xButton, yButton, clickCount, 1, 1)
} else {
break
}
}
if (foundDK) {
if (locateImage(imgAscend)) {
hasAscendButton := true
}
break
}
scrollDown(5)
}
scrollToBottom()
buyAvailableUpgrades()
if (initMode = 0) {
if (locateImage(imgSkillBar)) {
hasSkillBar := true
}
if (!locateImage(imgSkillLocked)) {
hasNoSkillLocked := true
}
logVariable("hasAscendButton", hasAscendButton, true, "TRACE")
logVariable("hasSkillBar", hasSkillBar, true, "TRACE")
logVariable("hasNoSkillLocked", hasNoSkillLocked, true, "TRACE")
}
return hasAscendButton and hasSkillBar and hasNoSkillLocked
}
getEndZone() {
global
return endLvlActive > endLvlIdle ? endLvlActive : endLvlIdle
}
getState() {
global
if (!WinExist(winName)) {
return -2 ; no ch window
}
if (getCurrentZone() = 0) {
return -1 ; vision, but not in browser
}
if (!locateImage(imgSmile)) {
return 0 ; vision, but not finding anything
}
if (getCurrentZone() < getEndZone() and !readyToAscend) {
return 1 ; ready for progression
} else {
return 2 ; ready to ascend
}
}
loopVisionRun() {
global
readyToAscend := false
local state := 0
showUserSplash("Starting Vision Runs!")
logVariable("browser", browser)
logVariable("browserTopMargin", browserTopMargin)
logVariable("gildedRanger", rangers[gildedRanger])
logVariable("endLvlIdle", endLvlIdle)
logVariable("endLvlActive", endLvlActive)
logVariable("maxIdleMonsterKillTime", maxIdleMonsterKillTime)
logVariable("maxMonsterKillTime", maxMonsterKillTime)
logVariable("chronos", chronos)
logVariable("kumawakamaru", kumawakamaru)
logVariable("vaagur", vaagur)
if (endLvlActive > 0) {
logArray("skillCombo", skillCombo)
}
logVariable("clickableHuntDelay", clickableHuntDelay)
logVariable("saveBeforeAscending", saveBeforeAscending, true)
logVariable("autoAscend", autoAscend, true)
logVariable("noSleep", noSleep, true)
logVariable("levelSolomon", levelSolomon, true)
loop
{
state := getState()
if (state < 1) {
showWarningSplash("Start failed (state = " . state . ")! Trying again...")
clientCheck()
clickerInitialize()
continue
}
if (getState() = 1) {
visionRun()
}
if (getState() = 2) {
if (saveBeforeAscending) {
save()
}
ascend(autoAscend)
readyToAscend := false
if (levelSolomon) {
solomonLeveler(solomonLevels)
}
handleScheduledStop()
handleScheduledReload("loopVisionRun")
}
}
}
visionRun() {
global
exitThread := false
isResuming := false
local startRunTime := A_TickCount
local isInitiated := false
local isClickerRunning := false
local isComboActive := false
local triggerActive := false
local hasBomberBuff := gildedRanger = 12 ? true : false
local hasGogBuff := gildedRanger = 13 ? true : false
local foundTheHero := false
local xBtn := 0, yBtn := 0, isNew := 0, startAt := 0
local xSkill := 0, ySkill := 0, skillSearch := false
local locateGildedDelay := gildedRanger ? 60 : 4
local locateBuyUpgradesDelay := 20
local progressCheckDelay := 10
local t := 0
local elapsedRunTime := 0
local comboDelay := skillCombo[1]
comboIndex := 2
manualProgression := false
switchToCombatTab()
setProgressionMode()
if (!locateImage(imgProgression)) {
showTraceSplash("Manual progression: On")
manualProgression := true
SetTimer, nextZoneTimer, 500
}
local previousZone := 0
local previousIdleZone := 0
local zoneMonsters := 10.0 + kumawakamaru
local secPerMonster := 0
local farmMonsterKillTime := 2.0 ; stop and farm before boss when exceeded
farmTime := 60
bossFightTimer := 30 + chronos + 1
bossFailCounter := 0
local startZone := getCurrentZone()
local zone := startZone
zoneTime := {}
local initiatedZone := 0
local earliestAscendZone := 140
local estimatedAscendLevel := gildedRanger ? abs(gildedRanger) * 250 - 75 : earliestAscendZone
local initZone := 146
local earlyGameZone := 175
local tr1 := -1 ; Samurai
local tr2 := ""
if (gildedCheck(tr1, tr2, earlyGameZone)) {
showSplash("Recommended transitional hero(es): " . rangers[tr1] . " > " . rangers[tr2])
}
local earlyGameMode := true
gameMode := "INIT"
showSplash("Starting Vision Run")
showDebugSplash("Early game mode ends @ Lvl " . earlyGameZone)
if (estimatedAscendLevel > earliestAscendZone) {
showDebugSplash("Estimated ascension @ Lvl " . estimatedAscendLevel + 400 . " (idle), " . estimatedAscendLevel + 800 . " (active)")
}
startMonitoring()
startTimer()
reFocus()
SetTimer, zoneTimer, 500
loop
{
if (exitThread) {
zoneTime := ""
SetTimer, nextZoneTimer, off
SetTimer, zoneTimer, off
SetTimer, comboTimer, off
clickerStop()
stopTimer()
stopMonitoring()
showUserSplash("Vision Run aborted!")
exit
}
; Gief moar rubies plox!
if (mod(t, clickableHuntDelay) = 0) {
getClickable(isClickerRunning)
}
; Active zone?
if (isActiveZone(zone) or triggerActive) {
if (!isClickerRunning) {
; Yup, start hammering!
clickerStart() ; ~38 CPS
isClickerRunning := true
}
if (isInitiated and isClickerRunning and !isComboActive) {
; Save combos till we have all skills
Gosub, comboTimer
SetTimer, comboTimer, % comboDelay * 1000 + 250
isComboActive := true
}
} else if (isClickerRunning) {
clickerStop()
isClickerRunning := false
}
; Early progression
if (zone < earlyGameZone) {
if (manualProgression) {
if (zone > 100) {
showTraceSplash("Manual progression: Off")
manualProgression := false
SetTimer, nextZoneTimer, off
}
}
if (mod(t, locateBuyUpgradesDelay) = 0 or isResuming) {
; Scroll down when loosing track of the upgrades button
if (!locateImage(imgBuyUpgrades)) {
scrollToBottom()
sleep % coinPickUpDelay * 1000
buyAvailableUpgrades()
}
skillSearch := true
isResuming := false
}
if (mod(t, lvlUpDelay) = 0) {
; Level heroes bottom up
if (locateImageUp(imgCoin, xBtn, yBtn)) {
ctrlClick(xBtn, yBtn, 2, 1, 1)
}
}
if (zone > 30 and zone > initiatedZone and mod(zone-6, 30) = 0 and zone < initZone) {
; Lvl earlier heroes at zones 36, 66, 96 and 126
initRun(1) ; x 100
initiatedZone := zone
}
} else if (earlyGameMode) {
showTraceSplash("Ending early game mode @ Lvl " . zone)
earlyGameMode := false
}
if (!isInitiated and zone >= initZone) {
; If enough gold, run init
isInitiated := initRun()
isResuming := true
}
; Normal progression
if (!earlyGameMode and ((!foundTheHero and mod(t, locateGildedDelay) = 0) or isResuming)) {
; Traverse bottom up till we find the first gilded hero/ranger we can lvl up
if (locateGilded(xBtn, yBtn, isNew, startAt, !gildedRanger, foundTheHero)) {
maxClick(xBtn, yBtn, 2, 1)
if (!gildedRanger) {
; "Power 5" mode, moving between gilded heroes
startAt := yBtn + yWinPos - 56
} else {
if (isNew) {
showDebugSplash("New gilded hero found @ Lvl " . zone)
buyAvailableUpgrades()
}
skillSearch := true
}
isResuming := false
} else {
scrollToBottom()
earlyGameZone := zone + 25
earlyGameMode := true
showTraceSplash("No gilded hero found yet! Early game mode extended to Lvl " . earlyGameZone)
}
}
zone := getCurrentZone()
; [Hybrid] Trigger active?
if (!triggerActive and isHybrid() and !isClickerRunning) {
if (zone > 10 and zone > previousIdleZone) {
previousIdleZone := zone
; Calculate average monster kill time for the previous 5 zones
secPerMonster := timeBetweenZones(zone-5, zone) / 5.0 / zoneMonsters
; Still insta-killing?
if (secPerMonster >= maxIdleMonsterKillTime) {
; No, trigger active
showDebugSplash("Lvl " . zone-5 . " -> " . zone . " - Avg monster kill time: " . round(secPerMonster, 2))
triggerActive := true
}
} else if (gameMode = "INIT" and isInitiated and t > 5) {
triggerActive := true
}
}
; Ascend or keep farming?
if (zone > 10 and zone > previousZone and mod(zone-4, 5) = 0 and gameMode = "PROGRESSING") {
; Progressing @ zone before boss
previousZone := zone
; Calculate average monster kill time for the previous zone
secPerMonster := timeBetweenZones(zone-2, zone) / 2.0 / zoneMonsters
; Fast enough to kill next boss easily?
if (secPerMonster >= farmMonsterKillTime) {
showDebugSplash("Lvl " . zone-2 . " -> " . zone . " - Avg monster kill time: " . round(secPerMonster, 2))
; No, time to ascend?
if (secPerMonster >= maxMonsterKillTime and zone > estimatedAscendLevel) {
; Yeah, we are done here
triggerAscension("End of run")
break
}
if (gameMode = "PROGRESSING") {
; Farm a bit before next boss
farmTime := ceil(secPerMonster * 25)
startFarming()
}
}
}
; Progressing?
if (mod(t, progressCheckDelay) = 0) {
if (!locateImage(imgProgression) and gameMode != "FARMING") {
if (++bossFailCounter < 2) {
setProgressionMode()
} else {
if (zone > estimatedAscendLevel) {
triggerAscension("Stuck at high level boss")
break
} else {
startFarming()
}
}
}
}
; Level up...
if (!earlyGameMode and mod(t, lvlUpDelay) = 0 and !isResuming) {
if (matchPixelColor(blueColor, xBtn+xWinPos, yBtn+yWinPos)) {
if (!foundTheHero) {
; Get Bomber Max and Gog global gold and dps buffs when we can
if (!hasBomberBuff and zone > 2930) {
getBuff(imgMax, hasBomberBuff, skillSearch)
} else if (!hasGogBuff and zone > 3210) {
getBuff(imgGog, hasGogBuff, skillSearch)
}
}
; ... when we can afford to do so
ctrlClick(xBtn, yBtn, 2, 1, 1)
} else if (gildedRanger and !matchPixelColor(goldColor, xBtn-51+xWinPos, yBtn+yWinPos)) {
if (!matchPixelColor(brightGoldColor, xBtn-51+xWinPos, yBtn+yWinPos)) {
; ... or not, lost sight of our gilded hero
showTraceSplash("Trigger gilded hero locator")
clickAwayImage(imgCombatTab)
isResuming := true
}
}
}
if (skillSearch) {
; Aquire possible new skills
while (locateImage(imgSkill, xSkill, ySkill)) {
clickPos(xSkill, ySkill, 1, 1)
sleep 500
}
if (!locateImage(imgDimmedSkill)) {
skillSearch := false
}
}
zone := getCurrentZone()
t += 1
sleep 1000
} until zone > getEndZone() or readyToAscend
if (earlyGameMode) {
maxLevels() ; get some extra souls from levels
}
SetTimer, nextZoneTimer, off
SetTimer, zoneTimer, off
if (useZoneDataLogger) {
logZoneData(zdlStart, zone, zdlInterval)
}
zoneTime := ""
SetTimer, comboTimer, off
clickerStop()
stopTimer()
stopMonitoring()
elapsedRunTime := (A_TickCount - startRunTime) / 1000
showSplash("Vision Run duration: " . formatSeconds(elapsedRunTime))
}
gildedCheck(byref tr1, byref tr2, byref earlyGameZone) {
global
if (gildedRanger > 0) {
if (gildedRanger > 3) {
if (gildedRanger > 14) {
; Use Wepwawet as last transitional hero for gilded Betty or Midas
tr2 := 14
} else {
tr2 := gildedRanger - 3
}
if (gildedRanger > 6) {
tr1 := tr2 - 3
earlyGameZone := tr1 * 250 - 75
}
}
return 1
}
return 0
}
triggerAscension(msg, delay:=0) {
global
if (!readyToAscend) {
if (delay > 0) {
showDebugSplash("Trigger ascension in " . floor(delay) . " seconds (" . msg . ")")
SetTimer, ascendTimer, % -delay * 1000
} else {
showDebugSplash("Ascension triggered! (" . msg . ")")
readyToAscend := true
}
}
}
setGameMode(newGameMode) {
global
showTraceSplash(gameMode . " --> " . newGameMode . " @ Lvl " . getCurrentZone())
gameMode := newGameMode
}
isHybrid() {
global
return endLvlActive > endLvlIdle and endLvlIdle > 0
}
isActiveZone(zone) {
global
if (zone < 10) {
return true
}
if (zone < endLvlActive) {
if (endLvlIdle < endLvlActive and zone < endLvlIdle) {
return false
}
return true
}
return false
}
getBuff(image, byref hasBuff, byref skillSearch) {
global
local who := image = imgMax ? "Bomber Max" : "Gog"
scrollToBottom()
if (upLocator(image, image.file, xImg, yImg)) {
showDebugSplash("Get buff from " . who . " @ Lvl " . getCurrentZone())
ctrlClick(xImg-320, yImg+43, 2, 1, 1) ; hire
skillSearch := true
}
hasBuff := true
}
; Max levels early game for some extra souls
maxLevels() {
global
showDebugSplash("Max levels for souls")
scrollToTop()
reFocus()
local xButton, yButton
loop 9 ; pages
{
ControlSend,, {vk51 down}, ahk_id %chWinId% ; {q}, {vk51} or {sc010}
sleep 500
if (locateImage(imgMaxLvl, xButton, yButton)) {
loop 4
{
clickPos(xButton, yButton, 1, 1)
sleep % zzz
yButton += oLvl
}
}
scrollDown(5)
}
ControlSend,, {vk51 up}, ahk_id %chWinId%
}
clickerStart(duration := 0) {
sendClickerMsg(WM_CLICKER_START)
if (duration > 0) {
SetTimer, clickerStopTimer, % -duration * 1000
}
}
clickerPause() {
sendClickerMsg(WM_CLICKER_PAUSE)
}
clickerStop() {
sendClickerMsg(WM_CLICKER_STOP)
sleep 1000
}
clickerReload() {
sendClickerMsg(WM_CLICKER_RELOAD)
}
clickerInitialize() {
sendClickerMsg(WM_CLICKER_INITIALIZE)
}
clickerModeFast() {
sendClickerMsg(WM_CLICKER_MODE_FAST)
}
clickerModeSlow() {
sendClickerMsg(WM_CLICKER_MODE_SLOW)
}
getClickerStatus() {
return sendClickerMsg(WM_CLICKER_STATUS, 1)
}
sendClickerMsg(msg, wait:=0) {
global
local reply := 0
local tmm := A_TitleMatchMode
local dhw := A_DetectHiddenWindows
SetTitleMatchMode, 2
DetectHiddenWindows, on
if (!wait) {
PostMessage, %msg%,,,,% clickerName
} else {
SendMessage, %msg%,,,,% clickerName
if (ErrorLevel != "FAIL") {
reply := ErrorLevel
} else {
showWarningSplash("SendMessage failed! " . clickerScript . " started?")
}
}
DetectHiddenWindows,% dhw
SetTitleMatchMode,% tmm
return reply
}
openSaveDialog() {
global
clickPos(xSettings, ySettings)
sleep % zzz * 3
clickPos(xSave, ySave)
sleep % zzz * 4
}
save() {
global
local fileName := "ch" . A_NowUTC . ".txt"
local newFileName := ""
showDebugSplash("Save to " . fileName)
; Close possible other dialog box
ControlSend,, {esc}, ahk_class %dialogBoxClass%
clickerPause()
openSaveDialog()
; 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)
sleep % zzz
}
ascend(autoYes:=false) {
global
exitThread := false
local x, y
startMonitoring()
if (autoYes) {
if (autoAscendDelay > 0) {
showWarningSplash(autoAscendDelay . " seconds till ASCENSION! (Abort with Alt+Pause)", autoAscendDelay)
if (exitThread) {
exitThread := false
stopMonitoring()
showUserSplash("Ascension aborted!")
exit
}
}
} else {
playWarningSound()
msgbox, 260,% script,Salvage Junk Pile & Ascend? ; default no
ifmsgbox no
{
stopMonitoring()
showUserSplash("Salvage aborted!")
exit
}
}
salvageJunkPile() ; must salvage junk relics before ascending
setFarmMode()
showDebugSplash("Ascend @ Lvl " . getCurrentZone())
clickPos(xAscend, yAscend) ; 0.23 ascend button
sleep % zzz * 4
clickPos(xYes, yYes)
sleep % zzz * 2
stopMonitoring()
sleep 1000 ; wait a sec
}
salvageJunkPile() {
global
switchToRelicTab()
if (autoAscend) {
if (displayRelicsDuration > 0) {
clickPos(xRelic, yRelic) ; focus (will show the upgrade screen in 0.23)
}
if (displayRelicsDuration > 0) {
showWarningSplash("Salvaging junk in " . displayRelicsDuration . " seconds! (Abort with Alt+Pause)", displayRelicsDuration)
if (exitThread) {
exitThread := false
showUserSplash("Salvage aborted!")
exit
}
}
if (displayRelicsDuration > 0) {
clickPos(xUpgradeNo, yUpgradeNo) ; don't upgrade
sleep % zzz
clickPos(xRelic+100, yRelic) ; remove focus
}
}
showDebugSplash("Salvage Junk Pile")
clickPos(xSalvageJunk, ySalvageJunk)
sleep % zzz * 4
clickPos(xDestroyYes, yDestroyYes)
sleep % zzz * 2
}
buyAvailableUpgrades() {
global
clickPos(xBuy, yBuy, 2)
sleep % zzz * 3
}
raid(doSpend:=0, attempts:=1) {
global
exitThread := false
local xBtn := 0, yBtn := 0, raidDuration := 34 * 1000
local wasClickerRunning := getClickerStatus()
local mode := doSpend ? "Paid" : "Free"
showUserSplash(mode . " Raid x " . attempts)
Thread, NoTimers ; block timers if mid run
switchToClanTab()
sleep 1000
clickAwayImage(imgClanRaid)
if (!wasClickerRunning) {
clickerStart()
sleep 2500
}
loop % attempts
{
if (exitThread) {
exitThread := false
showUserSplash("Raid aborted!")
break
}
if (clickAwayImage(imgClanCollect)) {
break
}
if (doSpend) {
showSplash(mode . " Raid (" . A_Index . "/" . attempts . ")")
if (locateImage(imgClanFightAgain, xBtn, yBtn)) {
while (!locateImage(imgYes)) {
clickPos(xBtn, yBtn, 1, 1)
sleep 250
}
clickAwayImage(imgYes)
clickAwayImage(imgClanFight)
sleep % raidDuration
}
} else {
if (clickAwayImage(imgClanFight)) {
sleep % raidDuration
}
}
getClickable()
}