-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCoC.ahk
1260 lines (1138 loc) · 27.1 KB
/
CoC.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
#SingleInstance force
#Include OCR.ahk
#Include GDIp.ahk
#Include GDIpHelper.ahk
idleOption := 0
buttonOption := 0
donate := 0
errorCheck := 0
error := 0
useNN := 1
myTroopPercent := -1
myGold := -1
myElixir := -1
myDarkElixir := -1
myTrophies := -1
myGems := -1
myBuilders := -1
enemyGold := -1
enemyElixir := -1
dGold := -1
dElixir := -1
dDarkElixir := -1
dTrophies := -1
dAttacked := -1
barbarian := 1
archer := 2
goblin := 3
giant := 4
wallBreaker := 5
balloon := 6
wizard := 7
healer := 8
dragon := 9
pekka := 10
minion := 11
hogRider := 12
valkyrie := 13
golem := 14
witch := 15
barbarianKing := 16
archerQueen := 17
lightning := 18
heal := 19
rage := 20
jump := 21
freeze := 22
santa := 23
clan := 24
numSprites := 24
CoordMode, Pixel, Relative
CoordMode, Mouse, Relative
SetTitleMatchMode, RegEx
SetFormat, float, 0.16
SetDefaultMouseSpeed, 5
; Create the popup menu by adding some items to it.
Menu, Toggles, Add, Keep from idling, IdleHandler
Menu, Toggles, Add, Donate Goblins, DonateHandler
Menu, Toggles, Add, Check for Errors, ErrorHandler
Menu, MyMenu, Add, Toggle Options, :Toggles
Menu, Buttons, Add, No Action, ButtonsHandler
Menu, Buttons, Add, Troop Spray, ButtonsHandler
Menu, Buttons, Add, Wall Upgrade, ButtonsHandler
Menu, Buttons, Check, No Action
Menu, MyMenu, Add, MouseButton1 Options, :Buttons
Menu, Automations, Add, Gobblegobble, GoblinHandler
Menu, Automations, Add, Drop Trophies Below 200, DropTrophies
Menu, Automations, Add, Drop All Trophies, DropAllTrophies
Menu, MyMenu, Add, Full Automation, :Automations
Menu, SmallAutomations, Add, Train Goblins, TrainGoblins
Menu, SmallAutomations, Add, Collect Resources, CollectResources
Menu, SmallAutomations, Add, Test Colors, TestColors
Menu, MyMenu, Add, Small Routines, :SmallAutomations
Menu, Configuration, Add, Set Collector Locations, ConfigResourceLocation
Menu, Configuration, Add, Set Barracks Locations, ConfigBarracksLocation
Menu, Configuration, Add, Set Camp Location, ConfigCampLocation
Menu, MyMenu, Add, Configuration, :Configuration
Menu, MyMenu, Add, Get Resources, MenuHandler ; Add another menu item beneath the submenu.
Menu, MyMenu, Add ; Add a separator line.
Menu, MyMenu, Add, Cum on step it up, Sanic
Menu, MyMenu, Add, Show Debug Window, ShowDebug
Menu, MyMenu, Add, Lock MouseY, LockMouseY
Menu, MyMenu, Add, asdf, GatherTroopSelectors
Menu, MyMenu, Add, Close Script, CoCExit
BlockInput, MouseMoveOff
;SetTimer, CopyLogToDropbox, 1800000
Gosub, IdleHandler
Gosub, ReadConfig
Gui, Add, Text,, Trophies:
Gui, Add, Text,, Gems:
Gui, Add, Text,, Builders:
Gui, Add, Text,, Gold:
Gui, Add, Text,, Elixir:
Gui, Add, Text,, DarkElixir:
Gui, Add, Text,w100 vTrophies ys, % myTrophies
Gui, Add, Text,w100 vGems, % myGems
Gui, Add, Text,w100 vBuilders, % myBuilders
Gui, Add, Text,w100 vGold, % myGold
Gui, Add, Text,w100 vElixir, % myElixir
Gui, Add, Text,w100 vDarkElixir, % myDarkElixir
Gui, Add, Text,ys, EnemyGold:
Gui, Add, Text,, EnemyElixir:
Gui, Add, Text,, Error:
Gui, Add, Text,w100 vEnemyGold ys, % enemyGold
Gui, Add, Text,w100 vEnemyElixir, % enemyElixir
Gui, Add, Text,w100 vError, % error
return ; End of script's auto-execute section.
ShowDebug:
Gui, Show, ,
return
Sanic:
SoundPlay, sanictheweedhog.mp3
;SoundPlay, sanic.mp3
SoundSetWaveVolume, 100
return
WriteLog:
IfNotExist, log.csv
{
FileAppend, time`,myGold`,myElixir`,myDarkElixir`,myTrophies`,myGems`,myBuilders`n, log.csv
}
time := ((A_YDay*24)+A_Hour)*60+A_Min
FileAppend, %time%`,%myGold%`,%myElixir%`,%myDarkElixir%`,%myTrophies%`,%myGems%`,%myBuilders%`n, log.csv
return
WriteLog2:
IfNotExist, log2.csv
{
FileAppend, myTrophies`,flowPixels`,netGold`,netElixir`,netDarkElixir`,netTrophies`,attacked`n, log2.csv
}
FileAppend, %myTrophies%`,%pix%`,%dGold%`,%dElixir%`,%dDarkElixir%`,%dTrophies%`,%dAttacked%`n, log2.csv
return
CopyLogToDropbox:
if InStr(FileExist(HOMEDRIVE HOMEPATH "\Dropbox"), "D")
FileCopy, log.csv, %HOMEDRIVE%%HOMEPATH%\Dropbox\CoClog.csv , 1
return
UpdateGui:
GuiControl,, Trophies, %myTrophies%
GuiControl,, Gems, %myGems%
GuiControl,, Builders, %myBuilders%
GuiControl,, Gold, %myGold%
GuiControl,, Elixir, %myElixir%
GuiControl,, DarkElixir, %myDarkElixir%
GuiControl,, EnemyGold, %enemyGold%
GuiControl,, EnemyElixir, %enemyElixir%
GuiControl,, Error, %error%
return
DrawText(text,x,y,res,size) {
StartDrawGDIP()
ClearDrawGDIP()
Gdip_SetSmoothingMode(G,4)
Gdip_TextToGraphics(G,text, "x350 y200 cff000000 r4 s72")
EndDrawGDIP()
return
}
CoCExit:
ExitApp
return
GetMyStats:
GoSub, GetWindow
GoSub, MyGold
GoSub, MyElixir
GoSub, MyDarkElixir
GoSub, MyTrophies
GoSub, MyGems
GoSub, MyBuilders
GoSub, UpdateGui
return
MenuHandler:
GoSub, MyGold
GoSub, MyElixir
GoSub, MyDarkElixir
GoSub, MyTrophies
GoSub, MyGems
GoSub, MyBuilders
MsgBox Gold: %myGold% Elixir: %myElixir% DarkElixir: %myDarkElixir% Trophies: %myTrophies% Gems: %myGems% Builders: %myBuilders%
return
ButtonsHandler:
menu, %A_ThisMenu%, Check, %A_ThisMenuItem%
if (A_ThisMenuItem = "No Action") {
menu, %A_ThisMenu%, Uncheck, Wall Upgrade
menu, %A_ThisMenu%, Uncheck, Troop Spray
buttonOption := 0
} else if (A_ThisMenuItem = "Troop Spray") {
menu, %A_ThisMenu%, Uncheck, No Action
menu, %A_ThisMenu%, Uncheck, Wall Upgrade
buttonOption := 1
} else if (A_ThisMenuItem = "Wall Upgrade") {
menu, %A_ThisMenu%, Uncheck, No Action
menu, %A_ThisMenu%, Uncheck, Troop Spray
buttonOption := 2
}
Hotkey, IfWinActive, BlueStacks
if (buttonOption = 0) {
Hotkey, XButton1,TroopSpray, On
Hotkey, XButton1,, Off
} else if (buttonOption = 1){
Hotkey, XButton1, TroopSpray, On
} else if (buttonOption = 2){
Hotkey, XButton1, WallUpgrade, On
}
return
Esc::Reload
F1::GoSub, GoblinHandler
F2::GoSub, LockMouseY
F3::GoSub, DataLoop
F4::GoSub, GetDecision
#z::Menu, MyMenu, Show ; i.e. press the Win-Z hotkey to show the menu.
IdleHandler:
menu, Toggles, ToggleCheck, Keep from idling
idleOption := !idleOption
if (idleOption) {
SetTimer, CheckInactive, 270000
} else {
SetTimer, CheckInactive, Off
}
return
ErrorHandler:
menu, Toggles, ToggleCheck, Check for Errors
errorCheck := !errorCheck
if (errorCheck) {
SetTimer, CheckError, 60000
} else {
SetTimer, CheckError, Off
}
return
DonateHandler:
menu, Toggles, ToggleCheck, Donate Goblins
donate := !donate
return
CheckError:
Gosub, GetWindow
PixelGetColor color, 803, 488
PixelGetColor color2, 853, 488
PixelGetColor color3, 753, 488
if (color = 0x282828 and color2 = 0x282828 and color3 = 0x282828) {
Click 803, 488
error := 1
GoSub, UpdateGui
return
}
PixelGetColor color, 803, 499
PixelGetColor color2, 853, 499
PixelGetColor color3, 753, 499
if (color = 0x282828 and color2 = 0x282828 and color3 = 0x282828) {
Click 803, 499
error := 1
GoSub, UpdateGui
return
}
error := 0
GoSub, UpdateGui
return
CheckInactive:
Gosub, GetWindow
BlockInput On
MouseGetPos, xPos, yPos
MouseClick,,CX1,CY1,,0
MouseMove,xPos,yPos,0
BlockInput Off
return
return
GoblinHandler:
GoSub, GetWindow
BlockInput, MouseMove
if(idleOption = 1) {
Gosub, IdleHandler
}
if(errorCheck = 0) {
Gosub, ErrorHandler
}
SetTimer, WriteLog, 600000
Click 444, 77
Gosub, WaitForHome
Gosub, GetMyStats
Gosub, DropTrophies
Loop {
Gosub, MyTroopTotal
Gosub, TrainGoblins
Gosub, CollectResources
if(myTroopPercent < 0.3) {
Loop {
Sleep 10000
GoSub, MyTroopTotal
if (myTroopPercent > 0.3)
break
}
}
Gosub, GetWindow
Gosub, AttackButton
Gosub, FindMatchButton
Gosub, WaitForMatch
Gosub, UpdateGui
GoSub, GatherTroopSelectors
if(useNN) {
if(myTrophies < 150) {
Loop {
attack := NNDecision()
if(attack > 0.85) {
FileCopy, base.jpg, BasePictures\Attacked\%A_Now%.jpg
useGoblins:= Ceil((enemyGold + enemyElixir) / 400)
if (useGoblins > 60) {
useGoblins := 60
}
DropGobsGold(useGoblins)
dAttacked := 1
Gosub, ExitBattleIfDone
break
} else {
FileCopy, base.jpg, BasePictures\Surrendered\%A_Now%.jpg
Gosub, NextMatchButton
Gosub, WaitForMatch
}
}
} else {
Loop {
attack := NNDecision()
if(attack > 0.85) {
FileCopy, base.jpg, BasePictures\Attacked\%A_Now%.jpg
useGoblins:= Ceil((enemyGold + enemyElixir/2) / 400)
if (useGoblins > 60) {
useGoblins := 60
}
DropGobsGold(useGoblins)
dAttacked := 1
Gosub, ExitBattleIfDone
break
} else {
FileCopy, base.jpg, BasePictures\Surrendered\%A_Now%.jpg
DropGobsGold(0)
dAttacked := 0
Gosub, Surrender
Gosub, WaitForHome
Gosub, AttackButton
Gosub, FindMatchButton
Gosub, WaitForMatch
}
}
}
} else {
pix:=GetFlowPixels()
if(pix < 135000) {
Gosub, EnemyGold
Gosub, EnemyElixir
if((enemyGold + enemyElixir)>2000) {
useGoblins:= Ceil((enemyGold + enemyElixir) / 400)
if (useGoblins > 60) {
useGoblins := 60
}
DropGobsGold(useGoblins)
dAttacked := 1
Gosub, ExitBattleIfDone
} else {
DropGobsGold(0)
dAttacked := 0
Gosub, Surrender
}
} else {
DropGobsGold(0)
dAttacked := 0
Gosub, Surrender
}
}
Gosub, WaitForHome
dGold := myGold
dElixir := myElixir
dDarkElixir := myDarkElixir
dTrophies := myTrophies
Gosub, GetMyStats
dGold := myGold - dGold
dElixir := myElixir - dElixir
dDarkElixir := myDarkElixir - dDarkElixir
dTrophies := myTrophies - dTrophies
}
return
DropTrophies:
Gosub, MyTrophies
if(myTrophies < 200) {
return
}
Gosub, TrainGoblins
Loop {
Gosub, AttackButton
Gosub, FindMatchButton
Gosub, WaitForMatch
Gosub, GatherTroopSelectors
SelectTroop(goblin)
SelectTroop(barbarianKing)
SelectTroop(archerQueen)
Gosub, ZoomOut
Gosub, ScrollUp
Gosub, DropTroop
Gosub, Surrender
Gosub, WaitForHome
Gosub, MyTrophies
if(myTrophies < 200) {
return
}
}
return
DropAllTrophies:
Gosub, TrainGoblins
Loop {
Gosub, AttackButton
Gosub, FindMatchButton
Gosub, WaitForMatch
Gosub, GatherTroopSelectors
SelectTroop(goblin)
SelectTroop(barbarianKing)
SelectTroop(archerQueen)
Gosub, ZoomOut
Gosub, ScrollUp
Gosub, DropTroop
Gosub, Surrender
Gosub, WaitForHome
}
return
GetWindow:
Loop {
WinActivate, BlueStacks
IfWinActive, BlueStacks
break
Sleep 1000
}
return
ExitButton:
Gosub, GetWindow
Click 1556, 64
return
AttackButton:
Gosub, GetWindow
Click 85, 788
return
FindMatchButton:
Gosub, GetWindow
Click 281, 671
return
NextMatchButton:
Gosub, GetWindow
Click 1464, 648
return
EndMatchButton:
Gosub, GetWindow
Click 101, 676
return
TrainTroopsButton:
Gosub, GetWindow
Click 991, 782
return
TrainGoblinButton:
Gosub, GetWindow
Click 805, 438
return
TroopTrainExitButton:
Gosub, GetWindow
Click 1201, 201
return
ReturnFromBattleButton:
Gosub, GetWindow
Click 802, 702
return
SurrenderCancelButton:
Gosub, GetWindow
Click 692, 536
return
SurrenderOkayButton:
Gosub, GetWindow
Click 913, 536
return
ZoomOut:
Gosub, GetWindow
MouseMove, 803, 505
SendInput, {Control Down}
Sleep 300
SendInput, -
Sleep 300
SendInput, -
Sleep 300
SendInput, {Control Up}
return
ScrollUp:
Gosub, GetWindow
MouseMove, 803, 305, 0
Click down
MouseMove, 803, 705
Click up
return
WaitForMatch:
GoSub, GetWindow
Sleep 1000
Loop {
GoSub, GetWindow
Sleep 1000
;If there was a shield, hit okay and continue
PixelGetColor, color, 914, 511
MouseMove, 914, 511
if (color = 0x75EAD0) {
Click 914, 511
}
;look for the red end battle button, finish blocking if found
PixelGetColor, color, 141, 660
MouseMove, 141, 660
if (color = 0x5450EF) {
break
}
;if there was an error message the last time we are now back at the home screen but stuck
if (error = 1) {
;wait until we check for errors and there isn't one, sleep ten seconds, then restart the automation
Loop {
Sleep 10000
if (error = 0) {
Gosub, GoblinHandler
}
}
}
}
return
WaitForHome:
Gosub, GetWindow
Sleep 1000
Loop {
GoSub, GetWindow
Sleep 1000
;Look for the shield icon on the home screen (opaque so it's easy to get)
PixelGetColor, color, 831, 63
if (color = 0xF4F4EC) {
break
}
}
return
ExitBattleIfDone:
Gosub, GetWindow
lastResources := enemyGold + enemyElixir
i := 0
Loop {
Sleep 500
PixelGetColor, color, 802, 702
if (color = 0x7CECD4) {
Click 802, 702
return
}
GoSub, EnemyGold
GoSub, EnemyElixir
if ((enemyGold + enemyElixir) = lastResources) {
i := i + 1
if (i > 20) {
GoSub, Surrender
return
}
}
lastResources := enemyGold + enemyElixir
GoSub, UpdateGui
if ((enemyGold + enemyElixir) < 2000) {
GoSub, Surrender
return
}
}
return
Surrender:
Sleep 500
GoSub, EndMatchButton
GoSub, SurrenderOkayButton
GoSub, ReturnFromBattleButton
return
TrainGoblins:
Gosub, GetWindow
Gosub, ZoomOut
Gosub, ScrollUp
Loop %totalBarracks% {
Train(A_Index,goblin,60)
}
return
Train(barracks,troop,amount) {
Gosub, GetWindow
MouseClick,, BX%barracks%, BY%barracks%
Gosub, TrainTroopsButton
TrainTroop(troop,amount)
Gosub, TroopTrainExitButton
return
}
;while in the barracks dialogue, click a troop for an amount
TrainTroop(troop,amount) {
if (troop < 1 or troop > 10 )
return
clickX := Mod(troop-1,5)*141+525
clickY := ((troop-1)//5)*146+429
Loop %amount% {
MouseClick,, clickX, clickY
}
return
}
DropTroop:
SelectTroop(goblin)
SelectTroop(barbarianKing)
SelectTroop(archerQueen)
MouseMove 799, 53
Click
return
ConfigResourceLocation:
Gosub, GetWindow
Gosub, ZoomOut
Gosub, ScrollUp
Gosub, GetWindow
WinGetPos,winX,winY,winWidth,winHeight
InputBox, numCollectors, Number of Collectors, How many collectors do you have? (E`,G`, and DE) After inputting the amount`, click on each collector once and do not move the screen. It also works better if you select the bottom most collectors and work up ,,300,250,winX+winWidth/2-150,winY+winHeight/2-125,,,13
if ErrorLevel
return
if numCollectors is not integer
{
Msgbox, Not a valid number
return
}
IniDelete, config.ini, collectors
IniWrite, %numCollectors%, config.ini, collectors, numCollectors
Loop %numCollectors% {
KeyWait, LButton, D
KeyWait, LButton, U
MouseGetPos, xPos, yPos
IniWrite, %xPos%, config.ini, collectors, CX%A_Index%
IniWrite, %yPos%, config.ini, collectors, CY%A_Index%
}
GoSub, ReadConfig
return
ConfigBarracksLocation:
Gosub, GetWindow
Gosub, ZoomOut
Gosub, ScrollUp
Gosub, GetWindow
WinGetPos,winX,winY,winWidth,winHeight
InputBox, numBarracks, Number of Barracks, How many normal barracks do you have? After inputting the amount`, click on each barracks once and do not move the screen.,,300,250,winX+winWidth/2-150,winY+winHeight/2-125,,,4
if ErrorLevel
return
if numBarracks is not integer
{
Msgbox, Not a valid number
return
}
IniDelete, config.ini, barracks
IniWrite, %numBarracks%, config.ini, barracks, numBarracks
Loop %numBarracks% {
KeyWait, LButton, D
KeyWait, LButton, U
MouseGetPos, xPos, yPos
IniWrite, %xPos%, config.ini, barracks, BX%A_Index%
IniWrite, %yPos%, config.ini, barracks, BY%A_Index%
}
GoSub, ReadConfig
return
ConfigCampLocation:
Gosub, GetWindow
Gosub, ZoomOut
Gosub, ScrollUp
Gosub, GetWindow
WinGetPos,winX,winY,winWidth,winHeight
MsgBox, 0, Camp Location, After clicking okay on this window, click on an army camp and do not move the screen. Also`, make sure the camp will not be covered by gui buttons for the game.
IniDelete, config.ini, camp
KeyWait, LButton, D
KeyWait, LButton, U
MouseGetPos, xPos, yPos
IniWrite, %xPos%, config.ini, camp, campX
IniWrite, %yPos%, config.ini, camp, campY
GoSub, ReadConfig
return
ReadConfig:
IfNotExist, config.ini
{
MsgBox, Please configure barracks and collector locations (which will be saved)
return
}
IniRead, totalBarracks, config.ini, barracks, numBarracks
Loop %totalBarracks% {
IniRead, BX%A_Index%, config.ini, barracks, BX%A_Index%
IniRead, BY%A_Index%, config.ini, barracks, BY%A_Index%
}
IniRead, totalCollectors, config.ini, collectors, numCollectors
Loop %totalCollectors% {
IniRead, CX%A_Index%, config.ini, collectors, CX%A_Index%
IniRead, CY%A_Index%, config.ini, collectors, CY%A_Index%
}
IniRead, campX, config.ini, camp, campX
IniRead, campY, config.ini, camp, campY
return
CollectResources:
Gosub, GetWindow
Gosub, ZoomOut
Gosub, ScrollUp
Loop 2 {
Loop %totalCollectors% {
MouseClick,, CX%A_Index%, CY%A_Index%,,0
}
}
return
DonateGoblins:
Gosub, GetWindow
Click 22, 466
Sleep 500
Click WheelUp
Sleep 500
Loop {
Gosub, GetWindow
PixelSearch, Dx, Dy, 166, 223, 167, 852, 0x50DCB4, 3, fast
if ErrorLevel = 0
{
Click %Dx%, %Dy%
Dx := Dx + 361
Dy := Dy - 85
MouseMove %Dx%, %Dy%
Click Down
Sleep 1500
Click Up
Dx := Dx - 361
Dy := Dy + 85
Click %Dx%, %Dy%
} else {
break
}
}
Click 440, 471
Sleep 500
return
MyGold:
GoSub, GetWindow
myGold := GetOCR(1344, 55, 180, 25, "activeWindow")
StringReplace, myGold, myGold, %A_SPACE%, , All
StringReplace, myGold, myGold, `n, , All
if(myGold = "")
myGold := 0
return
MyElixir:
GoSub, GetWindow
myElixir := GetOCR(1344, 122, 185, 25, "activeWindow")
StringReplace, myElixir, myElixir, %A_SPACE%, , All
StringReplace, myElixir, myElixir, `n, , All
if(myElixir = "")
myElixir := 0
return
MyDarkElixir:
GoSub, GetWindow
myDarkElixir := GetOCR(1409, 186, 122, 25, "activeWindow")
StringReplace, myDarkElixir, myDarkElixir, %A_SPACE%, , All
StringReplace, myDarkElixir, myDarkElixir, `n, , All
if(myDarkElixir = "")
myDarkElixir := 0
return
MyTrophies:
GoSub, GetWindow
myTrophies := GetOCR(77, 119, 87, 27, "activeWindow")
StringReplace, myTrophies, myTrophies, %A_SPACE%, , All
StringReplace, myTrophies, myTrophies, `n, , All
if(myTrophies = "")
myTrophies := 0
return
MyGems:
GoSub, GetWindow
myGems := GetOCR(1440, 251, 92, 23, "activeWindow")
StringReplace, myGems, myGems, %A_SPACE%, , All
StringReplace, myGems, myGems, `n, , All
if(myGems = "")
myGems := 0
return
MyBuilders:
GoSub, GetWindow
myBuilders := GetOCR(654, 52, 68, 26, "activeWindow")
StringReplace, myBuilders, myBuilders, %A_SPACE%, , All
StringReplace, myBuilders, myBuilders, `n, , All
myBuilders := SubStr(myBuilders,1,1)
if(myBuilders = "")
myBuilders := 0
return
EnemyGold:
GoSub, GetWindow
enemyGold := GetOCR(68, 110, 162, 38, "activeWindow")
StringReplace, enemyGold, enemyGold, %A_SPACE%, , All
StringReplace, enemyGold, enemyGold, `n, , All
if(enemyGold = "")
enemyGold := 0
return
EnemyElixir:
GoSub, GetWindow
enemyElixir := GetOCR(64, 144, 162, 38, "activeWindow")
StringReplace, enemyElixir, enemyElixir, %A_SPACE%, , All
StringReplace, enemyElixir, enemyElixir, `n, , All
if(enemyElixir = "")
enemyElixir := 0
return
TestColors:
SetDefaultMouseSpeed, 0
WinActivate, Paint
Loop {
WinActivate, Paint
PixelSearch tempX, tempY, 15, 155, 1135, 809, 0x2662DB, 5, Fast
; 0xE058D5
if ErrorLevel {
MsgBox, Done
SetDefaultMouseSpeed, 10
break
}
Click %tempX%, %tempY%
}
return
GetFlowPixels() {
GoSub, GetWindow
GoSub, ZoomOut
WinGetPos, xOffset, yOffset,,,A
fileJpg := "base.jpg"
filePng := "filter.png"
fileTxt := "base.txt"
jpegQual := 100
convertPath=convert.exe
;take a screenshot of the specified area
pToken:=Gdip_Startup()
TopLeftX:=211 + xOffset
TopLeftY:=38 + yOffset
Width:=1122
Height:=655
pBitmap:=Gdip_BitmapFromScreen(TopLeftX "|" TopLeftY "|" Width "|" Height)
Gdip_SaveBitmapToFile(pBitmap, fileJpg, jpegQual)
Gdip_Shutdown(pToken)
; Wait for jpg file to exist
while NOT FileExist(fileJpg)
Sleep, 10
;ensure the exes are there
if NOT FileExist(convertPath)
MsgBox, No convert.exe found
convertCmd=convert.exe %fileJpg% -negate -threshold 60`% -edge 5 -morphology EdgeOut Disk -fill white -floodfill +20+20 black -floodfill +1100+20 black -floodfill +20+630 black -floodfill +1100+630 black -floodfill +20+425 black -floodfill +20+375 black -floodfill +20+325 black -floodfill +20+275 black -floodfill +20+225 black -floodfill +1100+425 black -floodfill +1100+375 black -floodfill +1100+325 black -floodfill +1100+275 black -floodfill +1100+225 black %filePng%
Runwait, %comspec% /c %convertCmd%,, Hide
; Wait for png file to exist
while NOT FileExist(filePng)
Sleep, 10
convertCmd=convert.exe %filePng% -format `%c histogram:info:- > %fileTxt%
Runwait, %comspec% /c %convertCmd%,, Hide
; Wait for txt file to exist
while NOT FileExist(fileTxt)
Sleep, 10
FileRead, result, %fileTxt%
result:=SubStr(result,1,10)
result:=RegExReplace(result," ")
return result
}
DropGobsGold(gobs) {
global
GoSub, GetWindow
if (gobs = 0) {
SelectTroop(goblin)
SelectTroop(barbarianKing)
SelectTroop(archerQueen)
GoSub, ScrollUp
Click 799, 53
return
}
topLeftX:=211
topLeftY:=38
width:=1333
height:=693
WinGetPos,,,winWidth,winHeight, A
PixelSearch seedX, seedY, topLeftX, topLeftY, 1135, 809, 0x00A4D8, 1, Fast
if (ErrorLevel = 1) {
seedX := winWidth/2
seedY := winHeight/2
}
MouseMove seedX, seedY, 1
Loop, 150 {
topLeftX := Floor(seedX-(A_Index*3))
if (topLeftX < 0)
topLeftX := 0
topLeftY := Floor(seedY-(A_Index*3))
if (topLeftY < 0)
topLeftY := 0
bottomRightX := Floor(seedX+(A_Index*3))
if (bottomRightX > winWidth)
bottomRightX := winWidth
bottomRightY := Floor(seedY+(A_Index*3))
if (bottomRightY > winHeight)
bottomRightY := winHeight
;MouseMove topLeftX, topLeftY, 0
;MouseMove bottomRightX, topLeftY, 0
;MouseMove bottomRightX, bottomRightY, 0
;MouseMove topLeftX, bottomRightY, 0
PixelSearch, dropPointX, dropPointY, topLeftX, topLeftY, bottomRightX, bottomRightY, 0x2E7CCE, 1, Fast
if (ErrorLevel == 0) {
SelectTroop(goblin)
Loop %gobs% {
Click %dropPointX% %dropPointY%
}
SelectTroop(barbarianKing)
Click %dropPointX% %dropPointY%
SelectTroop(archerQueen)
Click %dropPointX% %dropPointY%
return
} else if (ErrorLevel == 2) {
MsgBox, PixelSearch Error
return
}
}
return
}
;drops troop at fastest speed possible in random positions in a circle
TroopSpray:
BlockInput, MouseMove
While GetKeyState("XButton1","P")
{
Random, randRadius, 0, 200
Random, randRadians, 0.0, 6.2832
MouseGetPos, xPos, yPos
randX := Floor( randRadius * Cos(randRadians) ) + xPos
randY := Floor( randRadius * Sin(randRadians) ) + yPos
if (randX < 225)
randX := 225
if (randY < 30)
randY := 30