GkevinOD

COC Bot Pre-Alpha v005 (Not Finished)

Dec 29th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 63.75 KB | None | 0 0
  1. #include <ButtonConstants.au3>
  2. #include <ComboConstants.au3>
  3. #include <EditConstants.au3>
  4. #include <GUIConstantsEx.au3>
  5. #include <GuiStatusBar.au3>
  6. #Include <GUIEdit.au3>
  7. #Include <GUIComboBox.au3>
  8. #include <StaticConstants.au3>
  9. #include <TabConstants.au3>
  10. #include <WindowsConstants.au3>
  11. #include <ScreenCapture.au3>
  12. #include <Date.au3>
  13. #include <Misc.au3>
  14.  
  15. #RequireAdmin
  16.  
  17. #Region ### START Koda GUI section ###
  18. $frmBot = GUICreate("COC Bot Pre-Alpha v005", 417, 392, 207, 158)
  19. $tabMain = GUICtrlCreateTab(8, 8, 401, 355)
  20. $pageGeneral = GUICtrlCreateTabItem("General")
  21. $txtLog = GUICtrlCreateEdit("", 16, 40, 385, 240, BitOR($ES_AUTOVSCROLL,$ES_NOHIDESEL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
  22. GUICtrlSetBkColor(-1, 0xFFFFFF)
  23. $Controls = GUICtrlCreateGroup("Controls", 16, 290, 185, 65)
  24. $btnStart = GUICtrlCreateButton("Start", 30, 314, 75, 25)
  25. $btnStop = GUICtrlCreateButton("Stop", 110, 314, 75, 25)
  26. GUICtrlSetState(-1, $GUI_DISABLE)
  27. GUICtrlCreateGroup("", -99, -99, 1, 1)
  28. $otherSettings = GUICtrlCreateGroup("Other Settings", 208, 290, 185, 65)
  29. $lblMaxTrophy = GUICtrlCreateLabel("Max Trophy :", 230, 320, 66, 17)
  30. $txtMaxTrophy = GUICtrlCreateInput("3000", 298, 318, 71, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
  31. GUICtrlSetState(-1, $GUI_DISABLE)
  32. GUICtrlSetTip(-1, "Bot will lose tropies if your trophy is greater than this.")
  33. GUICtrlCreateGroup("", -99, -99, 1, 1)
  34. $pageSearchSetting = GUICtrlCreateTabItem("Search Settings")
  35. $btnSearchMode = GUICtrlCreateButton("Search Mode", 24, 327, 368, 25)
  36. GUICtrlSetTip(-1, "Does not attack. Searches for base that meets conditions.")
  37. $Conditions = GUICtrlCreateGroup("Conditions", 16, 40, 193, 185)
  38. $chkMeetDE = GUICtrlCreateCheckbox("Meet Dark Elixir", 40, 88, 97, 17)
  39. $chkMeetTrophy = GUICtrlCreateCheckbox("Meet Trophy Count", 40, 112, 113, 17)
  40. $chkMeetGxE = GUICtrlCreateCheckbox("Meet Gold and Elixir", 40, 64, 113, 17)
  41. GUICtrlSetState(-1, $GUI_CHECKED)
  42. $lblConditions = GUICtrlCreateLabel("Check the boxes that you want to meet. The bot will stop at a base when it meets the conditions. If all unchecked, bot will stop if gold or elixir that is met.", 26, 143, 172, 72, $SS_CENTER)
  43. GUICtrlCreateGroup("", -99, -99, 1, 1)
  44. $Resources = GUICtrlCreateGroup("Resources", 208, 40, 193, 185)
  45. $lblMinGold = GUICtrlCreateLabel("Minimum Gold: ", 216, 64, 76, 17)
  46. $lblMinElixir = GUICtrlCreateLabel("Minimum Elixir:", 216, 88, 72, 17)
  47. $lblMinDarkElixir = GUICtrlCreateLabel("Minimum Dark Elixir:", 216, 112, 98, 17)
  48. $lblMinTrophy = GUICtrlCreateLabel("Minimum Trophy Count:", 216, 136, 115, 17)
  49. $txtMinGold = GUICtrlCreateInput("80000", 330, 62, 61, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
  50. $txtMinElixir = GUICtrlCreateInput("80000", 330, 86, 61, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
  51. $txtMinDarkElixir = GUICtrlCreateInput("0", 330, 110, 61, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
  52. $txtMinTrophy = GUICtrlCreateInput("0", 330, 134, 61, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
  53. GUICtrlSetLimit(-1, 2)
  54. $lblResources = GUICtrlCreateLabel("Bot will stop when a base is found with resources higher or equal to the minimum resources.", 220, 164, 168, 51, $SS_CENTER)
  55. GUICtrlCreateGroup("", -99, -99, 1, 1)
  56. $OtherSearchSettings = GUICtrlCreateGroup("Other Seach Settings", 15, 225, 385, 95)
  57. $chkAlertSearch = GUICtrlCreateCheckbox("Alert when Base Found", 30, 250, 132, 17)
  58. GUICtrlSetState(-1, $GUI_DISABLE)
  59. GUICtrlCreateGroup("", -99, -99, 1, 1)
  60. $pageAttackSettings = GUICtrlCreateTabItem("Attack Settings")
  61. $WeakBaseSettings = GUICtrlCreateGroup("Weak Base Settings", 15, 35, 130, 230)
  62. $lblMortar = GUICtrlCreateLabel("Max Mortar Lvl:", 20, 58, 77, 17)
  63. $cmbMortar = GUICtrlCreateCombo("", 100, 55, 35, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  64. GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8", "5")
  65. GUICtrlSetState(-1, $GUI_DISABLE)
  66. $lblWizardTower = GUICtrlCreateLabel("Wiz Tower Lvl:", 20, 83, 75, 17)
  67. $cmbWizTower = GUICtrlCreateCombo("", 100, 80, 35, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  68. GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8", "4")
  69. GUICtrlSetState(-1, $GUI_DISABLE)
  70. $lblCannon = GUICtrlCreateLabel("Cannon Lvl:", 20, 108, 61, 17)
  71. $lblArcher = GUICtrlCreateLabel("Archer Lvl:", 20, 133, 55, 17)
  72. $chkWithKing = GUICtrlCreateCheckbox("Attack their King", 20, 180, 112, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_RIGHTBUTTON))
  73. GUICtrlSetState(-1, $GUI_CHECKED)
  74. GUICtrlSetState(-1, $GUI_DISABLE)
  75. $chkWithQueen = GUICtrlCreateCheckbox("Attack their Queen", 20, 200, 112, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_RIGHTBUTTON))
  76. GUICtrlSetState(-1, $GUI_DISABLE)
  77. $cmbCannon = GUICtrlCreateCombo("", 100, 105, 35, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  78. GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13", "8")
  79. GUICtrlSetState(-1, $GUI_DISABLE)
  80. $cmbArcher = GUICtrlCreateCombo("", 100, 130, 35, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  81. GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13", "8")
  82. GUICtrlSetState(-1, $GUI_DISABLE)
  83. $lblWeakDescription = GUICtrlCreateLabel("Bot will attack bases that meet requirement.", 17, 225, 125, 32, $SS_CENTER)
  84. $lblxBow = GUICtrlCreateLabel("X-Bow Lvl:", 20, 158, 55, 17)
  85. $cmbxBow = GUICtrlCreateCombo("", 100, 155, 35, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  86. GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13", "0")
  87. GUICtrlSetState(-1, $GUI_DISABLE)
  88. GUICtrlCreateGroup("", -99, -99, 1, 1)
  89. $AttackMode = GUICtrlCreateGroup("Attack Mode", 150, 35, 250, 115)
  90. $radDeadBases = GUICtrlCreateRadio("Dead Bases - Meets condition, full collectors", 155, 55, 238, 17)
  91. $radWeakBases = GUICtrlCreateRadio("Weak Bases - Meets condition and able 50%", 155, 85, 228, 17)
  92. GUICtrlSetState(-1, $GUI_DISABLE)
  93. $radAllBases = GUICtrlCreateRadio("All Bases - Attack all that meets search.", 155, 115, 228, 17)
  94. GUICtrlSetState(-1, $GUI_CHECKED)
  95. GUICtrlCreateGroup("", -99, -99, 1, 1)
  96. $HeroesSettings = GUICtrlCreateGroup("Royals Settings", 150, 155, 250, 110)
  97. $chkKingAttackDead = GUICtrlCreateCheckbox("Atk Dead Bases", 165, 195, 97, 17)
  98. GUICtrlSetState(-1, $GUI_DISABLE)
  99. $chkKingAttackWeakBases = GUICtrlCreateCheckbox("Atk Weak Bases", 165, 215, 97, 17)
  100. GUICtrlSetState(-1, $GUI_DISABLE)
  101. $chkKingAttackAllBases = GUICtrlCreateCheckbox("Atk All Bases", 165, 235, 97, 17)
  102. GUICtrlSetState(-1, $GUI_DISABLE)
  103. $lblKingSettings = GUICtrlCreateLabel("King Settings:", 165, 175, 69, 17)
  104. $lblQueenSettings = GUICtrlCreateLabel("Queen Settings:", 285, 175, 80, 17)
  105. $chkQueenAttackDeadBases = GUICtrlCreateCheckbox("Atk Dead Bases", 285, 195, 97, 17)
  106. GUICtrlSetState(-1, $GUI_DISABLE)
  107. $chkQueenAttackWeakBases = GUICtrlCreateCheckbox("Atk Weak Bases", 285, 215, 97, 17)
  108. GUICtrlSetState(-1, $GUI_DISABLE)
  109. $chkQueenAttackAllBases = GUICtrlCreateCheckbox("Atk All Bases", 285, 235, 97, 17)
  110. GUICtrlSetState(-1, $GUI_DISABLE)
  111. GUICtrlCreateGroup("", -99, -99, 1, 1)
  112. $DeploySettings = GUICtrlCreateGroup("Deploy Settings", 15, 270, 385, 85)
  113. $chkAttackTH = GUICtrlCreateCheckbox("Attack Townhall (Outside)", 250, 320, 142, 17)
  114. GUICtrlSetState(-1, $GUI_DISABLE)
  115. $cmbDeploy = GUICtrlCreateCombo("", 30, 290, 360, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  116. GUICtrlSetData(-1, "Attack on two sides, penetrates through base|Attack on three sides, gets outer and some inside of base|Attack on all sides equally, gets most of outer base", "Attack on all sides equally, gets most of outer base")
  117. $cmbAlgorithm = GUICtrlCreateCombo("", 30, 320, 215, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  118. GUICtrlSetData(-1, "Barbarians + Archers|Use all troops", "Barbarians + Archers") ;"Archers|Barbarians|Goblins|Barbarians + Archers|Barb + Arch + Goblin + Giant|Barb + Arch + Giant|Barb + Arch + Goblin|Barb + Arch + Goblin + Giant + Wallbreakers|Use Barracks"
  119. GUICtrlCreateGroup("", -99, -99, 1, 1)
  120. $pageDonateSettings = GUICtrlCreateTabItem("Donate Settings")
  121. $Donation = GUICtrlCreateGroup("", 15, 30, 385, 325)
  122. $Barbarians = GUICtrlCreateGroup("Barbarians", 20, 70, 120, 235)
  123. $Checkbox1 = GUICtrlCreateCheckbox("Donate to All", 30, 95, 97, 17)
  124. GUICtrlSetState(-1, $GUI_DISABLE)
  125. $txtDonateBarbarians = GUICtrlCreateEdit("", 25, 120, 110, 179, BitOR($ES_WANTRETURN,$WS_VSCROLL))
  126. GUICtrlSetData(-1, StringFormat("barbarians\r\nbarb\r\nany"))
  127. GUICtrlSetState(-1, $GUI_DISABLE)
  128. GUICtrlSetTip(-1, "Keywords for donating Barbarians")
  129. GUICtrlCreateGroup("", -99, -99, 1, 1)
  130. $Archers = GUICtrlCreateGroup("Archers", 148, 70, 120, 235)
  131. $Checkbox2 = GUICtrlCreateCheckbox("Donate to All", 155, 95, 97, 17)
  132. GUICtrlSetState(-1, $GUI_DISABLE)
  133. $txtDonateArchers = GUICtrlCreateEdit("", 153, 120, 110, 179, BitOR($ES_WANTRETURN,$WS_VSCROLL))
  134. GUICtrlSetData(-1, StringFormat("archers\r\narch\r\nany"))
  135. GUICtrlSetState(-1, $GUI_DISABLE)
  136. GUICtrlSetTip(-1, "Keywords for donating Archers")
  137. GUICtrlCreateGroup("", -99, -99, 1, 1)
  138. $Giants = GUICtrlCreateGroup("Giants", 275, 70, 120, 235)
  139. $Checkbox3 = GUICtrlCreateCheckbox("Donate to All", 285, 95, 97, 17)
  140. GUICtrlSetState(-1, $GUI_DISABLE)
  141. $txtDonateGiants = GUICtrlCreateEdit("", 280, 120, 110, 179, BitOR($ES_WANTRETURN,$WS_VSCROLL))
  142. GUICtrlSetData(-1, StringFormat("giants\r\ngiant\r\nany"))
  143. GUICtrlSetState(-1, $GUI_DISABLE)
  144. GUICtrlSetTip(-1, "Keywords for donating Giants")
  145. GUICtrlCreateGroup("", -99, -99, 1, 1)
  146. $chkDonateGiants = GUICtrlCreateCheckbox("Donate Giants", 275, 305, 97, 17)
  147. GUICtrlSetState(-1, $GUI_DISABLE)
  148. $chkDonateArchers = GUICtrlCreateCheckbox("Donate Archers", 149, 305, 97, 17)
  149. GUICtrlSetState(-1, $GUI_DISABLE)
  150. $chkDonateBarbarians = GUICtrlCreateCheckbox("Donate Barbarians", 20, 305, 112, 17)
  151. GUICtrlSetState(-1, $GUI_DISABLE)
  152. $chkRequest = GUICtrlCreateCheckbox("Request for :", 30, 45, 82, 17)
  153. GUICtrlSetState(-1, $GUI_DISABLE)
  154. $txtRequest = GUICtrlCreateInput("any", 115, 45, 276, 21)
  155. GUICtrlSetState(-1, $GUI_DISABLE)
  156. GUICtrlSetTip(-1, "Request for input.")
  157. $btnLocateClanCastle = GUICtrlCreateButton("Locate Clan Castle Manually", 25, 325, 365, 25)
  158. GUICtrlSetState(-1, $GUI_DISABLE)
  159. GUICtrlCreateGroup("", -99, -99, 1, 1)
  160. $pageTroopSettings = GUICtrlCreateTabItem("Troop Settings")
  161. $Barracks = GUICtrlCreateGroup("Troops", 20, 40, 185, 215)
  162. $lblBarbarians = GUICtrlCreateLabel("Barbarians :", 30, 68, 60, 17)
  163. $lblArchers = GUICtrlCreateLabel("Archers :", 30, 93, 46, 17)
  164. $lblGoblins = GUICtrlCreateLabel("Goblins :", 30, 118, 45, 17)
  165. $txtBarbarians = GUICtrlCreateInput("30", 115, 65, 56, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
  166. GUICtrlSetState(-1, $GUI_DISABLE)
  167. $txtArchers = GUICtrlCreateInput("60", 115, 90, 56, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
  168. GUICtrlSetState(-1, $GUI_DISABLE)
  169. $txtGoblins = GUICtrlCreateInput("10", 115, 115, 56, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
  170. GUICtrlSetState(-1, $GUI_DISABLE)
  171. $lblPercentBarbarians = GUICtrlCreateLabel("%", 175, 68, 12, 17)
  172. $lblPercentArchers = GUICtrlCreateLabel("%", 175, 93, 12, 17)
  173. $lblPercentGoblins = GUICtrlCreateLabel("%", 175, 118, 12, 17)
  174. $lblBarracks = GUICtrlCreateLabel("Must equal 100% to fully distribute the troops with maximum amount efficiency. Bot will use this if custom troops is selected", 40, 175, 140, 67, $SS_CENTER)
  175. $cmbTroopComp = GUICtrlCreateCombo("", 45, 145, 131, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  176. GUICtrlSetData(-1, "B.Arch|Use Barracks", "Use Barracks") ;"Archers|Barbarians|Goblins|B.Arch|B.A.G.G.|B.A.Giant|B.A.Goblin|B.A.G.G.Wall|Use Barracks|Custom Troops"
  177. GUICtrlCreateGroup("", -99, -99, 1, 1)
  178. $OtherTroops = GUICtrlCreateGroup("Other Troops", 210, 40, 185, 85)
  179. $lblGiants = GUICtrlCreateLabel("Number of Giants:", 215, 68, 89, 17)
  180. $lblWallBreakers = GUICtrlCreateLabel("Number of Wall Breakers:", 215, 93, 125, 17)
  181. $txtNumGiants = GUICtrlCreateInput("4", 340, 65, 46, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
  182. GUICtrlSetState(-1, $GUI_DISABLE)
  183. $txtNumWallbreakers = GUICtrlCreateInput("4", 340, 90, 46, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
  184. GUICtrlSetState(-1, $GUI_DISABLE)
  185. GUICtrlCreateGroup("", -99, -99, 1, 1)
  186. $BarrackGroup = GUICtrlCreateGroup("Barracks", 210, 130, 185, 125)
  187. $lblBarrack1 = GUICtrlCreateLabel("Barrack 1:", 220, 153, 53, 17)
  188. $lblBarrack2 = GUICtrlCreateLabel("Barrack 2:", 220, 178, 53, 17)
  189. $lblBarrack3 = GUICtrlCreateLabel("Barrack 3:", 220, 203, 53, 17)
  190. $lblBarrack4 = GUICtrlCreateLabel("Barrack 4:", 220, 228, 53, 17)
  191. $cmbBarrack1 = GUICtrlCreateCombo("", 275, 150, 110, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  192. GUICtrlSetData(-1, "Barbarians|Archers", "Barbarians") ; "Barbarians|Archers|Giants|Goblins"
  193. $cmbBarrack2 = GUICtrlCreateCombo("", 275, 175, 110, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  194. GUICtrlSetData(-1, "Barbarians|Archers", "Barbarians") ; "Barbarians|Archers|Giants|Goblins"
  195. $cmbBarrack3 = GUICtrlCreateCombo("", 275, 200, 110, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  196. GUICtrlSetData(-1, "Barbarians|Archers", "Archers") ; "Barbarians|Archers|Giants|Goblins"
  197. $cmbBarrack4 = GUICtrlCreateCombo("", 275, 225, 110, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
  198. GUICtrlSetData(-1, "Barbarians|Archers", "Archers") ; "Barbarians|Archers|Giants|Goblins"
  199. GUICtrlCreateGroup("", -99, -99, 1, 1)
  200. $OtherBarrackSettings = GUICtrlCreateGroup("Other Settings", 20, 255, 375, 100)
  201. $btnLocateBarracks = GUICtrlCreateButton("Locate Barracks Manually", 30, 320, 355, 25)
  202. GUICtrlCreateGroup("", -99, -99, 1, 1)
  203. GUICtrlCreateTabItem("")
  204. $statLog = _GUICtrlStatusBar_Create($frmBot)
  205. _GUICtrlStatusBar_SetSimple($statLog)
  206. _GUICtrlStatusBar_SetText($statLog, "Status : Idle")
  207. GUISetState(@SW_SHOW)
  208. #EndRegion ### END Koda GUI section ###
  209. ;---------------------------------------------------
  210. #Region #####Global Variables#####
  211.    Global $version = "Pre-Alpha v005"
  212.    Global $config = @ScriptDir & "\config.ini"
  213.    Global $Restart = False
  214.    Global $RunState = False
  215.  
  216.    Global $cmbTroopComp ;For Event change on ComboBox Troop Compositions
  217.    ;---------------------------------------------------------------------------------------------------
  218.    Global $BSpos[2] ; Inside BlueStacks positions relative to the screen
  219.    Global $CtrlHandle ; BlueStacks control handle
  220.    ;---------------------------------------------------------------------------------------------------
  221. ;Search Settings
  222.    Global $searchGold, $searchElixir, $searchDark, $searchTrophy ;Resources of bases when searching
  223.    Global $MinGold, $MinElixir, $MinDark, $MinTrophy ; Minimum Resources conditions
  224.    Global $chkConditions[3] ;Conditions (meet gold...)
  225.  
  226.    Global $SearchCount = 0 ;Number of searches
  227. ;Attack Settings
  228.    Global $atkTroops[7][2] ;7 Slots of troops -  Name,Amount
  229.    Global $icmbAlgorithm ;Algorithm to use when attacking
  230.  
  231.    Global $fullArmy ;Check for full army or not
  232.    Global $deploySettings ;Method of deploy found in attack settings
  233.  
  234.    Global $iradAttackMode ;Attack mode, 0 1 2
  235. ;Donate Settings
  236.  
  237. ;Troop Settings
  238.    Global $icmbTroopComp ;Troop Composition
  239.  
  240.    Global $barrackPos[4][2] ;Positions of each barracks
  241.    Global $barrackTroop[4] ;Barrack troop set
  242.  
  243.    ;Apply the configs------------------------------
  244.    If FileExists($config) Then
  245.       readConfig()
  246.       applyConfig()
  247.    EndIf
  248. #EndRegion #####End Global Variables#####
  249. ;---------------------------------------------------
  250. #Region ### Button Section ###
  251.    While 1
  252.       $nMsg = GUIGetMsg()
  253.       Switch $nMsg
  254.       Case $GUI_EVENT_CLOSE
  255.          SaveConfig()
  256.          Exit
  257.       Case $btnStart ;Starts the bot--------------------------------------------------
  258.          SaveConfig()
  259.          ReadConfig()
  260.          ApplyConfig()
  261.          _GUICtrlEdit_SetText($txtLog, "")
  262.          If WinExists("BlueStacks App Player") Then
  263.             If IsArray(ControlGetPos("BlueStacks App Player", "_ctl.Window", "[CLASS:BlueStacksApp; INSTANCE:1]")) Then
  264.                Local $BSsize = [ControlGetPos("BlueStacks App Player", "_ctl.Window", "[CLASS:BlueStacksApp; INSTANCE:1]")[2], ControlGetPos("BlueStacks App Player", "_ctl.Window", "[CLASS:BlueStacksApp; INSTANCE:1]")[3]]
  265.                If $BSsize[0] <> 860 Or $BSsize[1] <> 720 Then
  266.                   SetLog("BlueStacks is not set to 860x720!")
  267.                   SetLog("Download the '860x720.reg' file and run it, restart BlueStacks")
  268.                   SetLog("Download the '860x720.reg' here: http://ge.tt/6Twq4O72")
  269.                Else
  270.                   SetLog("~~~~Welcome to COC Bot " & $version & "!~~~~")
  271.                   SetLog("Bot is starting...")
  272.  
  273.                   GUICtrlSetState($btnStart, $GUI_DISABLE)
  274.                   GUICtrlSetState($btnLocateBarracks, $GUI_DISABLE)
  275.                   GUICtrlSetState($btnSearchMode, $GUI_DISABLE)
  276.                   GUICtrlSetState($cmbTroopComp, $GUI_DISABLE)
  277.                   GUICtrlSetState($btnStop, $GUI_ENABLE)
  278.  
  279.                   If _Sleep(2000) Then ExitLoop
  280.                   $RunState = True
  281.                   runBot()
  282.                EndIf
  283.             Else
  284.                SetLog("Not in Game!")
  285.             EndIf
  286.          Else
  287.             SetLog("BlueStacks was not found!")
  288.          EndIf
  289.       Case $btnLocateBarracks
  290.          ZoomOut()
  291.          LocateBarrack()
  292.       Case $btnSearchMode
  293.          GUICtrlSetState($btnStart, $GUI_DISABLE)
  294.          GUICtrlSetState($btnLocateBarracks, $GUI_DISABLE)
  295.          GUICtrlSetState($btnSearchMode, $GUI_DISABLE)
  296.          GUICtrlSetState($cmbTroopComp, $GUI_DISABLE)
  297.          GUICtrlSetState($btnStop, $GUI_ENABLE)
  298.  
  299.          $RunState = True
  300.          VillageSearch()
  301.          $RunState = False
  302.  
  303.          GUICtrlSetState($btnStart, $GUI_ENABLE)
  304.          GUICtrlSetState($btnLocateBarracks, $GUI_ENABLE)
  305.          GUICtrlSetState($btnSearchMode, $GUI_ENABLE)
  306.          GUICtrlSetState($cmbTroopComp, $GUI_ENABLE)
  307.          GUICtrlSetState($btnStop, $GUI_DISABLE)
  308.       EndSwitch
  309.  
  310.       If _GUICtrlComboBox_GetCurSel($cmbTroopComp) <> $icmbTroopComp Then
  311.          $icmbTroopComp = _GUICtrlComboBox_GetCurSel($cmbTroopComp)
  312.          SetComboTroopComp()
  313.       EndIf
  314.    WEnd
  315.  
  316.    Func SetComboTroopComp()
  317.       Switch _GUICtrlComboBox_GetCurSel($cmbTroopComp)
  318.       Case 0
  319.          GUICtrlSetState($cmbBarrack1, $GUI_DISABLE)
  320.          GUICtrlSetState($cmbBarrack2, $GUI_DISABLE)
  321.          GUICtrlSetState($cmbBarrack3, $GUI_DISABLE)
  322.          GUICtrlSetState($cmbBarrack4, $GUI_DISABLE)
  323.  
  324.          GUICtrlSetData($txtBarbarians, "50")
  325.          GUICtrlSetData($txtArchers, "50")
  326.          GUICtrlSetData($txtGoblins, "0")
  327.  
  328.          GUICtrlSetData($txtNumGiants, "0")
  329.          GUICtrlSetData($txtNumWallbreakers, "0")
  330.       Case 1
  331.          GUICtrlSetState($cmbBarrack1, $GUI_ENABLE)
  332.          GUICtrlSetState($cmbBarrack2, $GUI_ENABLE)
  333.          GUICtrlSetState($cmbBarrack3, $GUI_ENABLE)
  334.          GUICtrlSetState($cmbBarrack4, $GUI_ENABLE)
  335.       EndSwitch
  336.    EndFunc
  337. #EndRegion ### End Button Section
  338. ;---------------------------------------------------
  339. #Region ### General Functions ###
  340.    Func runBot() ;Bot that runs everything in order
  341.       While 1
  342.          $Restart = False
  343.          checkMainScreen()
  344.          If _Sleep(1000) Or $RunState = False Then ExitLoop
  345.          ZoomOut()
  346.          If _Sleep(1000) Or $RunState = False Then ExitLoop
  347.          Train()
  348.          If _Sleep(1000) Or $RunState = False Then ExitLoop
  349.          Idle()
  350.          If _Sleep(1000) Or $RunState = False Then ExitLoop
  351.          AttackMain()
  352.          If _Sleep(1000) Or $RunState = False Then ExitLoop
  353.       WEnd
  354.    EndFunc
  355.  
  356.    Func Idle() ;Sequence that runs until Full Army
  357.       While 1
  358.          If $fullArmy = False Then
  359.             SetLog("~~~Waiting for full army~~~")
  360.             While $fullArmy = False
  361.                checkMainScreen()
  362.                If _Sleep(1000) Or $RunState = False Then ExitLoop(2)
  363.                ZoomOut()
  364.                If _Sleep(1000) Or $RunState = False Then ExitLoop(2)
  365. ;~             Collect()                                            ;Collect too buggy to be used
  366. ;~             If _Sleep(1000) Or $RunState = False Then ExitLoop(2)
  367.                Train()
  368.                If _Sleep(30000) Or $RunState = False Then ExitLoop(2)
  369.             WEnd
  370.          EndIf
  371.          ExitLoop
  372.       WEnd
  373.    EndFunc
  374.  
  375.    Func checkMainScreen() ;Checks if in main screen
  376.       getBSPos()
  377.       If _ColorCheckVariation(Hex(PixelGetColor($BSpos[0] + 284, $BSpos[1] + 28), 6), Hex(0x41B1CD, 6)) = False Then
  378.          While 1
  379.             SetLog("Not in main screen, Restarting BlueStacks...")
  380.  
  381.             ProcessClose("HD-Frontend.exe")
  382.             If _Sleep(1000) Or $RunState = False Then ExitLoop
  383.  
  384.             Local $ProgramFileDir
  385.             Switch @OSArch
  386.                Case "X86"
  387.                   $ProgramFileDir = "Program Files"
  388.                Case "X64"
  389.                   $ProgramFileDir = "Program Files (x86)"
  390.             EndSwitch
  391.  
  392.             If FileExists(@HomeDrive & "\" & $ProgramFileDir & "\BlueStacks\HD-RunApp.exe") Then
  393.                Run(@HomeDrive & "\" & $ProgramFileDir & "\BlueStacks\HD-RunApp.exe -p com.supercell.clashofclans -a com.supercell.clashofclans.GameApp")
  394.             Else
  395.                SetLog("Could not automatically load Clash Of Clans")
  396.                SetLog("Try and open Clash Of Clans Manually")
  397.             EndIf
  398.  
  399.             If _Sleep(2000) or $RunState = False Then ExitLoop
  400.             SetLog("Waiting for Clash Of Clans to Load")
  401.  
  402.             Local $counter = 0
  403.  
  404.             While 1
  405.                If _Sleep(2000) or $RunState = False Then ExitLoop(2)
  406.                If WinExists("BlueStacks App Player") Then
  407.                   getBSPos()
  408.                   If _ColorCheckVariation(Hex(PixelGetColor($BSpos[0] + 284, $BSpos[1] + 28), 6), Hex(0x41B1CD, 6)) Then
  409.                      Exitloop(2)
  410.                   EndIf
  411.                EndIf
  412.                $counter += 1
  413.  
  414.                If $counter >= 50 Then
  415.                   SetLog("Could not automatically load Clash Of Clans")
  416.                   checkMainScreen()
  417.                   ExitLoop(2)
  418.                EndIf
  419.             WEnd
  420.          WEnd
  421.       EndIf
  422.    EndFunc
  423.  
  424.    Func checkNextButton() ;Checks for Out of Sync or Connection Lost errors
  425.       getBSpos()
  426.       Local $Color1 = PixelGetColor($BSpos[0] + 737, $BSpos[1] + 491) ;0xEEA828
  427.       Local $Color2 = PixelGetColor($BSpos[0] + 740, $BSpos[1] + 514) ;0xD84C00
  428.  
  429.       If _ColorCheckVariation(Hex($Color1, 6), Hex(0xEEA828, 6), 10) And _ColorCheckVariation(Hex($Color2, 6), Hex(0xD84C00, 6), 10) Then
  430.          Return True
  431.       Else
  432.          Return False
  433.       EndIf
  434.    EndFunc
  435.  
  436.    Func ZoomOut() ;Zooms out
  437.       SetLog("Zooming Out")
  438.       Local $i = 0
  439.       While 1
  440.          getBSPos()
  441.          If _Sleep(500) Then ExitLoop
  442.          If PixelGetColor($BSpos[0]+1, $BSpos[1]+1) = 0x000000 And PixelGetColor($BSpos[0]+850, $BSpos[1]+1) = 0x000000 Then
  443.             SetLog("Zoom Out Complete")
  444.             ExitLoop
  445.          Else
  446.             ControlSend("BlueStacks App Player", "", "", "{DOWN}", 0)
  447.             $i += 1
  448.             If $i = 20 Then
  449.                SetLog("Zoom Out Complete")
  450.                ExitLoop
  451.             EndIf
  452.          EndIf
  453.       WEnd
  454.    EndFunc
  455. #EndRegion ### End General Functions ###
  456. ;---------------------------------------------------
  457. #Region ### Attack Functions ###
  458.    Func AttackMain() ;Main control for attack functions
  459.       While 1
  460.          PrepareSearch()
  461.          If _Sleep(1000) Or $RunState = False Then ExitLoop
  462.          VillageSearch()
  463.          If _Sleep(1000) Or $RunState = False Or $Restart Then ExitLoop
  464.          PrepareAttack()
  465.          If _Sleep(1000) Or $RunState = False Then ExitLoop
  466.          Attack()
  467.          If _Sleep(1000) Or $RunState = False Then ExitLoop
  468.          ;ReturnMainScreen()
  469.          ExitLoop
  470.       WEnd
  471.    EndFunc
  472.  
  473.    Func Attack()
  474.       While 1
  475.          SetLog("======Beginning Attack======")
  476.          If _Sleep(500) Or $RunState = False Then ExitLoop
  477.          Switch $icmbAlgorithm
  478.          Case 0 ;Barbarians + Archers
  479.             SetLog("~Using 'Barbarians + Archers' algorithm to attack")
  480.             If _Sleep(500) Or $RunState = False Then ExitLoop
  481.             Switch $deploySettings
  482.             Case 0 ;Two sides
  483.                SetLog("~Attacking in two sides...")
  484.                If _Sleep(500) Or $RunState = False Then ExitLoop
  485.  
  486.             Case 1 ;Three sides
  487.                SetLog("~Attacking in three sides...")
  488.                If _Sleep(500) Or $RunState = False Then ExitLoop
  489.  
  490.             Case 2 ;Four sides
  491.                SetLog("~Attacking in all sides...")
  492.                If _Sleep(500) Or $RunState = False Then ExitLoop
  493.  
  494.             EndSwitch
  495.          Case 1 ;Use All Troops
  496.  
  497.          EndSwitch
  498.          ExitLoop
  499.       WEnd
  500.    EndFunc
  501.  
  502.    Func PrepareAttack()
  503.       While 1
  504.          SetLog("Preparing to attack")
  505.          For $i = 0 to 6
  506.             $Troop = PixelGetColor($BSpos[0] + 68 + (72 * $i) , $BSpos[1] + 595)
  507.             If _ColorCheckVariation(Hex($Troop, 6), Hex(0xF8B020, 6), 10) Then ;Check if slot is Barbarian
  508.                $atkTroops[$i][0] = "Barbarian"
  509.                $atkTroops[$i][1] = Number(getNormal($BSpos[0] + 40 + (72 * $i), $BSpos[1] + 565))
  510.             ElseIf _ColorCheckVariation(Hex($Troop, 6), Hex(0xD83F68, 6), 10) Then ;Check if slot is Archer
  511.                $atkTroops[$i][0] = "Archer"
  512.                $atkTroops[$i][1] = Number(getNormal($BSpos[0] + 40 + (72 * $i), $BSpos[1] + 565))
  513.             ElseIf _ColorCheckVariation(Hex($Troop, 6), Hex(0x7BC950, 6), 10) Then ;Check if slot is Goblin
  514.                $atkTroops[$i][0] = "Goblin"
  515.                $atkTroops[$i][1] = Number(getNormal($BSpos[0] + 40 + (72 * $i), $BSpos[1] + 565))
  516.             ElseIf _ColorCheckVariation(Hex($Troop, 6), Hex(0xF8D49E, 6), 10) Then ;Check if slot is Giant
  517.                $atkTroops[$i][0] = "Giant"
  518.                $atkTroops[$i][1] = Number(getNormal($BSpos[0] + 40 + (72 * $i), $BSpos[1] + 565))
  519.             ElseIf _ColorCheckVariation(Hex($Troop, 6), Hex(0x60A4D0, 6), 10) Then ;Check if slot is Wallbreaker
  520.                $atkTroops[$i][0] = "Wallbreaker"
  521.                $atkTroops[$i][1] = Number(getNormal($BSpos[0] + 40 + (72 * $i), $BSpos[1] + 565))
  522.             ElseIf _ColorCheckVariation(Hex($Troop, 6), Hex(0xF8EB79, 6), 10) Then ;Check if slot is King
  523.                $atkTroops[$i][0] = "King"
  524.                $atkTroops[$i][1] = 1
  525.             ElseIf _ColorCheckVariation(Hex($Troop, 6), Hex(0x000000, 6), 10) Then ;Check if slot is Queen (Need Pixel)
  526.                $atkTroops[$i][0] = "Queen"
  527.                $atkTroops[$i][1] = 1
  528.             EndIf
  529.             If $atkTroops[$i][0] <> "" Then SetLog("-" & $atkTroops[$i][0] & " " & $atkTroops[$i][1])
  530.          Next
  531.          ExitLoop
  532.       WEnd
  533.    EndFunc
  534.  
  535.    Func VillageSearch() ;Control for searching a village that meets conditions
  536.       While 1
  537.          SetLog("===============Searching For Base===============")
  538.          $SearchCount = 0
  539.          While 1
  540.             If _Sleep(1000) Or $RunState = False Then ExitLoop(2)
  541.  
  542.             GetResources() ;Reads Resource Values
  543.  
  544.             If $Restart = True Then ExitLoop(2)
  545.  
  546.             If CompareResources() Then
  547.                If $iradAttackMode = 0 Then
  548.                   If CheckDeadBase() Then
  549.                      SetLog("~~~~~~~Dead Base Found!")
  550.                      ExitLoop
  551.                   Else
  552.                      SetLog("~~~~~~~Not dead base, skipping")
  553.                      Click(750, 500) ;Click Next
  554.                   EndIf
  555.                Else
  556.                   ExitLoop
  557.                EndIf
  558.             Else
  559.                Click(750, 500) ;Click Next
  560.             EndIf
  561.          WEnd
  562.  
  563.          SetLog("===============Searching Complete===============")
  564.          ExitLoop
  565.       WEnd
  566.    EndFunc
  567.  
  568.    Func GetResources() ;Reads resources
  569.       While 1
  570.          Local $i = 0
  571.          While getGold($BSpos[0] + 51, $BSpos[1] + 66) = "" ; Loops until gold is readable
  572.             getBSPos()
  573.             If _Sleep(500) Or $RunState = False Then ExitLoop(2)
  574.             $i += 1
  575.             If $i >= 20 Then ; If gold cannot be read by 10 seconds
  576.                If checkNextButton() Then ;Checks for Out of Sync or Connection Error during search
  577.                   Click(750, 500) ;Click Next
  578.                Else
  579.                   SetLog("Cannot locate Next button, Restarting Bot")
  580.                   checkMainScreen()
  581.                   $Restart = True
  582.                   ExitLoop(2)
  583.                EndIf
  584.                $i = 0
  585.             EndIf
  586.          WEnd
  587.  
  588.          $searchGold = getGold($BSpos[0] + 51, $BSpos[1] + 66)
  589.          $searchElixir = getElixir($BSpos[0] + 51, $BSpos[1] + 66 + 29)
  590.          $searchTrophy = getTrophy($BSpos[0] + 51, $BSpos[1] + 66 + 90)
  591.  
  592.          If $searchTrophy <> "" Then
  593.             $searchDark = getDarkElixir($BSpos[0] + 51, $BSpos[01] + 66 + 57)
  594.          Else
  595.             $searchDark = 0
  596.             $searchTrophy = getTrophy($BSpos[0] + 51, $BSpos[1] + 66 + 60)
  597.          EndIf
  598.  
  599.          SetLog("(" & $SearchCount+1 & ") [G]: " & $searchGold & Tab($searchGold,12) & "[E]: " & $searchElixir & Tab($searchElixir,12) & "[D]: " & $searchDark & Tab($searchDark,12) & "[T]: " & $searchTrophy)
  600.          $SearchCount += 1 ; Counter for number of searches
  601.          ExitLoop
  602.       WEnd
  603.    EndFunc
  604.  
  605.    Func CompareResources() ;Compares resources and returns true if conditions meet, otherwise returns false
  606.       Local $G = (Number($searchGold) >= Number($MinGold)), $E = (Number($searchElixir) >= Number($MinElixir)), $D = (Number($searchDark) >= Number($MinDark)), $T = (Number($searchTrophy) >= Number($MinTrophy))
  607.       Local $Boolean = False
  608.  
  609.       If $G Or $E Then $Boolean = True
  610.  
  611.       If $chkConditions[0] = 1 Then
  612.          If $G = False Or $E = False Then $Boolean = False
  613.          Return $Boolean
  614.       EndIf
  615.  
  616.       If $chkConditions[1] = 1 Then
  617.          If $D = False Then $Boolean = False
  618.          Return $Boolean
  619.       EndIf
  620.  
  621.       If $chkConditions[2] = 1 Then
  622.          If $T = False Then $Boolean = False
  623.          Return $Boolean
  624.       EndIf
  625.  
  626.       Return $Boolean
  627.    EndFunc
  628.  
  629.    Func PrepareSearch() ;Click attack button and find match button, will break shield
  630.       SetLog("Preparing to search")
  631.       While 1
  632.          Click(60, 614);Click Attack Button
  633.          If _Sleep(1000) Or $RunState = False Then ExitLoop
  634.          Click(217, 510);Click Find a Match Button
  635.          If _Sleep(1000) Or $RunState = False Then ExitLoop
  636.          If _ColorCheckVariation(Hex(PixelGetColor(513 + $BSpos[0], 416 + $BSpos[1]), 6), Hex(0x5DAC10, 6), 20) Then
  637.             Click(513, 416);Click Okay To Break Shield
  638.          EndIf
  639.          ExitLoop
  640.       WEnd
  641.    EndFunc
  642. #EndRegion ### End Attack Functions ###
  643. ;---------------------------------------------------
  644. #Region ### Troops Settings ###
  645.    Func LocateBarrack()
  646.       SetLog("Locating Barracks...")
  647.       Local $MsgBox
  648.       While 1
  649.          While 1
  650.             $MsgBox = MsgBox(6+262144, "Locate first barrack", "Click Continue then click on your first barrack. Cancel if not available. Try again to start over.", 0, $frmBot)
  651.             If $MsgBox = 11 Then
  652.                   $barrackPos[0][0] = FindPos()[0]
  653.                   $barrackPos[0][1] = FindPos()[1]
  654.             ElseIf $MsgBox = 10 Then
  655.                ExitLoop
  656.             Else
  657.                $barrackPos[0][0] = ""
  658.                $barrackPos[0][1] = ""
  659.             EndIf
  660.  
  661.             $MsgBox = MsgBox(6+262144, "Locate second barrack", "Click Continue then click on your second barrack. Cancel if not available. Try again to start over.", 0, $frmBot)
  662.             If $MsgBox = 11 Then
  663.                $barrackPos[1][0] = FindPos()[0]
  664.                $barrackPos[1][1] = FindPos()[1]
  665.             ElseIf $MsgBox = 10 Then
  666.                ExitLoop
  667.             Else
  668.                $barrackPos[1][0] = ""
  669.                $barrackPos[1][1] = ""
  670.             EndIf
  671.  
  672.             $MsgBox = MsgBox(6+262144, "Locate third barrack", "Click Continue then click on your third barrack. Cancel if not available. Try again to start over.", 0, $frmBot)
  673.             If $MsgBox = 11 Then
  674.                $barrackPos[2][0] = FindPos()[0]
  675.                $barrackPos[2][1] = FindPos()[1]
  676.             ElseIf $MsgBox = 10 Then
  677.                ExitLoop
  678.             Else
  679.                $barrackPos[2][0] = ""
  680.                $barrackPos[2][1] = ""
  681.             EndIf
  682.  
  683.             $MsgBox = MsgBox(6+262144, "Locate fourth barrack", "Click Continue then click on your fourth barrack. Cancel if not available. Try again to start over.", 0, $frmBot)
  684.             If $MsgBox = 11 Then
  685.                $barrackPos[3][0] = FindPos()[0]
  686.                $barrackPos[3][1] = FindPos()[1]
  687.             ElseIf $MsgBox = 10 Then
  688.                ExitLoop
  689.             Else
  690.                $barrackPos[3][0] = ""
  691.                $barrackPos[3][1] = ""
  692.             EndIf
  693.             ExitLoop(2)
  694.          WEnd
  695.       WEnd
  696.       SaveConfig()
  697.       SetLog("-Locating Complete-")
  698.       SetLog("-Barrack 1 = " & "(" & $barrackPos[0][0] & "," & $barrackPos[0][1] & ")")
  699.       SetLog("-Barrack 2 = " & "(" & $barrackPos[1][0] & "," & $barrackPos[1][1] & ")")
  700.       SetLog("-Barrack 3 = " & "(" & $barrackPos[2][0] & "," & $barrackPos[2][1] & ")")
  701.       SetLog("-Barrack 4 = " & "(" & $barrackPos[3][0] & "," & $barrackPos[3][1] & ")")
  702.    EndFunc
  703.  
  704.    Func Train()
  705.          If $barrackPos[0][0] = "" Then
  706.             LocateBarrack()
  707.             SaveConfig()
  708.             If _Sleep(2000) Then Return
  709.          EndIf
  710.          SetLog("Training Troops...")
  711.  
  712.          While 1
  713.             For $i = 0 to 3
  714.                If _Sleep(1000) Or $RunState = False Then ExitLoop(2)
  715.                getBSPos()
  716.  
  717.                Click(1, 1) ;Click Away
  718.  
  719.                If _Sleep(500) Or $RunState = False Then ExitLoop(2)
  720.  
  721.                Click($barrackPos[$i][0], $barrackPos[$i][1]) ;Click Barrack
  722.  
  723.                If _Sleep(1000) Or $RunState = False Then ExitLoop(2)
  724.  
  725.                Local $TrainPos = PixelSearch($BSpos[0] + 155, $BSpos[1] + 557, $BSpos[0] + 694, $BSpos[1] + 642, 0x687DA1, 5) ;Finds Train Troops button
  726.                If IsArray($TrainPos) = False Then
  727.                   SetLog("Barrack " & $i + 1 & " is not available")
  728.  
  729.                   If _Sleep(1000) Or $RunState = False Then ExitLoop(2)
  730.                Else
  731.                   Click($TrainPos[0] - $BSpos[0], $TrainPos[1] - $BSpos[1]) ;Click Train Troops button
  732.                   If _Sleep(1000) Or $RunState = False Then ExitLoop(2)
  733.  
  734.                   CheckFullArmy()
  735.  
  736.                   Switch $barrackTroop[$i]
  737.                   Case 0
  738.                      Click(220, 320, 75, 1) ;Barbarian
  739.                   Case 1
  740.                      Click(331, 320, 75, 1) ;Archer
  741.                   Case 2
  742.                      Click(432, 320, 15, 1) ;Giant
  743.                   Case 3
  744.                      Click(546, 320, 75, 1) ;Goblins
  745.                   EndSwitch
  746.                EndIf
  747.                If _Sleep(500) Or $RunState = False Then ExitLoop(2)
  748.                Click(1, 1, 2, 500); Click away twice with 500ms delay
  749.             Next
  750.  
  751.             SetLog("Training Troops Complete")
  752.             ExitLoop
  753.          WEnd
  754.    EndFunc
  755.  
  756.    Func CheckFullArmy()
  757.       $Pixel = _ColorCheckVariation(Hex(PixelGetColor(327 + $BSpos[0], 520 + $BSpos[1]),6), Hex(0xD03838,6),20)
  758.       If $Pixel Then
  759.          $fullArmy = True
  760.       Else
  761.          $fullArmy = False
  762.       EndIf
  763.    EndFunc
  764. #EndRegion ### End Troops Settings ###
  765. ;---------------------------------------------------
  766. #Region ### Village Functions ###
  767. ;~    Func Collect()
  768. ;~    While 1
  769. ;~       SetLog("Collecting Resources")
  770. ;~       Local $Collector = PixelSearch($BSpos[0], $BSpos[1], $BSpos[0] + 860, $BSpos[1] + 720, 0xB0B875, 1, 1)
  771. ;~       If _Sleep(300) Then ExitLoop
  772. ;~       While IsArray($Collector)
  773. ;~          Click($Collector[0] - $BSpos[0], $Collector[1] - $BSpos[1])
  774. ;~          If _Sleep(300) Then ExitLoop(2)
  775. ;~          $Collector = PixelSearch($BSpos[0], $BSpos[1], $BSpos[0] + 860, $BSpos[1] + 720, 0xB0B875, 1, 1)
  776. ;~       WEnd
  777. ;~       SetLog("Collecting Complete")
  778. ;~       ExitLoop
  779. ;~    WEnd
  780. ;~    EndFunc
  781. #EndRegion ### End Village Functions ###
  782. ;---------------------------------------------------
  783. #Region ### Other Functions ###
  784.    Func ReadConfig() ;Reads config and sets it to the variables
  785.       If FileExists($config) Then
  786. ;Search Settings------------------------------------------------------------------------
  787.          $MinGold = IniRead($config, "search", "searchGold", "0")
  788.          $MinElixir = IniRead($config, "search", "searchElixir", "0")
  789.          $MinDark = IniRead($config, "search", "searchDark", "0")
  790.          $MinTrophy = IniRead($config, "search", "searchTrophy", "0")
  791.  
  792.          $chkConditions[0] = IniRead($config, "search", "conditionGoldElixir", "0")
  793.          $chkConditions[1] = IniRead($config, "search", "conditionDark", "0")
  794.          $chkConditions[2] = IniRead($config, "search", "conditionTrophy", "0")
  795. ;Attack Settings-------------------------------------------------------------------------
  796.          $deploySettings = IniRead($config, "attack", "deploy", "0")
  797.          $icmbAlgorithm = IniRead($config, "attack", "algorithm", "0")
  798.          $iradAttackMode = IniRead($config, "attack", "mode", "0")
  799. ;Donate Settings-------------------------------------------------------------------------
  800.  
  801. ;Troop Settings--------------------------------------------------------------------------
  802.          $icmbTroopComp = IniRead($config, "troop", "composition", 0)
  803.  
  804.          For $i = 0 to 3 ;Covers all 4 Barracks
  805.             $barrackPos[$i][0] = IniRead($config, "troop", "xBarrack" & $i+1, "0")
  806.             $barrackPos[$i][1] = IniRead($config, "troop", "yBarrack" & $i+1, "0")
  807.             $barrackTroop[$i] = IniRead($config, "troop", "troop" & $i+1, "0")
  808.          Next
  809.       Else
  810.          Return False
  811.       EndIf
  812.    EndFunc
  813.  
  814.    Func applyConfig() ;Applies the data from config to the controls in GUI
  815. ;Search Settings------------------------------------------------------------------------
  816.       GuiCtrlSetData($txtMinGold, $MinGold)
  817.       GuiCtrlSetData($txtMinElixir, $MinElixir)
  818.       GuiCtrlSetData($txtMinDarkElixir, $MinDark)
  819.       GuiCtrlSetData($txtMinTrophy, $MinTrophy)
  820.  
  821.       If $chkConditions[0] = 1 Then
  822.          GuiCtrlSetState($chkMeetGxE, $GUI_CHECKED)
  823.       ElseIf $chkConditions[0] = 0 Then
  824.          GuiCtrlSetState($chkMeetGxE, $GUI_UNCHECKED)
  825.       EndIf
  826.  
  827.       If $chkConditions[1] = 1 Then
  828.          GuiCtrlSetState($chkMeetDE, $GUI_CHECKED)
  829.       ElseIf $chkConditions[1] = 0 Then
  830.          GuiCtrlSetState($chkMeetDE, $GUI_UNCHECKED)
  831.       EndIf
  832.  
  833.       If $chkConditions[2] = 1 Then
  834.          GuiCtrlSetState($chkMeetTrophy, $GUI_CHECKED)
  835.       ElseIf $chkConditions[2] = 0 Then
  836.          GuiCtrlSetState($chkMeetTrophy, $GUI_UNCHECKED)
  837.       EndIf
  838. ;Attack Settings-------------------------------------------------------------------------
  839.       _GUICtrlComboBox_SetCurSel($cmbDeploy, $deploySettings)
  840.       _GUICtrlComboBox_SetCurSel($cmbAlgorithm, $icmbAlgorithm)
  841.  
  842.       Switch $iradAttackMode
  843.       Case 0
  844.          GUICtrlSetState($radDeadBases, $GUI_CHECKED)
  845.          GUICtrlSetState($radWeakBases, $GUI_UNCHECKED)
  846.          GUICtrlSetState($radAllBases, $GUI_UNCHECKED)
  847.       Case 1
  848.          GUICtrlSetState($radDeadBases, $GUI_UNCHECKED)
  849.          GUICtrlSetState($radWeakBases, $GUI_CHECKED)
  850.          GUICtrlSetState($radAllBases, $GUI_UNCHECKED)
  851.       Case 2
  852.          GUICtrlSetState($radDeadBases, $GUI_UNCHECKED)
  853.          GUICtrlSetState($radWeakBases, $GUI_UNCHECKED)
  854.          GUICtrlSetState($radAllBases, $GUI_CHECKED)
  855.       EndSwitch
  856. ;Donate Settings-------------------------------------------------------------------------
  857.  
  858. ;Troop Settings--------------------------------------------------------------------------
  859.       _GUICtrlComboBox_SetCurSel($cmbTroopComp, $icmbTroopComp)
  860.       SetComboTroopComp()
  861.  
  862.       _GUICtrlComboBox_SetCurSel($cmbBarrack1, $barrackTroop[0])
  863.       _GUICtrlComboBox_SetCurSel($cmbBarrack2, $barrackTroop[1])
  864.       _GUICtrlComboBox_SetCurSel($cmbBarrack3, $barrackTroop[2])
  865.       _GUICtrlComboBox_SetCurSel($cmbBarrack4, $barrackTroop[3])
  866.    EndFunc
  867.  
  868.    Func SaveConfig() ;Saves the controls settings to the config
  869. ;Search Settings------------------------------------------------------------------------
  870.          IniWrite($config, "search", "searchGold", GUICtrlRead($txtMinGold))
  871.          IniWrite($config, "search", "searchElixir", GUICtrlRead($txtMinElixir))
  872.          IniWrite($config, "search", "searchDark", GUICtrlRead($txtMinDarkElixir))
  873.          IniWrite($config, "search", "searchTrophy", GUICtrlRead($txtMinTrophy))
  874.  
  875.          If GUICtrlRead($chkMeetGxE) = $GUI_CHECKED Then
  876.             IniWrite($config, "search", "conditionGoldElixir", 1)
  877.          Else
  878.             IniWrite($config, "search", "conditionGoldElixir", 0)
  879.          EndIf
  880.  
  881.          If GUICtrlRead($chkMeetDE) = $GUI_CHECKED Then
  882.             IniWrite($config, "search", "conditionDark", 1)
  883.          Else
  884.             IniWrite($config, "search", "conditionDark", 0)
  885.          EndIf
  886.  
  887.          If GUICtrlRead($chkMeetTrophy) = $GUI_CHECKED Then
  888.             IniWrite($config, "search", "conditionTrophy", 1)
  889.          Else
  890.             IniWrite($config, "search", "conditionTrophy", 0)
  891.          EndIf
  892. ;Attack Settings-------------------------------------------------------------------------
  893.          IniWrite($config, "attack", "deploy",  _GUICtrlComboBox_GetCurSel($cmbDeploy))
  894.          IniWrite($config, "attack", "algorithm", _GUICtrlComboBox_GetCurSel($cmbAlgorithm))
  895.  
  896.          If GUICtrlRead($radDeadBases) = $GUI_CHECKED Then
  897.             IniWrite($config, "attack", "mode", 0)
  898.          ElseIf GUICtrlRead($radWeakBases) = $GUI_CHECKED Then
  899.             IniWrite($config, "attack", "mode", 1)
  900.          ElseIf GUICtrlREad($radAllBases) = $GUI_CHECKED Then
  901.             IniWrite($config, "attack", "mode", 2)
  902.          EndIf
  903.  
  904. ;Donate Settings-------------------------------------------------------------------------
  905.  
  906. ;Troop Settings--------------------------------------------------------------------------
  907.          IniWrite($config, "troop", "composition", _GUICtrlComboBox_GetCurSel($cmbTroopComp))
  908.  
  909.          IniWrite($config, "troop", "troop1",  _GUICtrlComboBox_GetCurSel($cmbBarrack1))
  910.          IniWrite($config, "troop", "troop2",  _GUICtrlComboBox_GetCurSel($cmbBarrack2))
  911.          IniWrite($config, "troop", "troop3",  _GUICtrlComboBox_GetCurSel($cmbBarrack3))
  912.          IniWrite($config, "troop", "troop4",  _GUICtrlComboBox_GetCurSel($cmbBarrack4))
  913.          For $i = 0 to 3 ;Covers all 4 Barracks
  914.             IniWrite($config, "troop", "xBarrack" & $i+1, $barrackPos[$i][0])
  915.             IniWrite($config, "troop", "yBarrack" & $i+1, $barrackPos[$i][1])
  916.          Next
  917.    EndFunc
  918. ;========================================================================================
  919.    Func SetLog($string) ;Sets the text for the log
  920.       _GUICtrlEdit_AppendText($txtLog, Time() & $string & @CRLF)
  921.       _GUICtrlStatusBar_SetText($statLog, "Status : " & $string)
  922.    EndFunc
  923.  
  924.    Func Time() ;Gives the time in '[00:00:00 AM/PM]' format
  925.       Return "[" & _NowTime(3) & "] "
  926.    EndFunc
  927.  
  928.    Func getBSPos()
  929.       $aPos = ControlGetPos("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]")
  930.       $tPoint = DllStructCreate("int X;int Y")
  931.       DllStructSetData($tpoint, "X", $aPos[0])
  932.       DllStructSetData($tpoint, "Y", $aPos[1])
  933.       _WinAPI_ClientToScreen(WinGetHandle(WinGetTitle("BlueStacks App Player")), $tPoint)
  934.  
  935.       $BSpos[0] = DllStructGetData($tpoint, "X")
  936.       $BSpos[1] = DllStructGetData($tpoint, "Y")
  937.  
  938.       $CtrlHandle = ControlGetHandle("BlueStacks App Player", "", "BlueStacksApp1")
  939.    EndFunc
  940.  
  941.    Func _Sleep($iDelay)
  942.       $iBegin = TimerInit()
  943.          While TimerDiff($iBegin) < $iDelay
  944.             Switch GUIGetMsg()
  945.             Case $GUI_EVENT_CLOSE
  946.                SaveConfig()
  947.                Exit
  948.             Case $btnStop
  949.                $RunState = False
  950.                GUICtrlSetState($btnStart, $GUI_ENABLE)
  951.                GUICtrlSetState($btnLocateBarracks, $GUI_ENABLE)
  952.                GUICtrlSetState($btnSearchMode, $GUI_ENABLE)
  953.                GUICtrlSetState($cmbTroopComp, $GUI_ENABLE)
  954.                GUICtrlSetState($btnStop, $GUI_DISABLE)
  955.                SetLog("Bot has stopped")
  956.                Return True
  957.             EndSwitch
  958.          WEnd
  959.       Return False
  960.    EndFunc
  961.  
  962.    Func Click($x, $y, $times = 1, $speed = 0)
  963.       If $times <> 1 Then
  964.          For $i = 0 To ($times - 1)
  965.             ControlClick("BlueStacks App Player", "", "", "left", "1", $x, $y)
  966.             If _Sleep($speed) Or $RunState = False Then ExitLoop
  967.          Next
  968.       Else
  969.          ControlClick("BlueStacks App Player", "", "", "left", "1", $x, $y)
  970.       EndIf
  971.    EndFunc
  972.  
  973.    Func FindPos()
  974.       Local $Pos[2]
  975.       While 1
  976.          If _IsPressed("01") Then
  977.             $Pos[0] = MouseGetPos()[0] - $BSpos[0]
  978.             $Pos[1] = MouseGetPos()[1] - $BSpos[1]
  979.             Return $Pos
  980.          EndIf
  981.       WEnd
  982.    EndFunc
  983.  
  984.    Func Tab($a, $b)
  985.       $Tab = ""
  986.       For $i = StringLen($a) to $b Step 1
  987.          $Tab &= " "
  988.       Next
  989.       Return $Tab
  990.    EndFunc
  991. #EndRegion ### End Other Functions ###
  992. ;---------------------------------------------------
  993. #Region ### Get Resources Functions ###
  994. ;==============================================================================================================
  995. ;===Main Function==============================================================================================
  996. ;--------------------------------------------------------------------------------------------------------------
  997. ;Checks if the color components exceed $sVari and returns true if they are below $sVari.
  998. ;--------------------------------------------------------------------------------------------------------------
  999.  
  1000. Func getGold($x_start, $y_start)
  1001.    Global $hDll = DllOpen("gdi32.dll")
  1002.    Global $vDC = _PixelGetColor_CreateDC($hDll)
  1003.    _PixelGetColor_CaptureRegion($vDC, 0, 0, $x_start + 90, $y_start + 20)
  1004.    ;-----------------------------------------------------------------------------
  1005.    Local $x = $x_start, $y = $y_start
  1006.    Local $Gold, $i = 0
  1007.    While getDigit($x, $y + $i, "Gold") = ""
  1008.       If $i >= 15 Then ExitLoop
  1009.       $i += 1
  1010.    WEnd
  1011.    $x = $x_start
  1012.    $Gold &= getDigit($x, $y + $i, "Gold")
  1013.    $Gold &= getDigit($x, $y + $i, "Gold")
  1014.    $Gold &= getDigit($x, $y + $i, "Gold")
  1015.    $x += 6
  1016.    $Gold &= getDigit($x, $y + $i, "Gold")
  1017.    $Gold &= getDigit($x, $y + $i, "Gold")
  1018.    $Gold &= getDigit($x, $y + $i, "Gold")
  1019.    Return $Gold
  1020. EndFunc
  1021.  
  1022. Func getElixir($x_start, $y_start)
  1023.    Global $hDll = DllOpen("gdi32.dll")
  1024.    Global $vDC = _PixelGetColor_CreateDC($hDll)
  1025.    _PixelGetColor_CaptureRegion($vDC, 0, 0, $x_start + 90, $y_start + 20)
  1026.    ;-----------------------------------------------------------------------------
  1027.    Local $x = $x_start, $y = $y_start
  1028.    Local $Elixir, $i = 0
  1029.    While getDigit($x, $y + $i, "Elixir") = ""
  1030.       If $i >= 15 Then ExitLoop
  1031.       $i += 1
  1032.    WEnd
  1033.    $x = $x_start
  1034.    $Elixir &= getDigit($x, $y + $i, "Elixir")
  1035.    $Elixir &= getDigit($x, $y + $i, "Elixir")
  1036.    $Elixir &= getDigit($x, $y + $i, "Elixir")
  1037.    $x += 6
  1038.    $Elixir &= getDigit($x, $y + $i, "Elixir")
  1039.    $Elixir &= getDigit($x, $y + $i, "Elixir")
  1040.    $Elixir &= getDigit($x, $y + $i, "Elixir")
  1041.    Return $Elixir
  1042. EndFunc
  1043.  
  1044. Func getDarkElixir($x_start, $y_start)
  1045.    Global $hDll = DllOpen("gdi32.dll")
  1046.    Global $vDC = _PixelGetColor_CreateDC($hDll)
  1047.    _PixelGetColor_CaptureRegion($vDC, 0, 0, $x_start + 90, $y_start + 20)
  1048.    ;-----------------------------------------------------------------------------
  1049.    Local $x = $x_start, $y = $y_start
  1050.    Local $DarkElixir, $i = 0
  1051.    While getDigit($x, $y + $i, "DarkElixir") = ""
  1052.     If $i >= 15 Then ExitLoop
  1053.     $i += 1
  1054.    WEnd
  1055.    $x = $x_start
  1056.    $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  1057.    $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  1058.    $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  1059.    $x += 6
  1060.    $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  1061.    $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  1062.    $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  1063.    Return $DarkElixir
  1064. EndFunc
  1065.  
  1066. Func getTrophy($x_start, $y_start)
  1067.    Global $hDll = DllOpen("gdi32.dll")
  1068.    Global $vDC = _PixelGetColor_CreateDC($hDll)
  1069.    _PixelGetColor_CaptureRegion($vDC, 0, 0, $x_start + 90, $y_start + 20)
  1070.    ;-----------------------------------------------------------------------------
  1071.    Local $x = $x_start, $y = $y_start
  1072.    Local $Trophy, $i = 0
  1073.    While getDigit($x, $y + $i, "Trophy") = ""
  1074.     If $i >= 15 Then ExitLoop
  1075.     $i += 1
  1076.    WEnd
  1077.    $x = $x_start
  1078.    $Trophy &= getDigit($x, $y + $i, "Trophy")
  1079.    $Trophy &= getDigit($x, $y + $i, "Trophy")
  1080.    Return $Trophy
  1081. EndFunc
  1082.  
  1083. Func getNormal($x_start, $y_start)
  1084.    Global $hDll = DllOpen("gdi32.dll")
  1085.    Global $vDC = _PixelGetColor_CreateDC($hDll)
  1086.    _PixelGetColor_CaptureRegion($vDC, 0, 0, $x_start + 90, $y_start + 20)
  1087.    ;-----------------------------------------------------------------------------
  1088.    Local $x = $x_start, $y = $y_start
  1089.    Local $Normal, $i = 0
  1090.  
  1091.    $Normal = getDigit($x, $y, "Normal")
  1092.  
  1093.    While $Normal = ""
  1094.     If $i >= 50 Then ExitLoop
  1095.     $i += 1
  1096.     $x += 1
  1097.     $Normal = getDigit($x, $y, "Normal")
  1098.    WEnd
  1099.  
  1100.  
  1101.    $Normal &= getDigit($x, $y, "Normal")
  1102.    $Normal &= getDigit($x, $y, "Normal")
  1103.  
  1104.    Return $Normal
  1105. EndFunc
  1106.  
  1107. ;==============================================================================================================
  1108. ;==============================================================================================================
  1109. ;===Color Variation============================================================================================
  1110. ;--------------------------------------------------------------------------------------------------------------
  1111. ;Checks if the color components exceed $sVari and returns true if they are below $sVari.
  1112. ;--------------------------------------------------------------------------------------------------------------
  1113.  
  1114. Func _ColorCheckVariation($nColor1, $nColor2, $sVari=5)
  1115.     $Red1 = Dec(StringMid(String($nColor1), 1, 2))
  1116.     $Blue1 = Dec(StringMid(String($nColor1), 3, 2))
  1117.     $Green1 = Dec(StringMid(String($nColor1), 5, 2))
  1118.  
  1119.     $Red2 = Dec(StringMid(String($nColor2), 1, 2))
  1120.     $Blue2 = Dec(StringMid(String($nColor2), 3, 2))
  1121.     $Green2 = Dec(StringMid(String($nColor2), 5, 2))
  1122.  
  1123.     If abs($Blue1 - $Blue2) > $sVari Then Return False
  1124.     If abs($Green1 - $Green2) > $sVari Then Return False
  1125.     If abs($Red1 - $Red2) > $sVari Then Return False
  1126.     Return True
  1127. EndFunc
  1128.  
  1129. ;==============================================================================================================
  1130. ;===Check Pixels===============================================================================================
  1131. ;--------------------------------------------------------------------------------------------------------------
  1132. ;Using _ColorCheckVariation, checks compares multiple pixels and returns true if they all pass _ColorCheckVariation.
  1133. ;--------------------------------------------------------------------------------------------------------------
  1134.  
  1135. Func boolPixelSearch($pixel1, $pixel2, $pixel3)
  1136.     Local $Color1 = _PixelGetColor_GetPixel($vDC, $pixel1[0], $pixel1[1])
  1137.     Local $Color2 = _PixelGetColor_GetPixel($vDC, $pixel2[0], $pixel2[1])
  1138.     Local $Color3 = _PixelGetColor_GetPixel($vDC, $pixel3[0], $pixel3[1])
  1139.     If _ColorCheckVariation($Color1, $pixel1[2], 10) And _ColorCheckVariation($Color2, $pixel2[2], 10) And _ColorCheckVariation($Color3, $pixel3[2], 10) Then Return True
  1140.     Return False
  1141. EndFunc
  1142.  
  1143. ;==============================================================================================================
  1144. ;===Get Digit Gold=============================================================================================
  1145. ;--------------------------------------------------------------------------------------------------------------
  1146. ;Finds pixel color pattern of specific X and Y values, returns digit if pixel color pattern found.
  1147. ;--------------------------------------------------------------------------------------------------------------
  1148.  
  1149. Func getDigit(ByRef $x, $y, $type)
  1150.     Local $width = 0
  1151.  
  1152.     ;Search for digit 0
  1153.     $width = 13
  1154.     Select
  1155.         Case $type = "Gold"
  1156.             Local $c1 = Hex(0x989579, 6),   $c2 = Hex(0x39382E, 6), $c3 = Hex(0x272720, 6)
  1157.         Case $type = "Elixir"
  1158.             Local $c1 = Hex(0x978A96, 6),   $c2 = Hex(0x393439, 6), $c3 = Hex(0x272427, 6)
  1159.         Case $type = "DarkElixir"
  1160.             Local $c1 = Hex(0x909090, 6),   $c2 = Hex(0x363636, 6), $c3 = Hex(0x262626, 6)
  1161.         Case $type = "Trophy"
  1162.             Local $c1 = Hex(0x979797, 6),   $c2 = Hex(0x393939, 6), $c3 = Hex(0x272727, 6)
  1163.         Case $type = "Normal"
  1164.             Local $c1 = Hex(0x979797, 6),   $c2 = Hex(0x393939, 6), $c3 = Hex(0x262626, 6)
  1165.     EndSelect
  1166.     Local $pixel1[3] = [$x+6, $y+4, $c1], $pixel2[3] = [$x+7, $y+7, $c2], $pixel3[3] = [$x+10, $y+13, $c3]
  1167.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1168.       $x += $width ;Adds to x coordinate to get the next digit
  1169.       Return 0
  1170.     Else
  1171.       $x -= 1 ;Solves the problem when the spaces between the middle goes from 6 to 5 pixels
  1172.       Local $pixel1[3] = [$x+6, $y+4, $c1], $pixel2[3] = [$x+7, $y+7, $c2], $pixel3[3] = [$x+10, $y+13, $c3]
  1173.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1174.          $x += $width ;Changes x coordinate for the next digit.
  1175.          Return 0
  1176.       Else
  1177.          $x += 2 ;Solves the problem when there is 1 pixel space between a set of numbers
  1178.          Local $pixel1[3] = [$x+6, $y+4, $c1], $pixel2[3] = [$x+7, $y+7, $c2], $pixel3[3] = [$x+10, $y+13, $c3]
  1179.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1180.             $x += $width
  1181.             Return 0
  1182.          Else
  1183.             $x -= 1
  1184.          EndIf
  1185.       EndIf
  1186.     EndIf
  1187.  
  1188.     ;Search for digit 1
  1189.     $width = 6
  1190.     Select
  1191.         Case $type = "Gold"
  1192.             Local $c1 = Hex(0x979478, 6),   $c2 = Hex(0x313127, 6), $c3 = Hex(0xD7D4AC, 6)
  1193.         Case $type = "Elixir"
  1194.             Local $c1 = Hex(0x968895, 6),   $c2 = Hex(0x312D31, 6), $c3 = Hex(0xD8C4D6, 6)
  1195.         Case $type = "DarkElixir"
  1196.             Local $c1 = Hex(0x8F8F8F, 6),   $c2 = Hex(0x2F2F2F, 6), $c3 = Hex(0xCDCDCD, 6)
  1197.         Case $type = "Trophy"
  1198.             Local $c1 = Hex(0x969696, 6),   $c2 = Hex(0x313131, 6), $c3 = Hex(0xD8D8D8, 6)
  1199.         Case $type = "Normal"
  1200.             Local $c1 = Hex(0x969696, 6),   $c2 = Hex(0x313131, 6), $c3 = Hex(0xD8D8D8, 6)
  1201.     EndSelect
  1202.     Local $pixel1[3] = [$x+1, $y+1, $c1], $pixel2[3] = [$x+1, $y+12, $c2], $pixel3[3] = [$x+4, $y+12, $c3]
  1203.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1204.       $x += $width
  1205.       Return 1
  1206.     Else
  1207.       $x -= 1
  1208.       Local $pixel1[3] = [$x+1, $y+1, $c1], $pixel2[3] = [$x+1, $y+12, $c2], $pixel3[3] = [$x+4, $y+12, $c3]
  1209.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1210.          $x += $width
  1211.          Return 1
  1212.       Else
  1213.          $x += 2
  1214.          Local $pixel1[3] = [$x+1, $y+1, $c1], $pixel2[3] = [$x+1, $y+12, $c2], $pixel3[3] = [$x+4, $y+12, $c3]
  1215.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1216.             $x += $width
  1217.             Return 1
  1218.          Else
  1219.             $x -= 1
  1220.          EndIf
  1221.       EndIf
  1222.     EndIf
  1223.  
  1224.     ;Search for digit 2
  1225.     $width = 10
  1226.     Select
  1227.         Case $type = "Gold"
  1228.             Local $c1 = Hex(0xA09E80, 6),   $c2 = Hex(0xD8D4AC, 6), $c3 = Hex(0x979579, 6)
  1229.         Case $type = "Elixir"
  1230.             Local $c1 = Hex(0xA0919F, 6),   $c2 = Hex(0xD8C4D6, 6), $c3 = Hex(0x978A96, 6)
  1231.         Case $type = "DarkElixir"
  1232.             Local $c1 = Hex(0x989898, 6),   $c2 = Hex(0xCDCDCD, 6), $c3 = Hex(0x909090, 6)
  1233.         Case $type = "Trophy"
  1234.             Local $c1 = Hex(0xA0A0A0, 6),   $c2 = Hex(0xD8D8D8, 6), $c3 = Hex(0x979797, 6)
  1235.         Case $type = "Normal"
  1236.             Local $c1 = Hex(0xA0A0A0, 6),   $c2 = Hex(0xD8D8D8, 6), $c3 = Hex(0x979797, 6)
  1237.     EndSelect
  1238.     Local $pixel1[3] = [$x+1, $y+7, $c1], $pixel2[3] = [$x+3, $y+6, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  1239.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1240.       $x += $width
  1241.       Return 2
  1242.     Else
  1243.       $x -= 1
  1244.       Local $pixel1[3] = [$x+1, $y+7, $c1], $pixel2[3] = [$x+3, $y+6, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  1245.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1246.          $x += $width
  1247.          Return 2
  1248.       Else
  1249.          $x += 2
  1250.          Local $pixel1[3] = [$x+1, $y+7, $c1], $pixel2[3] = [$x+3, $y+6, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  1251.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1252.             $x += $width
  1253.             Return 2
  1254.          Else
  1255.             $x -= 1
  1256.          EndIf
  1257.       EndIf
  1258.     EndIf
  1259.  
  1260.     ;Search for digit 3
  1261.     $width = 10
  1262.     Select
  1263.         Case $type = "Gold"
  1264.             Local $c1 = Hex(0x7F7D65, 6),   $c2 = Hex(0x070706, 6), $c3 = Hex(0x37362C, 6)
  1265.         Case $type = "Elixir"
  1266.             Local $c1 = Hex(0x7F737E, 6),   $c2 = Hex(0x070607, 6), $c3 = Hex(0x373236, 6)
  1267.         Case $type = "DarkElixir"
  1268.             Local $c1 = Hex(0x797979, 6),   $c2 = Hex(0x070707, 6), $c3 = Hex(0x343434, 6)
  1269.         Case $type = "Trophy"
  1270.             Local $c1 = Hex(0x7F7F7F, 6),   $c2 = Hex(0x070707, 6), $c3 = Hex(0x373737, 6)
  1271.         Case $type = "Normal"
  1272.             Local $c1 = Hex(0x7F7F7F, 6),   $c2 = Hex(0x070707, 6), $c3 = Hex(0x373737, 6)
  1273.     EndSelect
  1274.     Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+4, $y+8, $c2], $pixel3[3] = [$x+5, $y+13, $c3]
  1275.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1276.       $x += $width
  1277.       Return 3
  1278.     Else
  1279.       $x -= 1
  1280.       Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+4, $y+8, $c2], $pixel3[3] = [$x+5, $y+13, $c3]
  1281.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1282.          $x += $width
  1283.          Return 3
  1284.       Else
  1285.          $x += 2
  1286.          Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+4, $y+8, $c2], $pixel3[3] = [$x+5, $y+13, $c3]
  1287.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1288.             $x += $width
  1289.             Return 3
  1290.          Else
  1291.                $x -= 1
  1292.          EndIf
  1293.       EndIf
  1294.     EndIf
  1295.  
  1296.     ;Search for digit 4
  1297.     $width = 12
  1298.     Select
  1299.         Case $type = "Gold"
  1300.             Local $c1 = Hex(0x282720, 6),   $c2 = Hex(0x080806, 6), $c3 = Hex(0x403F33, 6)
  1301.         Case $type = "Elixir"
  1302.             Local $c1 = Hex(0x282428, 6),   $c2 = Hex(0x080708, 6), $c3 = Hex(0x403A40, 6)
  1303.         Case $type = "DarkElixir"
  1304.             Local $c1 = Hex(0x262626, 6),   $c2 = Hex(0x070707, 6), $c3 = Hex(0x3D3D3D, 6)
  1305.         Case $type = "Trophy"
  1306.             Local $c1 = Hex(0x282828, 6),   $c2 = Hex(0x080808, 6), $c3 = Hex(0x404040, 6)
  1307.         Case $type = "Normal"
  1308.             Local $c1 = Hex(0x282828, 6),   $c2 = Hex(0x080808, 6), $c3 = Hex(0x404040, 6)
  1309.     EndSelect
  1310.     Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+3, $y+1, $c2], $pixel3[3] = [$x+1, $y+5, $c3]
  1311.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1312.       $x += $width
  1313.       Return 4
  1314.     Else
  1315.       $x -= 1
  1316.       Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+3, $y+1, $c2], $pixel3[3] = [$x+1, $y+5, $c3]
  1317.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1318.          $x += $width
  1319.          Return 4
  1320.       Else
  1321.          $x += 2
  1322.          Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+3, $y+1, $c2], $pixel3[3] = [$x+1, $y+5, $c3]
  1323.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1324.             $x += $width
  1325.             Return 4
  1326.          Else
  1327.             $x -= 1
  1328.          EndIf
  1329.       EndIf
  1330.     EndIf
  1331.  
  1332.     ;Search for digit 5
  1333.     $width = 10
  1334.     Select
  1335.         Case $type = "Gold"
  1336.             Local $c1 = Hex(0x060604, 6),   $c2 = Hex(0x040403, 6), $c3 = Hex(0xB7B492, 6)
  1337.         Case $type = "Elixir"
  1338.             Local $c1 = Hex(0x060606, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0xB7A7B6, 6)
  1339.         Case $type = "DarkElixir"
  1340.             Local $c1 = Hex(0x060606, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0xAFAFAF, 6)
  1341.         Case $type = "Trophy"
  1342.             Local $c1 = Hex(0x060606, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0xB7B7B7, 6)
  1343.         Case $type = "Normal"
  1344.             Local $c1 = Hex(0x060606, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0xB7B7B7, 6)
  1345.     EndSelect
  1346.     Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+4, $y+9, $c2], $pixel3[3] = [$x+6, $y+12, $c3]
  1347.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1348.       $x += $width
  1349.       Return 5
  1350.     Else
  1351.       $x -= 1
  1352.       Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+4, $y+9, $c2], $pixel3[3] = [$x+6, $y+12, $c3]
  1353.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1354.          $x += $width
  1355.          Return 5
  1356.       Else
  1357.          $x += 2
  1358.          Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+4, $y+9, $c2], $pixel3[3] = [$x+6, $y+12, $c3]
  1359.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1360.             $x += $width
  1361.             Return 5
  1362.          Else
  1363.             $x -= 1
  1364.          EndIf
  1365.       EndIf
  1366.     EndIf
  1367.  
  1368.     ;Search for digit 6
  1369.     $width = 11
  1370.     Select
  1371.         Case $type = "Gold"
  1372.             Local $c1 = Hex(0x070605, 6),   $c2 = Hex(0x040403, 6), $c3 = Hex(0x181713, 6)
  1373.         Case $type = "Elixir"
  1374.             Local $c1 = Hex(0x070707, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0x181618, 6)
  1375.         Case $type = "DarkElixir"
  1376.             Local $c1 = Hex(0x060606, 6),   $c2 = Hex(0x030303, 6), $c3 = Hex(0x161616, 6)
  1377.         Case $type = "Trophy"
  1378.             Local $c1 = Hex(0x070707, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0x181818, 6)
  1379.         Case $type = "Normal"
  1380.             Local $c1 = Hex(0x070707, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0x181818, 6)
  1381.     EndSelect
  1382.     Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+5, $c3]
  1383.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1384.       $x += $width
  1385.       Return 6
  1386.     Else
  1387.       $x -= 1
  1388.       Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+5, $c3]
  1389.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1390.          $x += $width
  1391.          Return 6
  1392.       Else
  1393.          $x += 2
  1394.          Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+5, $c3]
  1395.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1396.             $x += $width
  1397.             Return 6
  1398.          Else
  1399.             $x -= 1
  1400.          EndIf
  1401.       EndIf
  1402.     EndIf
  1403.  
  1404.     ;Search for digit 7
  1405.     $width = 10
  1406.     Select
  1407.         Case $type = "Gold"
  1408.             Local $c1 = Hex(0x5E5C4B, 6),   $c2 = Hex(0x87856C, 6), $c3 = Hex(0x5D5C4B, 6)
  1409.         Case $type = "Elixir"
  1410.             Local $c1 = Hex(0x5F565E, 6),   $c2 = Hex(0x877B86, 6), $c3 = Hex(0x5F565E, 6)
  1411.         Case $type = "DarkElixir"
  1412.             Local $c1 = Hex(0x5A5A5A, 6),   $c2 = Hex(0x818181, 6), $c3 = Hex(0x5A5A5A, 6)
  1413.         Case $type = "Trophy"
  1414.             Local $c1 = Hex(0x5F5F5F, 6),   $c2 = Hex(0x878787, 6), $c3 = Hex(0x5F5F5F, 6)
  1415.         Case $type = "Normal"
  1416.             Local $c1 = Hex(0x5F5F5F, 6),   $c2 = Hex(0x878787, 6), $c3 = Hex(0x5F5F5F, 6)
  1417.     EndSelect
  1418.     Local $pixel1[3] = [$x+5, $y+11, $c1], $pixel2[3] = [$x+4, $y+3, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  1419.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1420.       $x += $width
  1421.       Return 7
  1422.     Else
  1423.       $x -= 1
  1424.       Local $pixel1[3] = [$x+5, $y+11, $c1], $pixel2[3] = [$x+4, $y+3, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  1425.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1426.          $x += $width
  1427.          Return 7
  1428.       Else
  1429.          $x += 2
  1430.          Local $pixel1[3] = [$x+5, $y+11, $c1], $pixel2[3] = [$x+4, $y+3, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  1431.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1432.             $x += $width
  1433.             Return 7
  1434.          Else
  1435.             $x -= 1
  1436.          EndIf
  1437.       EndIf
  1438.     EndIf
  1439.  
  1440.     ;Search for digit 8
  1441.     $width = 11
  1442.     Select
  1443.         Case $type = "Gold"
  1444.             Local $c1 = Hex(0x27261F, 6),   $c2 = Hex(0x302F26, 6), $c3 = Hex(0x26261F, 6)
  1445.         Case $type = "Elixir"
  1446.             Local $c1 = Hex(0x272427, 6),   $c2 = Hex(0x302B2F, 6), $c3 = Hex(0x26261F, 6)
  1447.         Case $type = "DarkElixir"
  1448.             Local $c1 = Hex(0x252525, 6),   $c2 = Hex(0x2D2D2D, 6), $c3 = Hex(0x242424, 6)
  1449.         Case $type = "Trophy"
  1450.             Local $c1 = Hex(0x272727, 6),   $c2 = Hex(0x303030, 6), $c3 = Hex(0x262626, 6)
  1451.         Case $type = "Normal"
  1452.             Local $c1 = Hex(0x272727, 6),   $c2 = Hex(0x303030, 6), $c3 = Hex(0x262626, 6)
  1453.     EndSelect
  1454.     Local $pixel1[3] = [$x+5, $y+3, $c1], $pixel2[3] = [$x+5, $y+10, $c2], $pixel3[3] = [$x+1, $y+6, $c3]
  1455.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1456.       $x += $width
  1457.       Return 8
  1458.     Else
  1459.       $x -= 1
  1460.       Local $pixel1[3] = [$x+5, $y+3, $c1], $pixel2[3] = [$x+5, $y+10, $c2], $pixel3[3] = [$x+1, $y+6, $c3]
  1461.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1462.          $x += $width
  1463.          Return 8
  1464.       Else
  1465.          $x += 2
  1466.          Local $pixel1[3] = [$x+5, $y+3, $c1], $pixel2[3] = [$x+5, $y+10, $c2], $pixel3[3] = [$x+1, $y+6, $c3]
  1467.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1468.             $x += $width
  1469.             Return 8
  1470.          Else
  1471.             $x -= 1
  1472.          EndIf
  1473.       EndIf
  1474.     EndIf
  1475.  
  1476.     ;Search for digit 9
  1477.     $width = 11
  1478.     Select
  1479.         Case $type = "Gold"
  1480.             Local $c1 = Hex(0x302F26, 6),   $c2 = Hex(0x050504, 6), $c3 = Hex(0x272720, 6)
  1481.         Case $type = "Elixir"
  1482.             Local $c1 = Hex(0x302C30, 6),   $c2 = Hex(0x050505, 6), $c3 = Hex(0x282427, 6)
  1483.         Case $type = "DarkElixir"
  1484.             Local $c1 = Hex(0x2E2E2E, 6),   $c2 = Hex(0x050505, 6), $c3 = Hex(0x262626, 6)
  1485.         Case $type = "Trophy"
  1486.             Local $c1 = Hex(0x303030, 6),   $c2 = Hex(0x050505, 6), $c3 = Hex(0x272727, 6)
  1487.         Case $type = "Normal"
  1488.             Local $c1 = Hex(0x303030, 6),   $c2 = Hex(0x050505, 6), $c3 = Hex(0x272727, 6)
  1489.     EndSelect
  1490.     Local $pixel1[3] = [$x+5, $y+5, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+12, $c3]
  1491.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1492.       $x += $width
  1493.       Return 9
  1494.     Else
  1495.       $x -= 1
  1496.       Local $pixel1[3] = [$x+5, $y+5, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+12, $c3]
  1497.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1498.          $x += $width
  1499.          Return 9
  1500.       Else
  1501.          $x += 2
  1502.          Local $pixel1[3] = [$x+5, $y+5, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+12, $c3]
  1503.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  1504.             $x += $width
  1505.             Return 9
  1506.          Else
  1507.             $x -= 1
  1508.          EndIf
  1509.       EndIf
  1510.     EndIf
  1511.     Return ""
  1512. EndFunc
  1513.  
  1514. ;==============================================================================================================
  1515. ;===Other Functions============================================================================================
  1516. ;==============================================================================================================
  1517.  
  1518. Func _PixelGetColor_CreateDC($hDll = "gdi32.dll")
  1519.     $iPixelGetColor_MemoryContext = DllCall($hDll, "int", "CreateCompatibleDC", "int", 0)
  1520.     If @error Then Return SetError(@error,0,0)
  1521.     Return $iPixelGetColor_MemoryContext[0]
  1522. EndFunc
  1523.  
  1524. Func _PixelGetColor_CaptureRegion($iPixelGetColor_MemoryContext, $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = False, $hDll = "gdi32.dll")
  1525.     $HBITMAP = _ScreenCapture_Capture("", $iLeft, $iTop, $iRight, $iBottom, $fCursor)
  1526.     DllCall($hDll, "hwnd", "SelectObject", "int", $iPixelGetColor_MemoryContext, "hwnd", $HBITMAP)
  1527.     Return $HBITMAP
  1528. EndFunc
  1529.  
  1530. Func _PixelGetColor_GetPixel($iPixelGetColor_MemoryContext,$iX,$iY, $hDll = "gdi32.dll")
  1531.     $iColor = DllCall($hDll,"int","GetPixel","int",$iPixelGetColor_MemoryContext,"int",$iX,"int",$iY)
  1532.     If $iColor[0] = -1 then Return SetError(1,0,-1)
  1533.     $sColor = Hex($iColor[0],6)
  1534.     Return StringRight($sColor,2) & StringMid($sColor,3,2) & StringLeft($sColor,2)
  1535. EndFunc
  1536. #EndRegion ### End Get Resources Functions ###
  1537. ;---------------------------------------------------
  1538. #Region ### Check Dead Base Functions ###
  1539. ;==============================================================================================================
  1540. ;===Main Function==============================================================================================
  1541. ;--------------------------------------------------------------------------------------------------------------
  1542. ;Uses imagesearch to see whether a collector is full or semi-full to indicate that it is a dead base
  1543. ;Returns True if it is, returns false if it is not a dead base
  1544. ;--------------------------------------------------------------------------------------------------------------
  1545. Func CheckDeadBase()
  1546.  
  1547. EndFunc
  1548. ;==============================================================================================================
  1549. ;===Other Functions============================================================================================
  1550. ;==============================================================================================================
  1551. Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance, $HBMP=0)
  1552.    return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP)
  1553. EndFunc
  1554.  
  1555. Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance,$HBMP=0)
  1556.     ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
  1557.     if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
  1558. If IsString($findImage) Then
  1559.     $result = DllCall("COC Bot V005.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
  1560. Else
  1561.     $result = DllCall("COC Bot V005.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP)
  1562. EndIf
  1563.  
  1564.     ; If error exit
  1565.     if $result[0]="0" then return 0
  1566.  
  1567.     ; Otherwise get the x,y location of the match and the size of the image to
  1568.     ; compute the centre of search
  1569.     $array = StringSplit($result[0],"|")
  1570.  
  1571.    $x=Int(Number($array[2]))
  1572.    $y=Int(Number($array[3]))
  1573.    if $resultPosition=1 then
  1574.       $x=$x + Int(Number($array[4])/2)
  1575.       $y=$y + Int(Number($array[5])/2)
  1576.    endif
  1577.    return 1
  1578. EndFunc
  1579. #EndRegion ### End Check Zombie BAse Functions ###
Add Comment
Please, Sign In to add comment