Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #RequireAdmin
- #include <StaticConstants.au3>
- #include <ButtonConstants.au3>
- #include <ComboConstants.au3>
- #include <GuiComboBox.au3>
- #include <GuiListBox.au3>
- #include <GUIConstantsEx.au3>
- #include <EditConstants.au3>
- #include <WindowsConstants.au3>
- #include <TrayConstants.au3>
- #include <Misc.au3>
- #include "Tesseract-OCR\Tesseract.au3"
- Opt ("GUIOnEventMode", 1)
- Opt ("MouseClickDelay", 10)
- Opt ("MouseClickDownDelay", 10)
- Opt ("MouseCoordMode", 0)
- Opt ('PixelCoordMode', 0)
- GUIRegisterMsg($WM_COMMAND, "GUIControl")
- GUIRegisterMsg($WM_SYSCOMMAND, "GUIControl")
- Global $Title = "BlueStacks App Player"
- Global $HWnD = WinGetHandle (WinGetTitle($Title))
- WinActivate ($HWnD)
- Global $RunState = False
- Global $Gold, $Elixir, $MinGold = 30000, $MinElixir = 30000, $SearchMode = 1, $SearchCheck = 0, $SearchCount = 0
- Global $Attack = 0xF0E5D6, $FindAMatch = 0xF8E0A7
- Global $Config = @ScriptDir & "\config.ini"
- Global $Left = 50.23, $Top = 67.5, $Right = 613.95, $Bottom = 431.67
- Global $BSsize = WinGetClientSize($hWnd)
- Global $x_ratio = $BSsize[0]/800, $y_ratio = $BSsize[1]/600
- Global $Troop[5][2] = [[60*$x_ratio,505*$y_ratio],[130*$x_ratio,505*$y_ratio],[200*$x_ratio,505*$y_ratio],[265*$x_ratio,505*$y_ratio],[372*$x_ratio,505*$y_ratio]]
- Global $Barbarian[2] = [0,0], $Archer[2] = [0,0], $Golbin[2] =[0,0], $Giant[2] = [0,0]
- Global $B1Pos[2] = [0,0], $B2Pos[2] = [0,0], $B3Pos[2] = [0,0], $B4Pos[2] = [0,0]
- Global $B1Troop, $B2Troop, $B3Troop, $B4Troop
- Global $UpLeft[5][2] = [[350*$x_ratio,51*$y_ratio],[230*$x_ratio,100*$y_ratio],[186*$x_ratio,160*$y_ratio],[144*$x_ratio,187*$y_ratio],[125*$x_ratio,200*$y_ratio]]
- Global $UpRight[5][2] = [[460*$x_ratio,62*$y_ratio],[520*$x_ratio,97*$y_ratio],[570*$x_ratio,134*$y_ratio],[647*$x_ratio,186*$y_ratio],[692*$x_ratio,211*$y_ratio]]
- Global $LowLeft[5][2] = [[77*$x_ratio, 306*$y_ratio],[130*$x_ratio,353*$y_ratio],[181*$x_ratio,395*$y_ratio],[214*$x_ratio,415*$y_ratio],[250*$x_ratio,442*$y_ratio]]
- Global $LowRight[5][2] = [[734*$x_ratio,290*$y_ratio],[685*$x_ratio,318*$y_ratio],[630*$x_ratio,350*$y_ratio],[600*$x_ratio,369*$y_ratio],[535*$x_ratio,425*$y_ratio]]
- #Region ##### GUI #####
- $BotGUI = GUICreate("Clash of Clans Bot", 300, 500)
- GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
- GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")
- $Button = GUICtrlCreateButton("START", 20, 450, 260, 40)
- GUICtrlSetOnEvent(-1, "Start")
- $LBButton = GUICtrlCreateButton("Locate Barrack", 20, 380, 85, 30)
- GUICtrlSetOnEvent(-1, "LB")
- $TrButton = GUICtrlCreateButton("Train", 110, 380, 80, 30)
- GUICtrlSetOnEvent(-1, "Tr")
- $AtkButton = GUICtrlCreateButton("Attack", 195, 380, 85, 30)
- GUICtrlSetOnEvent(-1, "Atk")
- $VSButton = GUICtrlCreateButton("VILLAGE SEARCH", 20, 415, 130, 30)
- GUICtrlSetOnEvent(-1, "SearchFunction")
- $DTButton = GUICtrlCreateButton("DROP TROOPS", 150, 415, 130, 30)
- GUICtrlSetOnEvent(-1, "DropFunction")
- $MeetAll = GUICtrlCreateCheckbox("Meet all conditions", 30, 30, 140, 17)
- GUICtrlSetState(-1, $GUI_CHECKED)
- GUICtrlCreateLabel("Min Gold:", 30, 58, 58, 17)
- $MinGoldInput = GUICtrlCreateInput("", 80, 54, 55, 21, $ES_NUMBER)
- GUICtrlSetLimit(-1, 6)
- GUICtrlSetData(-1, $MinGold)
- GUICtrlCreateLabel("Min Elixir:", 30, 82, 57, 17)
- $MinElixirInput = GUICtrlCreateInput("", 80, 78, 55, 21, $ES_NUMBER)
- GUICtrlSetLimit(-1, 6)
- GUICtrlSetData(-1, $MinElixir)
- $Barrack01 = GUICtrlCreateCombo("Barrack 01", 175, 20, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
- GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
- _GUICtrlComboBox_SelectString(-1, "Archer")
- $Barrack02 = GUICtrlCreateCombo("Barrack 02", 175, 46, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
- GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
- _GUICtrlComboBox_SelectString(-1, "Archer")
- $Barrack03 = GUICtrlCreateCombo("Barrack 03", 175, 72, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
- GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
- _GUICtrlComboBox_SelectString(-1, "Barbarian")
- $Barrack04 = GUICtrlCreateCombo("Barrack 04", 175, 98, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
- GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
- _GUICtrlComboBox_SelectString(-1, "Barbarian")
- $Results = GUICtrlCreateList("", 20, 140, 260, 225, BitOR($SS_SUNKEN,$ES_READONLY, $SS_LEFT, $WS_VSCROLL))
- $Timer = GUICtrlCreateEdit("0", 30, 104, 40, 21, BITOR($SS_SUNKEN,$ES_READONLY, $SS_LEFT))
- GUISetState(@SW_SHOW)
- WinSetOnTop($BotGUI,"",1)
- #EndRegion ##### GUI #####
- While 1
- $Msg = GUIGetMsg()
- WEnd
- Func GUIControl($hWind, $iMsg, $wParam, $lParam)
- Local $nNotifyCode = BitShift($wParam, 16)
- Local $nID = BitAND($wParam, 0x0000FFFF)
- Local $hCtrl = $lParam
- #forceref $hWind, $iMsg, $wParam, $lParam
- Switch $iMsg
- Case 273
- Switch $nID
- Case $Button
- $RunState = Not $RunState
- If $RunState = True Then
- GUICtrlSetData($Button,"STOP")
- GUICtrlSetData($Results, "Bot Started.." & @CRLF, -1)
- ElseIf $RunState = False Then
- GUICtrlSetData($Button,"START")
- GUICtrlSetData($Results, "Bot Stopped" & @CRLF, -1)
- EndIf
- Case $LBButton
- GUICtrlSetData($LBButton,"Locating...")
- Case $TrButton
- GUICtrlSetData($TrButton,"Training...")
- Case $AtkButton
- GUICtrlSetData($AtkButton,"Attacking...")
- Case $VSButton
- GUICtrlSetData($VSButton,"Searching...")
- Case $VSButton
- GUICtrlSetData($DTButton,"Dropping Troops...")
- EndSwitch
- Case 274
- Switch $wParam
- Case 0xf060
- Exit
- EndSwitch
- EndSwitch
- Return $GUI_RUNDEFMSG
- EndFunc
- Func Start()
- Sleep(1000)
- While 1
- If $RunState = False Then
- ExitLoop
- EndIf
- MainScreen() ;Check if main screen
- If $RunState = False Then
- ExitLoop
- EndIf
- GetInput() ;Read user's input
- If $RunState = False Then
- ExitLoop
- EndIf
- ZoomOut()
- If $RunState = False Then
- ExitLoop
- EndIf
- LocateBarrack() ;If barrack not located, ask user to manually click on barrack to locate position
- If $RunState = False Then
- ExitLoop
- EndIf
- If $RunState = False Then
- ExitLoop
- EndIf
- Train() ;Locate Barrack, Train Barrack
- If $RunState = False Then
- ExitLoop
- EndIf
- ClearBox()
- ;Idle(900)
- If $RunState = False Then
- ExitLoop
- EndIf
- Attack() ;Prepare Attack, Read Value, Compute Value, Compare Value, Search Village, Drop Troop, Return Home
- WEnd
- EndFunc
- Func GetInput()
- $B1Troop = GUICtrlRead($Barrack01)
- $B2Troop = GUICtrlRead($Barrack02)
- $B3Troop = GUICtrlRead($Barrack03)
- $B4Troop = GUICtrlRead($Barrack04)
- $MinGold = Number(GUICtrlRead($MinGoldInput))
- $MinElixir = Number(GUICtrlRead($MinElixirInput))
- If GUICtrlRead($MeetAll) = $GUI_CHECKED Then
- $SearchMode = 2
- Else
- $SearchMode = 1
- EndIf
- $B1Pos[0] = IniRead($Config, "Barrack 01", "X", "0")
- $B1Pos[1] = IniRead($Config, "Barrack 01", "Y", "0")
- $B2Pos[0] = IniRead($Config, "Barrack 02", "X", "0")
- $B2Pos[1] = IniRead($Config, "Barrack 02", "Y", "0")
- $B3Pos[0] = IniRead($Config, "Barrack 03", "X", "0")
- $B3Pos[1] = IniRead($Config, "Barrack 03", "Y", "0")
- $B4Pos[0] = IniRead($Config, "Barrack 04", "X", "0")
- $B4Pos[1] = IniRead($Config, "Barrack 04", "Y", "0")
- EndFunc
- #Region ##### TRAIN #####
- Func LocateBarrack()
- Local $ClickCheck, $LocateCheck = 0
- While 1
- While 1
- If $RunState = False Then
- ExitLoop(2)
- EndIf
- If $B1Pos[0] = 0 Then
- $ClickCheck = MsgBox(6+262144, "Locate first barrack", "Click Continue then click on your first barrack. Cancel if not available. Try again to start over.", 0, $BotGUI)
- If $ClickCheck = 11 Then
- WinActivate ($HWnD)
- FindPos($B1Pos)
- IniWrite ($Config, "Barrack 01", "X", $B1Pos[0])
- IniWrite ($Config, "Barrack 01", "Y", $B1Pos[1])
- ElseIf $ClickCheck = 10 Then
- $B1Pos[0] = 0
- $B2Pos[0] = 0
- $B3Pos[0] = 0
- $B4Pos[0] = 0
- ExitLoop
- EndIf
- Sleep(500)
- EndIf
- If $RunState = False Then
- ExitLoop(2)
- EndIf
- If $B2Pos[0] = 0 Then
- $ClickCheck = MsgBox(6+262144, "Locate second barrack", "Click Continue then click on you second barrack. Cancel if not available. Try again to start over.", 0, $BotGUI)
- If $ClickCheck = 11 Then
- WinActivate ($HWnD)
- FindPos($B2Pos)
- IniWrite ($Config, "Barrack 02", "X", $B2Pos[0])
- IniWrite ($Config, "Barrack 02", "Y", $B2Pos[1])
- ElseIf $ClickCheck = 10 Then
- $B1Pos[0] = 0
- $B2Pos[0] = 0
- $B3Pos[0] = 0
- $B4Pos[0] = 0
- ExitLoop
- EndIf
- Sleep(500)
- EndIf
- If $RunState = False Then
- ExitLoop(2)
- EndIf
- If $B3Pos[0] = 0 Then
- $ClickCheck = MsgBox(6+262144, "Locate third barrack", "Click Continue then click on your third barrack. Cancel if not available. Try again to start over.", 0, $BotGUI)
- If $ClickCheck = 11 Then
- WinActivate ($HWnD)
- FindPos($B3Pos)
- IniWrite ($Config, "Barrack 03", "X", $B3Pos[0])
- IniWrite ($Config, "Barrack 03", "Y", $B3Pos[1])
- ElseIf $ClickCheck = 10 Then
- $B1Pos[0] = 0
- $B2Pos[0] = 0
- $B3Pos[0] = 0
- $B4Pos[0] = 0
- ExitLoop
- EndIf
- Sleep(500)
- EndIf
- If $RunState = False Then
- ExitLoop(2)
- EndIf
- If $B4Pos[0] = 0 Then
- $ClickCheck = MsgBox(6+262144, "Locate fourth barrack", "Click Continue then click on your fourth barrack. Cancel if not available. Try again to start over.", 0, $BotGUI)
- If $ClickCheck = 11 Then
- WinActivate ($HWnD)
- FindPos($B4Pos)
- IniWrite ($Config, "Barrack 04", "X", $B4Pos[0])
- IniWrite ($Config, "Barrack 04", "Y", $B4Pos[1])
- ElseIf $ClickCheck = 10 Then
- $B1Pos[0] = 0
- $B2Pos[0] = 0
- $B3Pos[0] = 0
- $B4Pos[0] = 0
- ExitLoop
- EndIf
- Sleep(500)
- EndIf
- ExitLoop(2)
- WEnd
- WEnd
- EndFunc
- Func TrainBarrack($x, $y, $z)
- While 1
- If $RunState = False Then
- ExitLoop
- EndIf
- ControlClick ($HWnD, "","", "left", "1", $x, $y)
- Sleep(1000)
- ControlClick ($HWnD, "","", "left", "1", 560*$x_ratio, 490*$y_ratio)
- Sleep(1000)
- Select
- Case $z = "Barbarian"
- For $i = 1 To 65 Step 1
- ControlClick ($HWnD, "","", "left", "1", 220*$x_ratio, 270*$y_ratio)
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(50)
- Next
- Case $z = "Archer"
- For $i = 1 To 65 Step 1
- ControlClick ($HWnD, "","", "left", "1", 310*$x_ratio, 270*$y_ratio)
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(50)
- Next
- Case $z = "Goblin"
- For $i = 1 To 65 Step 1
- ControlClick ($HWnD, "","", "left", "1", 490*$x_ratio, 270*$y_ratio)
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(50)
- Next
- Case $z = "Giant"
- For $i = 1 To 15 Step 1
- ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 270*$y_ratio)
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(50)
- Next
- EndSelect
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(1000)
- ControlClick ($HWnD, "","", "left", "1", 656*$x_ratio, 113*$y_ratio)
- Sleep(1000)
- ExitLoop
- WEnd
- EndFunc
- Func Train()
- If $B1Pos[0]*$B2Pos[0]*$B3Pos[0]*$B4Pos[0] <> 0 Then
- GUICtrlSetData($Results, "Barracks' position loaded successfully" & @CRLF, -1)
- GUICtrlSetData($Results, "Barrack 01: " & $B1Pos[0] & ", " & $B1Pos[1] & @CRLF, -1)
- GUICtrlSetData($Results, "Barrack 02: " & $B2Pos[0] & ", " & $B2Pos[1] & @CRLF, -1)
- GUICtrlSetData($Results, "Barrack 03: " & $B3Pos[0] & ", " & $B3Pos[1] & @CRLF, -1)
- GUICtrlSetData($Results, "Barrack 04: " & $B4Pos[0] & ", " & $B4Pos[1] & @CRLF, -1)
- EndIf
- GUICtrlSetData($Results,"Begin training" & @CRLF, -1)
- If $B1Pos[0] <> 0 Then
- TrainBarrack($B1Pos[0],$B1Pos[1],$B1Troop)
- EndIf
- If $B2Pos[0] <> 0 Then
- TrainBarrack($B2Pos[0],$B2Pos[1],$B2Troop)
- EndIf
- If $B3Pos[0] <> 0 Then
- TrainBarrack($B3Pos[0],$B3Pos[1],$B3Troop)
- EndIf
- If $B4Pos[0] <> 0 Then
- TrainBarrack($B4Pos[0],$B4Pos[1],$B4Troop)
- EndIf
- GUICtrlSetData($Results, "Training complete" & @CRLF, -1)
- EndFunc
- #EndRegion ##### TRAIN #####
- #Region ##### ATTACK #####
- Func Attack()
- While 1
- If $RunState = False Then
- ExitLoop
- EndIf
- AssignTroop()
- If $RunState = False Then
- ExitLoop
- EndIf
- PrepareAttack()
- If $RunState = False Then
- ExitLoop
- EndIf
- GUICtrlSetData($Results, "Attack started. Begin searching.." & @CRLF, -1)
- VillageSearch()
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(5000)
- DropTroop()
- If $RunState = False Then
- ExitLoop
- EndIf
- ReturnHome()
- ExitLoop
- WEnd
- EndFunc
- Func PrepareAttack()
- GUICtrlSetData($Results, "Func PrepareAttack" & @CRLF, -1)
- While 1
- If $RunState = False Then
- ExitLoop
- EndIf
- ControlClick ($HWnD, "","", "left", "1", 50*$x_ratio, 500*$y_ratio) ;Click Attack
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(2000)
- ControlClick ($HWnD, "","", "left", "1", 190*$x_ratio, 420*$y_ratio) ;Click Find a Match
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(2000)
- ControlClick ($HWnD, "","", "left", "1", 470*$x_ratio, 330*$y_ratio) ;Click Break Shield
- ExitLoop
- WEnd
- EndFunc
- Func CheckSearch()
- GUICtrlSetData($Results, "Func CheckSearch" & @CRLF, -1)
- $Pixel = PixelSearch(0,0,900,700,0xC00000,20,1,$HWnD) ;End Battle Button
- While Not IsArray($Pixel)
- $Pixel = PixelSearch(0,0,900,700,0xC00000,20,1,$HWnD) ;End Battle Button
- Sleep(200)
- If $RunState = False Then
- ExitLoop
- EndIf
- WEnd
- EndFunc
- Func VillageSearch()
- GUICtrlSetData($Results, "Func VillageSearch" & @CRLF, -1)
- While 1
- If $RunState = False Then
- ExitLoop
- EndIf
- CheckSearch()
- If $RunState = False Then
- ExitLoop
- EndIf
- ComputeValue()
- If $RunState = False Then
- ExitLoop
- EndIf
- CompareValue()
- If $RunState = False Then
- ExitLoop
- EndIf
- While $SearchCheck = 0
- If $RunState = False Then
- ExitLoop
- EndIf
- ControlClick ($HWnD, "","", "left", "1", 715*$x_ratio, 405*$y_ratio) ;Click Next
- If $RunState = False Then
- ExitLoop
- EndIf
- CheckSearch()
- If $RunState = False Then
- ExitLoop
- EndIf
- ComputeValue()
- If $RunState = False Then
- ExitLoop
- EndIf
- CompareValue()
- If $RunState = False Then
- ExitLoop
- EndIf
- WEnd
- If $RunState = False Then
- ExitLoop
- EndIf
- GUICtrlSetData($Results, "Enemy Found!" & @CRLF, -1)
- TrayTip ("Enemy Found!","Requirement met: Gold: " & $Gold & ". Elixir: " & $Elixir, 0, $TIP_ICONASTERISK)
- ExitLoop
- WEnd
- EndFunc
- Func CheckTroop($a)
- GUICtrlSetData($Results, "Func CheckTroop" & @CRLF, -1)
- If $B1Troop = $a Or $B2Troop = $a Or $B3Troop = $a Or $B4Troop = $a Then
- Return True
- Else
- Return False
- EndIf
- EndFunc
- Func AssignTroop()
- GUICtrlSetData($Results, "Func AssignTroop" & @CRLF, -1)
- If CheckTroop("Barbarian") Then
- $Barbarian[0] = $Troop[0][0]
- $Barbarian[1] = $Troop[0][1]
- If CheckTroop("Archer") Then
- $Archer[0] = $Troop[1][0]
- $Archer[1] = $Troop[1][1]
- If CheckTroop("Goblin") Then
- $Goblin[0] = $Troop[2][0]
- $Goblin[1] = $Troop[2][1]
- If CheckTroop("Giant") Then
- $Giant[0] = $Troop[3][0]
- $Giant[1] = $Troop[3][1]
- ;MsgBox(0,"","Barbarian, Archer, Goblin, Giant")
- EndIf
- ElseIf CheckTroop("Giant") Then
- $Giant[0] = $Troop[2][0]
- $Giant[1] = $Troop[2][1]
- ;MsgBox(0,"","Barbarian, Archer, Giant")
- EndIf
- ElseIf CheckTroop("Goblin") Then
- $Goblin[0] = $Troop[1][0]
- $Goblin[1] = $Troop[1][1]
- If CheckTroop("Giant") Then
- $Giant[0] = $Troop[2][0]
- $Giant[1] = $Troop[2][1]
- ;MsgBox(0,"","Barbarian, Goblin, Giant")
- EndIf
- ElseIf CheckTroop("Giant") Then
- $Giant[0] = $Troop[1][0]
- $Giant[1] = $Troop[1][1]
- ;MsgBox(0,"","Barbarian, Giant")
- EndIf
- ElseIf CheckTroop("Archer") Then
- $Archer[0] = $Troop[0][0]
- $Archer[1] = $Troop[0][1]
- If CheckTroop("Goblin") Then
- $Goblin[0] = $Troop[1][0]
- $Goblin[1] = $Troop[1][1]
- If CheckTroop("Giant") Then
- $Giant[0] = $Troop[2][0]
- $Giant[1] = $Troop[2][1]
- ;MsgBox(0,"","Archer, Goblin, Giant")
- EndIf
- ElseIf CheckTroop("Giant") Then
- $Giant[0] = $Troop[1][0]
- $Giant[1] = $Troop[1][1]
- ;MsgBox(0,"","Archer, Giant")
- EndIf
- ElseIf CheckTroop("Goblin") Then
- $Goblin[0] = $Troop[0][0]
- $Goblin[1] = $Troop[0][1]
- If CheckTroop("Giant") Then
- $Giant[0] = $Troop[1][0]
- $Giant[1] = $Troop[1][1]
- ;MsgBox(0,"","Goblin, Giant")
- EndIf
- ElseIf CheckTroop("Giant") Then
- $Giant[0] = $Troop[0][0]
- $Giant[1] = $Troop[0][1]
- ;MsgBox(0,"","Giant")
- EndIf
- EndFunc
- Func DropTroop()
- GUICtrlSetData($Results, "Func DropTroop" & @CRLF, -1)
- While 1
- GUICtrlSetData($Results, "Start to drop troops" & @CRLF, -1)
- If $RunState = False Then
- ExitLoop
- EndIf
- DropCombo($UpLeft)
- If $RunState = False Then
- ExitLoop
- EndIf
- DropCombo($UpRight)
- If $RunState = False Then
- ExitLoop
- EndIf
- DropCombo($UpLeft)
- If $RunState = False Then
- ExitLoop
- EndIf
- DropCombo($UpRight)
- If $RunState = False Then
- ExitLoop
- EndIf
- ExitLoop
- WEnd
- EndFunc
- Func DropSingle($T, $W)
- GUICtrlSetData($Results, "Func DropSingle" & @CRLF, -1)
- While 1
- If $RunState = False Then
- ExitLoop
- EndIf
- If CheckTroop($T) Then
- Select
- Case $T = "Giant"
- ControlClick ($HWnD, "","", "left", "1", $Giant[0], $Giant[1])
- Sleep(300)
- For $i = 1 to 5 Step 1
- ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
- Sleep(100)
- Next
- Sleep(300)
- If $RunState = False Then
- ExitLoop
- EndIf
- Case $T = "Barbarian"
- ControlClick ($HWnD, "","", "left", "1", $Barbarian[0], $Barbarian[1])
- Sleep(300)
- For $x = 0 to 5 Step 1
- For $i = 0 to 4 Step 1
- ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
- Sleep(100)
- Next
- Next
- Sleep(300)
- If $RunState = False Then
- ExitLoop
- EndIf
- Case $T = "Archer"
- ControlClick ($HWnD, "","", "left", "1", $Archer[0], $Archer[1])
- Sleep(300)
- For $x = 0 to 5 Step 1
- For $i = 0 to 4 Step 1
- ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
- Sleep(100)
- Next
- Next
- Sleep(300)
- If $RunState = False Then
- ExitLoop
- EndIf
- Case $T = "Goblin"
- ControlClick ($HWnD, "","", "left", "1", $Goblin[0], $Goblin[1])
- Sleep(300)
- For $x = 0 to 5 Step 1
- For $i = 0 to 4 Step 1
- ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
- Sleep(100)
- Next
- Next
- Sleep(300)
- EndSelect
- EndIf
- ExitLoop
- WEnd
- EndFunc
- Func DropCombo($W)
- GUICtrlSetData($Results, "Func DropCombo" & @CRLF, -1)
- While 1
- If $RunState = False Then
- ExitLoop
- EndIf
- If CheckTroop("Giant") Then
- ControlClick ($HWnD, "","", "left", "1", $Giant[0], $Giant[1])
- Sleep(500)
- For $i = 1 to 5 Step 1
- ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
- Sleep(500)
- Next
- Sleep(2000)
- EndIf
- If $RunState = False Then
- ExitLoop
- EndIf
- If CheckTroop("Barbarian") Then
- ControlClick ($HWnD, "","", "left", "1", $Barbarian[0], $Barbarian[1])
- Sleep(300)
- For $x = 0 to 7 Step 1
- For $i = 0 to 4 Step 1
- ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
- Sleep(100)
- Next
- Next
- Sleep(500)
- EndIf
- If $RunState = False Then
- ExitLoop
- EndIf
- If CheckTroop("Archer") Then
- ControlClick ($HWnD, "","", "left", "1", $Archer[0], $Archer[1])
- Sleep(300)
- For $x = 0 to 7 Step 1
- For $i = 0 to 4 Step 1
- ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
- Sleep(100)
- Next
- Next
- Sleep(500)
- EndIf
- If $RunState = False Then
- ExitLoop
- EndIf
- If CheckTroop("Goblin") Then
- ControlClick ($HWnD, "","", "left", "1", $Goblin[0], $Goblin[1])
- Sleep(300)
- For $x = 0 to 7 Step 1
- For $i = 0 to 4 Step 1
- ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
- Sleep(100)
- Next
- Next
- Sleep(500)
- EndIf
- ExitLoop
- WEnd
- EndFunc
- Func ReadValue(ByRef $x, ByRef $y)
- GUICtrlSetData($Results, "Func ReadValue" & @CRLF, -1)
- While 1
- If $RunState = False Then
- ExitLoop
- EndIf
- $Read = _TesseractWinCapture($HWnD,"",0,"",1,2,$Left*$x_ratio,$Top*$y_ratio,$Right*$x_ratio,$Bottom*$y_ratio,0) ;Capture screen region with gold and elixir
- $Read = StringRegExpReplace(StringRegExpReplace($Read, "(\v)+", @CRLF), "\A\v|\v\Z", "") ;Strip whitespaces & blank lines and split into array
- $Read = StringSplit($Read, @CRLF, 1)
- ;~ MsgBox(0,"",$Read)
- ;~ FileWrite("Read.png", $Read)
- If $RunState = False Then
- ExitLoop
- EndIf
- While UBound($Read) < 5
- If $RunState = False Then
- ExitLoop
- EndIf
- $Read = _TesseractWinCapture($HWnD,"",0,"",1,2,$Left*$x_ratio,$Top*$y_ratio,$Right*$x_ratio,$Bottom*$y_ratio,0) ;Capture screen region with gold and elixir
- $Read = StringRegExpReplace(StringRegExpReplace($Read, "(\v)+", @CRLF), "\A\v|\v\Z", "") ;Strip whitespaces & blank lines and split into array
- $Read = StringSplit($Read, @CRLF, 1)
- WEnd
- If $RunState = False Then
- ExitLoop
- EndIf
- $x = Number(StringRegExpReplace($Read[2], "[^[:digit:]]", "")) ;Convert gold to number
- $y = Number(StringRegExpReplace($Read[3], "[^[:digit:]]", "")) ;Convert exlir to number
- ExitLoop
- WEnd
- EndFunc
- Func ComputeValue()
- GUICtrlSetData($Results, "Func ComputeValue" & @CRLF, -1)
- While 1
- Local $G[3],$E[3]
- ReadValue($G[0], $E[0])
- ReadValue($G[1], $E[1])
- ReadValue($G[2], $E[2])
- $Gold = _ArrayMin($G)
- $Elixir = _ArrayMin($E)
- If $RunState = False Then
- ExitLoop
- EndIf
- GUICtrlSetData($Results, "(" & $SearchCount+1 & ") Gold: " & $Gold & ". Elixir: " & $Elixir & @CRLF, -1)
- $SearchCount += 1 ; Counter for number of searches
- ExitLoop
- WEnd
- EndFunc
- Func CompareValue()
- GUICtrlSetData($Results, "Func CompareValue" & @CRLF, -1)
- If $Gold >= $MinGold Then
- If $Elixir >= $MinElixir Then
- ;MsgBox(0, "Gold & Elixir Check", "Gold: " & $Gold & @CR & "Elixir: " & $Elixir & @CR & "Requirement met.")
- Select
- Case $SearchMode = 1
- $SearchCheck = 1
- Case $SearchMode = 2
- $SearchCheck = 1
- Case Else
- $SearchCheck = 0
- EndSelect
- Else
- ;MsgBox(0, "Gold & Elixir Check", "Gold: " & $Gold & @CR & "Elixir: " & $Elixir & @CR & "Not enough " & $MinElixir & " Elixir.")
- Select
- Case $SearchMode = 1
- $SearchCheck = 1
- Case $SearchMode = 2
- $SearchCheck = 0
- Case Else
- $SearchCheck = 0
- EndSelect
- EndIf
- Else
- If $Elixir >= $MinElixir Then
- ;MsgBox(0, "Gold & Elixir Check", "Gold: " & $Gold & @CR & "Elixir: " & $Elixir & @CR & "Not enough " & $MinGold & " Gold.")
- Select
- Case $SearchMode = 1
- $SearchCheck = 1
- Case $SearchMode = 2
- $SearchCheck = 0
- Case Else
- $SearchCheck = 0
- EndSelect
- Else
- ;MsgBox(0, "Gold & Elixir Check", "Gold: " & $Gold & @CR & "Elixir: " & $Elixir & @CR & "Not enough " & $MinGold & " Gold and " & $MinElixir & " Elixir." )
- Select
- Case $SearchMode = 1
- $SearchCheck = 0
- Case $SearchMode = 2
- $SearchCheck = 0
- Case Else
- $SearchCheck = 0
- EndSelect
- EndIf
- EndIf
- EndFunc
- #EndRegion ##### ATTACK #####
- #Region ##### MINI FUNCTION #####
- #cs
- Func MainScreen()
- While 1
- If $RunState = False Then
- ExitLoop
- EndIf
- GUICtrlSetData($Results, "Waiting for Clash of Clans to load..." & @CRLF, -1)
- $Pixel = PixelGetColor(630*$x_ratio, 390*$y_ratio, $HWnD)
- If Hex($Pixel,6) = 282828 Or $Pixel = 2962704 Then
- ControlClick ($HWnD, "","", "left", "1", 293*$x_ratio, 329*$y_ratio)
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(5000)
- EndIf
- $Pixel = PixelSearch(0,0,900,700,0xF8ED90,0,1,$HWnD)
- If IsArray($Pixel) Then
- ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 450*$y_ratio)
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(5000)
- EndIf
- $Pixel = PixelSearch(0,0,900,700,$Attack,0,1,$HWnD)
- While Not IsArray($Pixel)
- $Pixel = PixelSearch(0,0,900,700,$Attack,0,1,$HWnD)
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(200)
- WEnd
- GUICtrlSetData($Results, "In main screen" & @CRLF, -1)
- ExitLoop
- WEnd
- EndFunc
- #ce
- Func CheckScreenChange()
- GUICtrlSetData($Results, "Func CheckScreenChange" & @CRLF, -1)
- $Pixel = PixelChecksum(0.25*$BSsize[0],0.25*$BSsize[1], 0.75*$BSsize[0], 0.75*$BSsize[1], 2, $hWnD)
- Sleep(500)
- $Pixel1 = PixelChecksum(0.25*$BSsize[0],0.25*$BSsize[1], 0.75*$BSsize[0], 0.75*$BSsize[1], 2, $hWnD)
- If $Pixel = $Pixel1 Then
- Return False
- Else
- Return True
- EndIf
- EndFunc
- Func MainScreen()
- GUICtrlSetData($Results, "Func Mainscreen" & @CRLF, -1)
- If Not CheckScreenChange() Then
- ControlClick ($HWnD, "","", "left", "1", 293*$x_ratio, 329*$y_ratio)
- ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 408*$y_ratio)
- GUICtrlSetData($Results, "Waiting for Clash of Clans to load..." & @CRLF, -1)
- Sleep(5000)
- EndIf
- While Not CheckScreenChange()
- Sleep(1000)
- WEnd
- GUICtrlSetData($Results, "In main screen" & @CRLF, -1)
- EndFunc
- Func Idle($s)
- GUICtrlSetData($Results, "Func Idle" & @CRLF, -1)
- For $i = 1 to $s/60 Step 1
- If $RunState = False Then
- ExitLoop
- EndIf
- Train()
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(45000)
- Next
- EndFunc
- ;~ Func ReturnHome()
- ;~ GUICtrlSetData($Results, "Func ReturnHome" & @CRLF, -1)
- ;~ #cs
- ;~ While CheckScreenChange(0.25, 0.9, 0.75, 0.95)
- ;~ Sleep(1000)
- ;~ WEnd
- ;~ GUICtrlSetData($Results, "Return Home" & @CRLF, -1)
- ;~ ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 450*$y_ratio)
- ;~ #ce
- ;~ $tStart = TimerInit()
- ;~ $tStop = TimerDiff($tStart)
- ;~ While $tStop < 160
- ;~ If $RunState = False Then
- ;~ ExitLoop
- ;~ EndIf
- ;~ Sleep(1000)
- ;~ WEnd
- ;~ GUICtrlSetData($Results, "Return Home" & @CRLF, -1)
- ;~ ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 450*$y_ratio)
- ;~ EndFunc
- Func ReturnHome()
- GUICtrlSetData($Results, "Func ReturnHome" & @CRLF, -1)
- #cs
- While CheckScreenChange(0.25, 0.9, 0.75, 0.95)
- Sleep(1000)
- WEnd
- GUICtrlSetData($Results, "Return Home" & @CRLF, -1)
- ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 450*$y_ratio)
- #ce
- $Countdown = 150
- While $Countdown > 0
- GUICtrlSetData($Timer, $Countdown)
- $Countdown = $Countdown - 1
- sleep(1000)
- WEnd
- GUICtrlSetData($Results, "Return Home" & @CRLF, -1)
- ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 450*$y_ratio)
- EndFunc
- Func ZoomOut()
- GUICtrlSetData($Results, "Zoom Out" & @CRLF, -1)
- For $i = 1 To 20 Step 1
- ControlSend($HWnD, "", "", "{DOWN}", 0)
- If $RunState = False Then
- ExitLoop
- EndIf
- Sleep(500)
- Next
- EndFunc
- Func Button($hex)
- $Count = 0
- $Pixel = PixelSearch(0,0,900,700,$hex,0,1,$HWnD) ;Attack! button
- While Not IsArray($Pixel) And $Count < 5
- $Pixel = PixelSearch(0,0,900,700,$hex,0,1,$HWnD) ;Attack! button
- Sleep(200)
- $Count += 1
- WEnd
- If $Count < 5 Then
- ControlClick ($HWnD, "","", "left", "1", $Pixel[0], $Pixel[1])
- EndIf
- Sleep(1000)
- EndFunc
- Func Terminate()
- Exit
- EndFunc
- Func FindPos(ByRef $Pos)
- Opt ("MouseCoordMode", 2)
- Local $x = 1
- While $x = 1
- If _IsPressed("01") Then
- $Pos = MouseGetPos()
- $x = 0
- EndIf
- WEnd
- Opt ("MouseCoordMode", 0)
- EndFunc
- Func ClearBox()
- GUICtrlDelete($Results)
- $Results = GUICtrlCreateList("", 20, 140, 260, 225, BitOR($SS_SUNKEN,$ES_READONLY, $SS_LEFT, $WS_VSCROLL))
- EndFunc
- Func LB()
- ClearBox()
- $RunState = True
- GUICtrlSetData($Button,"STOP")
- MainScreen()
- ZoomOut()
- $B1Pos[0] = 0
- $B2Pos[0] = 0
- $B3Pos[0] = 0
- $B4Pos[0] = 0
- LocateBarrack()
- GUICtrlSetData($LBButton,"Locate Barracks")
- GUICtrlSetData($Results, "Barracks located" & @CRLF, -1)
- GUICtrlSetData($Results, "Barrack 01: " & $B1Pos[0] & ", " & $B1Pos[1] & @CRLF, -1)
- GUICtrlSetData($Results, "Barrack 02: " & $B2Pos[0] & ", " & $B2Pos[1] & @CRLF, -1)
- GUICtrlSetData($Results, "Barrack 03: " & $B3Pos[0] & ", " & $B3Pos[1] & @CRLF, -1)
- GUICtrlSetData($Results, "Barrack 04: " & $B4Pos[0] & ", " & $B4Pos[1] & @CRLF, -1)
- $RunState = False
- GUICtrlSetData($Button,"START")
- EndFunc
- Func Tr()
- ClearBox()
- $RunState = True
- GUICtrlSetData($Button,"STOP")
- MainScreen()
- GetInput()
- ZoomOut()
- Train()
- $RunState = False
- GUICtrlSetData($TrButton, "Train")
- GUICtrlSetData($Button,"STOP")
- EndFunc
- Func Atk()
- ClearBox()
- $RunState = True
- GUICtrlSetData($Button,"STOP")
- MainScreen()
- GetInput()
- ZoomOut()
- Attack()
- GUICtrlSetData($AtkButton, "Attack")
- $RunState = False
- GUICtrlSetData($Button,"START")
- EndFunc
- Func SearchFunction()
- ClearBox()
- $RunState = True
- GUICtrlSetData($Button,"STOP")
- GetInput()
- ControlClick ($HWnD, "","", "left", "1", 715*$x_ratio, 405*$y_ratio) ;Click Next
- VillageSearch()
- GUICtrlSetData($VSButton, "VILLAGE SEARCH")
- $RunState = False
- GUICtrlSetData($Button,"START")
- EndFunc
- Func DropFunction()
- ClearBox()
- $RunState = True
- GUICtrlSetData($Button,"STOP")
- GetInput()
- DropTroop()
- GUICtrlSetData($VSButton, "DROP TROOPS")
- $RunState = False
- GUICtrlSetData($Button,"START")
- EndFunc
- #cs
- Func Pause()
- $Paused = NOT $Paused
- While $Paused
- Sleep(100)
- TrayTip("Script Paused","SHIFT+1 to Unpause", 0, $TIP_ICONASTERISK)
- WEnd
- EndFunc
- Func Restart()
- ControlClick ($HWnD, "","", "left", "1", 125, 575)
- Sleep(2000)
- ControlClick ($HWnD, "","", "left", "1", 125, 577)
- Sleep(2000)
- ControlClick ($HWnD, "","", "left", "1", 205, 575)
- Sleep(2000)
- MouseClickDrag("left", 700, 300, 700, 120)
- Sleep(2000)
- ControlClick ($HWnD, "","", "left", "1", 290, 160)
- Sleep(50000)
- EndFunc
- Func Initiate()
- ControlClick ($HWnD, "","", "left", "1", 290, 150) ;Click BlueStacks
- Sleep(60000)
- ZoomOut()
- Sleep(10000)
- EndFunc
- #ce
- #EndRegion ##### MINI FUNCTION ######
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement