This repository has been archived by the owner on Feb 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
MyBot.run.au3
463 lines (431 loc) · 16.2 KB
/
MyBot.run.au3
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
; #FUNCTION# ====================================================================================================================
; Name ..........: MBR Bot
; Description ...: This file contens the Sequence that runs all MBR Bot
; Author ........: (2014)
; Modified ......:
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015
; MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
#RequireAdmin
#AutoIt3Wrapper_UseX64=n
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#pragma compile(Icon, "Icons\MyBot.ico")
#pragma compile(FileDescription, Clash of Clans Bot - A Free Clash of Clans bot - https://mybot.run)
#pragma compile(ProductName, My Bot)
#pragma compile(ProductVersion, 4.2)
#pragma compile(FileVersion, 4.2)
#pragma compile(LegalCopyright, © https://mybot.run)
$sBotVersion = "v4.2-1"
$sBotTitle = "My Bot " & $sBotVersion
Global $sBotDll = @ScriptDir & "\MBRPlugin.dll"
If _Singleton($sBotTitle, 1) = 0 Then
MsgBox(0, "", "Bot is already running.")
Exit
EndIf
If @AutoItX64 = 1 Then
MsgBox(0, "", "Don't Run/Compile the Script as (x64)! try to Run/Compile the Script as (x86) to get the bot to work." & @CRLF & _
"If this message still appears, try to re-install AutoIt.")
Exit
EndIf
If Not FileExists(@ScriptDir & "\License.txt") Then
$license = InetGet("http://www.gnu.org/licenses/gpl-3.0.txt", @ScriptDir & "\License.txt")
InetClose($license)
EndIf
#include "COCBot\MBR Global Variables.au3"
#include "COCBot\MBR GUI Design.au3"
#include "COCBot\MBR GUI Control.au3"
#include "COCBot\MBR Functions.au3"
CheckPrerequisites() ; check for VC2010 and .NET software
DirCreate($sTemplates)
DirCreate($sProfilePath & "\" & $sCurrProfile)
DirCreate($dirLogs)
DirCreate($dirLoots)
DirCreate($dirTemp)
FileMove(@ScriptDir & "\*.ini", $sProfilePath & "\" & $sCurrProfile, $FC_OVERWRITE + $FC_CREATEPATH)
DirCopy(@ScriptDir & "\Logs", $sProfilePath & "\" & $sCurrProfile & "\Logs", $FC_OVERWRITE + $FC_CREATEPATH)
DirCopy(@ScriptDir & "\Loots", $sProfilePath & "\" & $sCurrProfile & "\Loots", $FC_OVERWRITE + $FC_CREATEPATH)
DirCopy(@ScriptDir & "\Temp", $sProfilePath & "\" & $sCurrProfile & "\Temp", $FC_OVERWRITE + $FC_CREATEPATH)
DirRemove(@ScriptDir & "\Logs", 1)
DirRemove(@ScriptDir & "\Loots", 1)
DirRemove(@ScriptDir & "\Temp", 1)
If $ichkDeleteLogs = 1 Then DeleteFiles($dirLogs, "*.*", $iDeleteLogsDays, 0)
If $ichkDeleteLoots = 1 Then DeleteFiles($dirLoots, "*.*", $iDeleteLootsDays, 0)
If $ichkDeleteTemp = 1 Then DeleteFiles($dirTemp, "*.*", $iDeleteTempDays, 0)
FileChangeDir($LibDir)
;MBRfunctions.dll debugger
debugMBRFunctions($debugSearchArea, $debugRedArea, $debugOcr) ; set debug levels
AdlibRegister("PushBulletRemoteControl", $PBRemoteControlInterval)
AdlibRegister("PushBulletDeleteOldPushes", $PBDeleteOldPushesInterval)
;CheckVersion() ; check latest version on mybot.run site
;AutoStart Bot if request
AutoStart()
While 1
Switch TrayGetMsg()
Case $tiAbout
MsgBox(64 + $MB_APPLMODAL + $MB_TOPMOST, $sBotTitle, "Clash of Clans Bot" & @CRLF & @CRLF & _
"Version: " & $sBotVersion & @CRLF & _
"Released under the GNU GPLv3 license.", 0, $frmBot)
Case $tiExit
ExitLoop
EndSwitch
WEnd
Func runBot() ;Bot that runs everything in order
$TotalTrainedTroops = 0
;$ChatbotStartTime = TimerInit()
$ClanAdStartTime = TimerInit()
While 1
SWHTrainRevertNormal()
$Restart = False
$fullArmy = False
$CommandStop = -1
If _Sleep($iDelayRunBot1) Then Return
checkMainScreen()
If $Restart = True Then ContinueLoop
If $Is_ClientSyncError = False Then
If BotCommand() Then btnStop()
If _Sleep($iDelayRunBot2) Then Return
checkMainScreen(False)
If $Restart = True Then ContinueLoop
If $RequestScreenshot = 1 Then PushMsg("RequestScreenshot")
If _Sleep($iDelayRunBot3) Then Return
VillageReport()
ProfileSwitch()
If $OutOfGold = 1 And ($GoldCount >= $itxtRestartGold) Then ; check if enough gold to begin searching again
$OutOfGold = 0 ; reset out of gold flag
Setlog("Switching back to normal after no gold to search ...", $COLOR_RED)
$ichkBotStop = 0 ; reset halt attack variable
ContinueLoop ; Restart bot loop to reset $CommandStop
EndIf
If $OutOfElixir = 1 And ($ElixirCount >= $itxtRestartElixir) And ($DarkCount >= $itxtRestartDark) Then ; check if enough elixir to begin searching again
$OutOfElixir = 0 ; reset out of gold flag
Setlog("Switching back to normal setting after no elixir to train ...", $COLOR_RED)
$ichkBotStop = 0 ; reset halt attack variable
ContinueLoop ; Restart bot loop to reset $CommandStop
EndIf
If _Sleep($iDelayRunBot5) Then Return
checkMainScreen(False)
If $Restart = True Then ContinueLoop
CheckTombs()
If _Sleep($iDelayRunBot3) Then Return
If $Restart = True Then ContinueLoop
ReArm()
If _Sleep($iDelayRunBot3) Then Return
If $Restart = True Then ContinueLoop
ReplayShare($iShareAttackNow)
If _Sleep($iDelayRunBot3) Then Return
If $Restart = True Then ContinueLoop
ReportPushBullet()
If _Sleep($iDelayRunBot3) Then Return
If $Restart = True Then ContinueLoop
DonateCC()
If _Sleep($iDelayRunBot1) Then Return
checkMainScreen(False) ; required here due to many possible exits
If $Restart = True Then ContinueLoop
$iArmyPercent = 0
If $ichkUsePercent = 1 Then
checkArmyCamp()
PercentComp()
EndIf
Train()
If _Sleep($iDelayRunBot1) Then Return
checkMainScreen(False)
If $Restart = True Then ContinueLoop
Collect()
If $Restart = True Then ContinueLoop
BoostBarracks()
If $Restart = True Then ContinueLoop
BoostSpellFactory()
If $Restart = True Then ContinueLoop
BoostHeros()
If $Restart = True Then ContinueLoop
RequestCC()
If _Sleep($iDelayRunBot1) Then Return
checkMainScreen(False) ; required here due to many possible exits
If $Restart = True Then ContinueLoop
If $iUnbreakableMode >= 1 Then
If Unbreakable() = True Then ContinueLoop
EndIf
Laboratory()
If _Sleep($iDelayRunBot3) Then Return
checkMainScreen(False) ; required here due to many possible exits
If $Restart = True Then ContinueLoop
If $FreeBuilder > $iSaveWallBldr Then
UpgradeHeroes()
If _Sleep($iDelayRunBot3) Then Return
checkMainScreen(False) ; required here due to many possible exits
If $Restart = True Then ContinueLoop
UpgradeBuilding()
If _Sleep($iDelayRunBot3) Then Return
checkMainScreen(False) ; required here due to many possible exits
If $Restart = True Then ContinueLoop
EndIf
UpgradeWall()
If _Sleep($iDelayRunBot3) Then Return
If $Restart = True Then ContinueLoop
ClearObstacles()
If _Sleep($iDelayRunBot3) Then Return
If $Restart = True Then ContinueLoop
RequestCC()
If _Sleep($iDelayRunBot3) Then Return
;checkMainScreen(False) ; required here due to many possible exits
If $Restart = True Then ContinueLoop
Idle()
If _Sleep($iDelayRunBot3) Then Return
If $Restart = True Then ContinueLoop
If $CommandStop <> 0 And $CommandStop <> 3 Then
AttackMain()
If $OutOfGold = 1 Then
Setlog("Switching to Halt Attack, Stay Online/Collect mode ...", $COLOR_RED)
$ichkBotStop = 1 ; set halt attack variable
$icmbBotCond = 16 ; set stay online/collect only mode
$FirstStart = True ; reset First time flag to ensure army balancing when returns to training
ContinueLoop
EndIf
If _Sleep($iDelayRunBot1) Then Return
If $Restart = True Then ContinueLoop
EndIf
;
Else ;When error occours directly goes to attack
SetLog("Restarted after Out of Sync Error: Attack Now", $COLOR_RED)
PushMsg("OutOfSync")
checkMainScreen(False)
If $Restart = True Then ContinueLoop
AttackMain()
If $OutOfGold = 1 Then
Setlog("Switching to Halt Attack, Stay Online/Collect mode ...", $COLOR_RED)
$ichkBotStop = 1 ; set halt attack variable
$icmbBotCond = 16 ; set stay online/collect only mode
$FirstStart = True ; reset First time flag to ensure army balancing when returns to training
$Is_ClientSyncError = False ; reset fast restart flag to stop OOS mode and start collecting resources
ContinueLoop
EndIf
If _Sleep($iDelayRunBot5) Then Return
If $Restart = True Then ContinueLoop
EndIf
WEnd
EndFunc ;==>runBot
Func Idle() ;Sequence that runs until Full Army
Local $TimeIdle = 0 ;In Seconds
Local $trainTimerAdjust=-1, $timeInTrain=0, $TimeIdleinMinutes=0 ;In minutes
If $debugSetlog = 1 Then SetLog("Func Idle ", $COLOR_PURPLE)
While $fullArmy = False
If $RequestScreenshot = 1 Then PushMsg("RequestScreenshot")
If _Sleep($iDelayIdle1) Then Return
If $CommandStop = -1 Then SetLog("====== Waiting for full army ======", $COLOR_GREEN)
Local $hTimer = TimerInit()
Local $iReHere = 0
While $iReHere < 7
$iReHere += 1
DonateCC(True)
If _Sleep($iDelayIdle2) Then ExitLoop
If $Restart = True Then ExitLoop
WEnd
If _Sleep($iDelayIdle1) Then ExitLoop
checkMainScreen(False) ; required here due to many possible exits
If ($CommandStop = 3 Or $CommandStop = 0) Then
CheckOverviewFullArmy(True)
If Not ($fullArmy) And $bTrainEnabled = True Then
SetLog("Army Camp and Barracks are not full, Training Continues...", $COLOR_ORANGE)
$CommandStop = 0
EndIf
EndIf
ReplayShare($iShareAttackNow)
If _Sleep($iDelayIdle1) Then Return
If $Restart = True Then ExitLoop
If $iCollectCounter > $COLLECTATCOUNT Then ; This is prevent from collecting all the time which isn't needed anyway
Collect()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Or $RunState = False Then ExitLoop
$iCollectCounter = 0
EndIf
$iCollectCounter = $iCollectCounter + 1
If $CommandStop <> 0 Or $CommandStop <> 3 Then
If _GUICtrlComboBox_GetCurSel($cmbTroopComp) = 8 Then
If (($CurCamp >= ($TotalCamp * 20 / 100)) And ($iArmyPercent < 20)) Then
SetLog("====== Army more than 20% ======", $COLOR_GREEN)
Train()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
checkMainScreen(False)
RequestCC()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
;checkMainScreen(False)
$iArmyPercent = 20
ElseIf (($CurCamp >= ($TotalCamp * 40 / 100)) And ($iArmyPercent < 40)) Then
SetLog("====== Army more than 40% ======", $COLOR_GREEN)
Train()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
checkMainScreen(False)
RequestCC()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
;checkMainScreen(False)
$iArmyPercent = 40
ElseIf (($CurCamp >= ($TotalCamp * 60 / 100)) And ($iArmyPercent < 60)) Then
SetLog("====== Army more than 60% ======", $COLOR_GREEN)
Train()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
checkMainScreen(False)
RequestCC()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
;checkMainScreen(False)
$iArmyPercent = 60
ElseIf (($CurCamp >= ($TotalCamp * 80 / 100)) And ($iArmyPercent < 80)) Then
SetLog("====== Army more than 80% ======", $COLOR_GREEN)
Train()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
checkMainScreen(False)
RequestCC()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
;checkMainScreen(False)
$iArmyPercent = 80
Else
checkArmyCamp()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
checkMainScreen(False)
EndIf
Else
Train()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
checkMainScreen(False)
EndIf
EndIf
If _Sleep($iDelayIdle1) Then Return
If $CommandStop = 0 And $bTrainEnabled = True Then
If Not ($fullArmy) Then
Train()
If $Restart = True Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
checkMainScreen(False)
If $fullArmy Then
SetLog("Army Camp and Barracks are full, stop Training...", $COLOR_ORANGE)
$CommandStop = 3
EndIf
EndIf
EndIf
If _Sleep($iDelayIdle1) Then Return
If $CommandStop = -1 Then
DropTrophy()
If $Restart = True Then ExitLoop
If $fullArmy Then ExitLoop
If _Sleep($iDelayIdle1) Then ExitLoop
checkMainScreen(False)
EndIf
If _Sleep($iDelayIdle1) Then Return
If $Restart = True Then ExitLoop
If $ichkIceBreaker = 1 Then IceBreaker()
If $ichkKeepAlive = 1 Then KeepAlive()
If $ichkClanAd = 1 Then
If TimerDiff($ClanAdStartTime) = 15*1000 Then
WriteClan($itxtClanAd)
$ClanAdStartTime = TimerInit()
EndIf
EndIf
RequestCC()
SnipeWhileTrain()
$TimeIdle += Round(TimerDiff($hTimer) / 1000, 2) ;In Seconds
; use getMinInTrain() if Idle is too long without troops in training
$timeInTrain = getMaxInTrain()
$TimeIdleinMinutes = Floor($TimeIdle/60)
If $trainTimerAdjust = -1 Then $trainTimerAdjust = $TimeIdleinMinutes + $timeInTrain
If $debugSetlog = 1 Then SetLog("$trainTimerAdjust: " & $trainTimerAdjust & " $timeInTrain: " & $timeInTrain & " $TimeIdleinMinutes: " & $TimeIdleinMinutes)
If $debugSetlog = 1 Then SetLog("$CurCamp: " & $CurCamp & " $CurCampOld: " & $CurCampOld)
If $CurCamp = $CurCampOld Then ; if no new troop is produced or being trained
If $TimeIdleinMinutes-$trainTimerAdjust > 0 Then ;the adjusted idle time exceeds minimum time to wait for unit to be produced
If $iSpeed = 0 Then
If $notTraining < $numBarracksAvaiables Then ; training stuck, also $timeInTrain = -1
$RemoveTroops=True
ResetCounters()
$trainFiller = True
Else
$trainFiller = True
EndIf
If $notTrainingDark < $numDarkBarracksAvaiables Then ; training stuck, also $timeInTrain = -1
$RemoveDarkTroops=True
ResetCounters()
$trainFillerDark = True
Else
$trainFillerDark = True
EndIf
ElseIf $iSpeed = 1 Then
If $notTraining = 0 Then
$RemoveTroops=True
ResetCounters()
$trainFiller = True
Else
$trainFiller = True
EndIf
If $notTrainingDark = 0 Then
$RemoveDarkTroops=True
ResetCounters()
$trainFillerDark = True
Else
$trainFillerDark = True
EndIf
EndIf
If $debugSetlog = 1 Then SetLog("time $ArchComp: " & $ArchComp & " $eBallComp" & $BallComp & " $eMiniComp: " & $MiniComp)
EndIf
Else
$trainTimerAdjust = $TimeIdleinMinutes + $timeInTrain ;units are being produced, increment time to adjust idle time
EndIf
;If all barracks are idle and army not yet full
If $TotalCamp<>$CurCamp And $notTraining + $notTrainingDark = $numBarracksAvaiables + $numDarkBarracksAvaiables Then ResetCounters()
SetLog("Time Idle: " & StringFormat("%02i", Floor(Floor($TimeIdle / 60) / 60)) & ":" & StringFormat("%02i", Floor(Mod(Floor($TimeIdle / 60), 60))) & ":" & StringFormat("%02i", Floor(Mod($TimeIdle, 60))))
If $OutOfGold = 1 Then Return
WEnd
If $iSpeed = 0 Then
$RemoveTroops=True
$RemoveDarkTroops=True
EndIf
ResetCounters()
If $debugSetlog = 1 Then SetLog("attack $ArchComp: " & $ArchComp & " $eBallComp" & $BallComp & " $eMiniComp: " & $MiniComp)
EndFunc ;==>Idle
Func AttackMain() ;Main control for attack functions
;launch profilereport() only if option balance D/R it's activated
If $iChkUseCCBalanced = 1 Then
ProfileReport()
If _Sleep($iDelayAttackMain1) Then Return
checkMainScreen(False)
If $Restart = True Then Return
EndIf
PrepareSearch()
If $OutOfGold = 1 Then Return ; Check flag for enough gold to search
If $Restart = True Then Return
VillageSearch()
If $OutOfGold = 1 Then Return ; Check flag for enough gold to search
If $Restart = True Then Return
;;; ToolBox ;;;;;;;;;
If $ToolboxModeBot Then
_GUI_Toolbox_Show()
EndIf
PrepareAttack($iMatchMode)
If $Restart = True Then Return
;checkDarkElix()
;DEAttack()
;;; ToolBox ;;;;;;;;;
If $ToolboxModeBot Then
_GUI_Toolbox_Activate()
EndIf
If $Restart = True Then Return
Attack()
If $Restart = True Then Return
ReturnHome($TakeLootSnapShot)
If _Sleep($iDelayAttackMain2) Then Return
Return True
EndFunc ;==>AttackMain
Func Attack() ;Selects which algorithm
SetLog(" ====== Start Attack ====== ", $COLOR_GREEN)
algorithm_AllTroops()
EndFunc ;==>Attack