Advertisement
Guest User

54222custom

a guest
Jan 24th, 2015
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 108.81 KB | None | 0 0
  1. #RequireAdmin
  2. #AutoIt3Wrapper_UseX64=n
  3.  
  4. $sBotTitle = "COC Bot v5.4.2.2.2-custom"
  5.  
  6. DirCreate(@ScriptDir & "\Loots\")
  7. DirCreate(@ScriptDir & "\logs\")
  8.  
  9. If _Singleton($sBotTitle, 1) = 0 Then
  10.     MsgBox(0, "", "Bot is already running.")
  11.     Exit
  12. EndIf
  13.  
  14. #include <ButtonConstants.au3>
  15. #include <ComboConstants.au3>
  16. #include <EditConstants.au3>
  17. #include <FileConstants.au3>
  18. #include <GUIConstantsEx.au3>
  19. #include <GuiStatusBar.au3>
  20. #include <GUIEdit.au3>
  21. #include <GUIComboBox.au3>
  22. #include <StaticConstants.au3>
  23. #include <TabConstants.au3>
  24. #include <WindowsConstants.au3>
  25. #include <WinAPIProc.au3>
  26. #include <ScreenCapture.au3>
  27. #include <Date.au3>
  28. #include <Misc.au3>
  29. #include <File.au3>
  30. #include <TrayConstants.au3>
  31. #include <GUIMenu.au3>
  32. #include <ColorConstants.au3>
  33. #include <GDIPlus.au3>
  34.  
  35. Opt("GUIOnEventMode", 1)
  36. Opt("MouseClickDelay", 10)
  37. Opt("MouseClickDownDelay", 10)
  38.  
  39. #Region #####Global Variables#####
  40. Global $Compiled
  41. If @Compiled Then
  42.     $Compiled = "Executable"
  43. Else
  44.     $Compiled = "Au3 Script"
  45. EndIf
  46.  
  47. Global $hBitmap; Image for pixel functions
  48. Global $hHBitmap; Handle Image for Pixel Functions
  49.  
  50. Global $config = @ScriptDir & "\config.ini"
  51. Global $sLogPath ; `Will create a new log file every time the start button is pressed
  52. Global $hLogFileHandle
  53. Global $Restart = False
  54. Global $RunState = False
  55.  
  56. Global $cmbTroopComp ;For Event change on ComboBox Troop Compositions
  57. Global $iCollectCounter = 0 ; Collect counter, when reaches $COLLECTATCOUNT, it will collect
  58. Global $COLLECTATCOUNT = 8 ; Run Collect() after this amount of times before actually collect
  59. ;---------------------------------------------------------------------------------------------------
  60. Global $BSpos[2] ; Inside BlueStacks positions relative to the screen
  61. Global $CtrlHandle ; BlueStacks control handle
  62. ;---------------------------------------------------------------------------------------------------
  63. ;Search Settings
  64. Global $searchGold, $searchElixir, $searchDark, $searchTrophy ;Resources of bases when searching
  65. Global $MinGold, $MinElixir, $MinDark, $MinTrophy ; Minimum Resources conditions
  66. Global $chkConditions[3] ;Conditions (meet gold...)
  67.  
  68. Global $SearchCount = 0 ;Number of searches
  69. ;Attack Settings
  70. Global $TopLeft[5][2] = [[110, 250], [170, 205], [234, 162], [296, 115], [368, 66]]
  71. Global $TopRight[5][2] = [[480, 63], [540, 104], [589, 146], [655, 190], [717, 240]]
  72. Global $BottomLeft[5][2] = [[79, 342], [142, 389], [210, 446], [276, 492], [339, 539]]
  73. Global $BottomRight[5][2] = [[523, 537], [595, 484], [654, 440], [715, 393], [779, 344]]
  74.  
  75. Global $atkTroops[7][2] ;7 Slots of troops -  Name,Amount
  76. Global $icmbAlgorithm ;Algorithm to use when attacking
  77.  
  78. Global $fullArmy ;Check for full army or not
  79. Global $deploySettings ;Method of deploy found in attack settings
  80.  
  81. Global $KingAttack[3] ;King attack settings
  82. Global $QueenAttack[3] ;Queen attack settings
  83.  
  84. Global $checkKPower = -1 ;Check for King and Queen activate power
  85. Global $checkQPower = -1
  86. Global $delayActivateKQ = 20000 ;Delay before activating KQ
  87. Global $iradAttackMode ;Attack mode, 0 1 2
  88. ;Donate Settings
  89.  
  90. ;Troop Settings
  91. Global $icmbTroopComp ;Troop Composition
  92.  
  93. Global $barrackPos[4][2] ;Positions of each barracks
  94. Global $barrackTroop[4] ;Barrack troop set
  95.  
  96. Global $CCPos[2] = [-1, -1] ;Position of clan castle
  97. Global $TextRequest
  98. Global $CheckRequest
  99. Global $donatec
  100. Global $chkAttackpoint
  101. ;General Settings
  102. Global $botPos[2] ; Position of bot used for Hide function
  103. Global $frmBotPosX ; Position X of the GUI
  104. Global $frmBotPosY ; Position Y of the GUI
  105. Global $Hide = False ; If hidden or not
  106.  
  107. Global $itxtMaxTrophy ; Max trophy before drop trophy
  108. Global $ichkBackground ; Background mode enabled disabled
  109. Global $collectorPos[17][2] ;Positions of each collectors
  110.  
  111. ;checkDeadBase Variables:-------------===========================
  112. Global $Title = "BlueStacks App Player"
  113. Global $HWnD = WinGetHandle(WinGetTitle($Title))
  114.  
  115. Global $ZC = 0, $ZombieCount = 0, $E
  116. Global $ZombieFileSets = 5 ;Variant Image to use organized as per Folder
  117. Global $Tolerance = 90
  118.  
  119. Global $Lx[4] = [0, 400, 0, 400]
  120. Global $Ly[4] = [0, 0, 265, 265]
  121. Global $Rx[4] = [460, 860, 400, 860]
  122. Global $Ry[4] = [325, 325, 590, 590]
  123.  
  124. Global $Area[5][4], $IS_x[8][4], $IS_y[8][4], $E[5][5]
  125.  
  126. $E[0][0] = @ScriptDir & "\images\ELIX1\E9F9.bmp"
  127. $E[0][1] = @ScriptDir & "\images\ELIX1\E10F8.bmp"
  128. $E[0][2] = @ScriptDir & "\images\ELIX1\E10F9.bmp"
  129. $E[0][3] = @ScriptDir & "\images\ELIX1\E11F8.bmp"
  130. $E[0][4] = @ScriptDir & "\images\ELIX1\E11F9.bmp"
  131.  
  132. $E[1][0] = @ScriptDir & "\images\ELIX2\E9F9.bmp"
  133. $E[1][1] = @ScriptDir & "\images\ELIX2\E10F8.bmp"
  134. $E[1][2] = @ScriptDir & "\images\ELIX2\E10F9.bmp"
  135. $E[1][3] = @ScriptDir & "\images\ELIX2\E11F8.bmp"
  136. $E[1][4] = @ScriptDir & "\images\ELIX2\E11F9.bmp"
  137.  
  138. $E[2][0] = @ScriptDir & "\images\ELIX3\E9F9.bmp"
  139. $E[2][1] = @ScriptDir & "\images\ELIX3\E10F8.bmp"
  140. $E[2][2] = @ScriptDir & "\images\ELIX3\E10F9.bmp"
  141. $E[2][3] = @ScriptDir & "\images\ELIX3\E11F8.bmp"
  142. $E[2][4] = @ScriptDir & "\images\ELIX3\E11F9.bmp"
  143.  
  144. $E[3][0] = @ScriptDir & "\images\ELIX4\E9F9.bmp"
  145. $E[3][1] = @ScriptDir & "\images\ELIX4\E10F8.bmp"
  146. $E[3][2] = @ScriptDir & "\images\ELIX4\E10F9.bmp"
  147. $E[3][3] = @ScriptDir & "\images\ELIX4\E11F8.bmp"
  148. $E[3][4] = @ScriptDir & "\images\ELIX4\E11F9.bmp"
  149.  
  150. $E[4][0] = @ScriptDir & "\images\ELIXSNOW\E9F9.bmp"
  151. $E[4][1] = @ScriptDir & "\images\ELIXSNOW\E10F8.bmp"
  152. $E[4][2] = @ScriptDir & "\images\ELIXSNOW\E10F9.bmp"
  153. $E[4][3] = @ScriptDir & "\images\ELIXSNOW\E11F8.bmp"
  154. $E[4][4] = @ScriptDir & "\images\ELIXSNOW\E11F9.bmp"
  155.  
  156. #EndRegion #####Global Variables#####
  157. ;---------------------------------------------------
  158.  
  159. #Region ### START Koda GUI section ###
  160. $frmBot = GUICreate($sBotTitle, 417, 392, 207, 158)
  161. $tabMain = GUICtrlCreateTab(8, 8, 401, 355)
  162. $pageGeneral = GUICtrlCreateTabItem("General")
  163. $txtLog = GUICtrlCreateEdit("", 16, 40, 385, 240, BitOR($ES_AUTOVSCROLL, $ES_NOHIDESEL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
  164. GUICtrlSetBkColor(-1, 0xFFFFFF)
  165. $Controls = GUICtrlCreateGroup("Controls", 16, 290, 185, 65)
  166. $btnStart = GUICtrlCreateButton("Start", 30, 314, 75, 25)
  167. GUICtrlSetOnEvent(-1, "btnStart")
  168. $btnStop = GUICtrlCreateButton("Stop", 30, 314, 75, 25)
  169. GUICtrlSetOnEvent(-1, "btnStop")
  170. GUICtrlSetState(-1, $GUI_HIDE)
  171. $btnHide = GUICtrlCreateButton("Hide", 110, 314, 75, 25)
  172. GUICtrlSetOnEvent(-1, "btnHide")
  173. GUICtrlSetState(-1, $GUI_DISABLE)
  174. GUICtrlCreateGroup("", -99, -99, 1, 1)
  175. $otherSettings = GUICtrlCreateGroup("Other Settings", 208, 290, 185, 65)
  176. $lblMaxTrophy = GUICtrlCreateLabel("Max Trophy :", 230, 310, 66, 17)
  177. GUICtrlSetLimit(-1, 4)
  178. $txtMaxTrophy = GUICtrlCreateInput("3000", 298, 307, 71, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
  179. GUICtrlSetTip(-1, "Bot will lose tropies if your trophy is greater than this.")
  180. $chkBackground = GUICtrlCreateCheckbox("Background Mode", 245, 330, 115, 17)
  181. GUICtrlSetOnEvent(-1, "chkBackground")
  182. GUICtrlSetState(-1, $GUI_CHECKED)
  183. GUICtrlCreateGroup("", -99, -99, 1, 1)
  184. $pageSearchSetting = GUICtrlCreateTabItem("Search Settings")
  185. $btnSearchMode = GUICtrlCreateButton("Search Mode", 24, 327, 368, 25)
  186. GUICtrlSetOnEvent(-1, "btnSearchMode")
  187. GUICtrlSetTip(-1, "Does not attack. Searches for base that meets conditions.")
  188. $Conditions = GUICtrlCreateGroup("Conditions", 16, 40, 193, 185)
  189. $chkMeetDE = GUICtrlCreateCheckbox("Meet Dark Elixir", 40, 88, 97, 17)
  190. $chkMeetTrophy = GUICtrlCreateCheckbox("Meet Trophy Count", 40, 112, 113, 17)
  191. $chkMeetGxE = GUICtrlCreateCheckbox("Meet Gold and Elixir", 40, 64, 113, 17)
  192. GUICtrlSetState(-1, $GUI_CHECKED)
  193. $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)
  194. GUICtrlCreateGroup("", -99, -99, 1, 1)
  195. $Resources = GUICtrlCreateGroup("Resources", 208, 40, 193, 185)
  196. $lblMinGold = GUICtrlCreateLabel("Minimum Gold: ", 216, 64, 76, 17)
  197. $lblMinElixir = GUICtrlCreateLabel("Minimum Elixir:", 216, 88, 72, 17)
  198. $lblMinDarkElixir = GUICtrlCreateLabel("Minimum Dark Elixir:", 216, 112, 98, 17)
  199. $lblMinTrophy = GUICtrlCreateLabel("Minimum Trophy Count:", 216, 136, 115, 17)
  200. $txtMinGold = GUICtrlCreateInput("80000", 330, 62, 61, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
  201. GUICtrlSetLimit(-1, 6)
  202. $txtMinElixir = GUICtrlCreateInput("80000", 330, 86, 61, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
  203. GUICtrlSetLimit(-1, 6)
  204. $txtMinDarkElixir = GUICtrlCreateInput("0", 330, 110, 61, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
  205. GUICtrlSetLimit(-1, 6)
  206. $txtMinTrophy = GUICtrlCreateInput("0", 330, 134, 61, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
  207. GUICtrlSetLimit(-1, 2)
  208. $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)
  209. GUICtrlCreateGroup("", -99, -99, 1, 1)
  210. $OtherSearchSettings = GUICtrlCreateGroup("Other Seach Settings", 15, 225, 385, 95)
  211. $chkAlertSearch = GUICtrlCreateCheckbox("Alert when Base Found", 30, 250, 132, 17)
  212. GUICtrlSetState(-1, $GUI_CHECKED)
  213. GUICtrlCreateGroup("", -99, -99, 1, 1)
  214. $pageAttackSettings = GUICtrlCreateTabItem("Attack Settings")
  215. $WeakBaseSettings = GUICtrlCreateGroup("Weak Base Settings", 15, 35, 130, 230)
  216. $lblMortar = GUICtrlCreateLabel("Max Mortar Lvl:", 20, 58, 77, 17)
  217. $cmbMortar = GUICtrlCreateCombo("", 100, 55, 35, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  218. GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8", "5")
  219. GUICtrlSetState(-1, $GUI_DISABLE)
  220. $lblWizardTower = GUICtrlCreateLabel("Wiz Tower Lvl:", 20, 83, 75, 17)
  221. $cmbWizTower = GUICtrlCreateCombo("", 100, 80, 35, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  222. GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8", "4")
  223. GUICtrlSetState(-1, $GUI_DISABLE)
  224. $lblCannon = GUICtrlCreateLabel("Cannon Lvl:", 20, 108, 61, 17)
  225. $lblArcher = GUICtrlCreateLabel("Archer Lvl:", 20, 133, 55, 17)
  226. $chkWithKing = GUICtrlCreateCheckbox("Attack their King", 20, 180, 112, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_RIGHTBUTTON))
  227. GUICtrlSetState(-1, $GUI_CHECKED)
  228. GUICtrlSetState(-1, $GUI_DISABLE)
  229. $chkWithQueen = GUICtrlCreateCheckbox("Attack their Queen", 20, 200, 112, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_RIGHTBUTTON))
  230. GUICtrlSetState(-1, $GUI_DISABLE)
  231. $cmbCannon = GUICtrlCreateCombo("", 100, 105, 35, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  232. GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13", "8")
  233. GUICtrlSetState(-1, $GUI_DISABLE)
  234. $cmbArcher = GUICtrlCreateCombo("", 100, 130, 35, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  235. GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13", "8")
  236. GUICtrlSetState(-1, $GUI_DISABLE)
  237. $lblWeakDescription = GUICtrlCreateLabel("Bot will attack bases that meet requirement.", 17, 225, 125, 32, $SS_CENTER)
  238. $lblxBow = GUICtrlCreateLabel("X-Bow Lvl:", 20, 158, 55, 17)
  239. $cmbxBow = GUICtrlCreateCombo("", 100, 155, 35, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  240. GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13", "0")
  241. GUICtrlSetState(-1, $GUI_DISABLE)
  242. GUICtrlCreateGroup("", -99, -99, 1, 1)
  243. $AttackMode = GUICtrlCreateGroup("Attack Mode", 150, 35, 250, 115)
  244. $radDeadBases = GUICtrlCreateRadio("Dead Bases - Meets condition, full collectors", 155, 55, 238, 17)
  245. $radWeakBases = GUICtrlCreateRadio("Weak Bases - Meets condition and able 50%", 155, 85, 228, 17)
  246. GUICtrlSetState(-1, $GUI_DISABLE)
  247. $radAllBases = GUICtrlCreateRadio("All Bases - Attack all that meets search.", 155, 115, 228, 17)
  248. GUICtrlSetState(-1, $GUI_CHECKED)
  249. GUICtrlCreateGroup("", -99, -99, 1, 1)
  250. $HeroesSettings = GUICtrlCreateGroup("Royals Settings", 150, 155, 250, 110)
  251. $chkKingAttackDeadBases = GUICtrlCreateCheckbox("Atk Dead Bases", 165, 195, 97, 17)
  252. $chkKingAttackWeakBases = GUICtrlCreateCheckbox("Atk Weak Bases", 165, 215, 97, 17)
  253. GUICtrlSetState(-1, $GUI_DISABLE)
  254. $chkKingAttackAllBases = GUICtrlCreateCheckbox("Atk All Bases", 165, 235, 97, 17)
  255. $lblKingSettings = GUICtrlCreateLabel("King Settings:", 165, 175, 69, 17)
  256. $lblQueenSettings = GUICtrlCreateLabel("Queen Settings:", 285, 175, 80, 17)
  257. $chkQueenAttackDeadBases = GUICtrlCreateCheckbox("Atk Dead Bases", 285, 195, 97, 17)
  258. $chkQueenAttackWeakBases = GUICtrlCreateCheckbox("Atk Weak Bases", 285, 215, 97, 17)
  259. GUICtrlSetState(-1, $GUI_DISABLE)
  260. $chkQueenAttackAllBases = GUICtrlCreateCheckbox("Atk All Bases", 285, 235, 97, 17)
  261. GUICtrlCreateGroup("", -99, -99, 1, 1)
  262. $deploySettings = GUICtrlCreateGroup("Deploy Settings", 15, 270, 385, 85)
  263. $chkAttackTH = GUICtrlCreateCheckbox("Attack Townhall (Outside)", 250, 320, 142, 17)
  264. GUICtrlSetState(-1, $GUI_DISABLE)
  265. $cmbDeploy = GUICtrlCreateCombo("", 30, 290, 360, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  266. 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")
  267. $cmbAlgorithm = GUICtrlCreateCombo("", 30, 320, 215, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  268. 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"
  269. GUICtrlCreateGroup("", -99, -99, 1, 1)
  270. $pageDonateSettings = GUICtrlCreateTabItem("Donate Settings")
  271. GUICtrlSetState(-1,$GUI_SHOW)
  272. GUICtrlSetState(-1, $GUI_CHECKED)
  273. $Donation = GUICtrlCreateGroup("", 11, 27, 385, 325)
  274. GUICtrlSetFont(-1, 8, 400, 0, "Arial")
  275. $Barbarians = GUICtrlCreateGroup("Barbarians", 16, 91, 120, 211)
  276. $Checkbox1 = GUICtrlCreateCheckbox("Donate to All", 26, 116, 97, 17)
  277. GUICtrlSetState(-1, $GUI_DISABLE)
  278. $txtDonateBarbarians = GUICtrlCreateEdit("", 21, 141, 110, 155, BitOR($ES_WANTRETURN, $WS_VSCROLL))
  279. GUICtrlSetData(-1, StringFormat("barbarians\r\nbarb\r\nany"))
  280. GUICtrlSetTip(-1, "Keywords for donating Barbarians")
  281. GUICtrlCreateGroup("", -99, -99, 1, 1)
  282. $Archers = GUICtrlCreateGroup("Archers", 144, 91, 120, 211)
  283. $Checkbox2 = GUICtrlCreateCheckbox("Donate to All", 151, 116, 97, 17)
  284. GUICtrlSetState(-1, $GUI_DISABLE)
  285. $txtDonateArchers = GUICtrlCreateEdit("", 149, 141, 110, 155, BitOR($ES_WANTRETURN, $WS_VSCROLL))
  286. GUICtrlSetData(-1, StringFormat("archers\r\narch\r\ndefense\r\ndefensive\r\nany"))
  287. GUICtrlSetTip(-1, "Keywords for donating Archers")
  288. GUICtrlCreateGroup("", -99, -99, 1, 1)
  289. $Giants = GUICtrlCreateGroup("Giants", 271, 91, 120, 211)
  290. $Checkbox3 = GUICtrlCreateCheckbox("Donate to All", 281, 116, 97, 17)
  291. GUICtrlSetState(-1, $GUI_DISABLE)
  292. $txtDonateGiants = GUICtrlCreateEdit("", 276, 141, 110, 155, BitOR($ES_WANTRETURN, $WS_VSCROLL))
  293. GUICtrlSetData(-1, StringFormat("giants\r\ngiant\r\nany"))
  294. GUICtrlSetState(-1, $GUI_DISABLE)
  295. GUICtrlSetTip(-1, "Keywords for donating Giants")
  296. GUICtrlCreateGroup("", -99, -99, 1, 1)
  297. $chkDonateGiants = GUICtrlCreateCheckbox("Donate Giants", 271, 302, 97, 17)
  298. GUICtrlSetState(-1, $GUI_DISABLE)
  299. $chkDonateArchers = GUICtrlCreateCheckbox("Donate Archers", 145, 302, 97, 17)
  300. GUICtrlSetState(-1, $GUI_DISABLE)
  301. $chkDonateBarbarians = GUICtrlCreateCheckbox("Donate Barbarians", 16, 302, 112, 17)
  302. GUICtrlSetState(-1, $GUI_DISABLE)
  303. $chkRequest = GUICtrlCreateCheckbox("Request for :", 26, 42, 82, 17)
  304. ;GUICtrlSetState(-1, $GUI_CHECKED)
  305. $txtRequest = GUICtrlCreateInput("any", 111, 42, 276, 22)
  306. ;GUICtrlSetState(-1, $GUI_DISABLE)
  307. GUICtrlSetTip(-1, "Request for input.")
  308. $btnLocateClanCastle = GUICtrlCreateButton("Locate Clan Castle Manually", 21, 322, 365, 25)
  309. $donatec = GUICtrlCreateCheckbox("donate Troops", 16, 72, 97, 17)
  310. GUICtrlSetState(-1, $GUI_CHECKED)
  311. $1htime = GUICtrlCreateCheckbox("Wait 1h before next req", 128, 72, 161, 17)
  312. GUICtrlSetState(-1, $GUI_DISABLE)
  313. ;--
  314. ;GUICtrlSetState(-1, $GUI_DISABLE)
  315. GUICtrlSetOnEvent(-1, "btnLocateClanClastle")
  316. GUICtrlCreateGroup("", -99, -99, 1, 1)
  317. $pageTroopSettings = GUICtrlCreateTabItem("Troop Settings")
  318. $Barracks = GUICtrlCreateGroup("Troops", 20, 40, 185, 215)
  319. $lblBarbarians = GUICtrlCreateLabel("Barbarians :", 30, 68, 60, 17)
  320. $lblArchers = GUICtrlCreateLabel("Archers :", 30, 93, 46, 17)
  321. $lblGoblins = GUICtrlCreateLabel("Goblins :", 30, 118, 45, 17)
  322. $txtBarbarians = GUICtrlCreateInput("30", 115, 65, 56, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
  323. GUICtrlSetState(-1, $GUI_DISABLE)
  324. $txtArchers = GUICtrlCreateInput("60", 115, 90, 56, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
  325. GUICtrlSetState(-1, $GUI_DISABLE)
  326. $txtGoblins = GUICtrlCreateInput("10", 115, 115, 56, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
  327. GUICtrlSetState(-1, $GUI_DISABLE)
  328. $lblPercentBarbarians = GUICtrlCreateLabel("%", 175, 68, 12, 17)
  329. $lblPercentArchers = GUICtrlCreateLabel("%", 175, 93, 12, 17)
  330. $lblPercentGoblins = GUICtrlCreateLabel("%", 175, 118, 12, 17)
  331. $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)
  332. $cmbTroopComp = GUICtrlCreateCombo("", 45, 145, 131, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  333. GUISetOnEvent(-1, "cmbTroopComp")
  334. 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"
  335. GUICtrlCreateGroup("", -99, -99, 1, 1)
  336. $OtherTroops = GUICtrlCreateGroup("Other Troops", 210, 40, 185, 85)
  337. $lblGiants = GUICtrlCreateLabel("Number of Giants:", 215, 68, 89, 17)
  338. $lblWallBreakers = GUICtrlCreateLabel("Number of Wall Breakers:", 215, 93, 125, 17)
  339. $txtNumGiants = GUICtrlCreateInput("4", 340, 65, 46, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
  340. GUICtrlSetState(-1, $GUI_DISABLE)
  341. $txtNumWallbreakers = GUICtrlCreateInput("4", 340, 90, 46, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
  342. GUICtrlSetState(-1, $GUI_DISABLE)
  343. GUICtrlCreateGroup("", -99, -99, 1, 1)
  344. $BarrackGroup = GUICtrlCreateGroup("Barracks", 210, 130, 185, 125)
  345. $lblBarrack1 = GUICtrlCreateLabel("Barrack 1:", 220, 153, 53, 17)
  346. $lblBarrack2 = GUICtrlCreateLabel("Barrack 2:", 220, 178, 53, 17)
  347. $lblBarrack3 = GUICtrlCreateLabel("Barrack 3:", 220, 203, 53, 17)
  348. $lblBarrack4 = GUICtrlCreateLabel("Barrack 4:", 220, 228, 53, 17)
  349. $cmbBarrack1 = GUICtrlCreateCombo("", 275, 150, 110, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  350. GUICtrlSetData(-1, "Barbarians|Archers|Giants", "Barbarians") ; "Barbarians|Archers|Giants|Goblins"
  351. $cmbBarrack2 = GUICtrlCreateCombo("", 275, 175, 110, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  352. GUICtrlSetData(-1, "Barbarians|Archers|Giants", "Barbarians") ; "Barbarians|Archers|Giants|Goblins"
  353. $cmbBarrack3 = GUICtrlCreateCombo("", 275, 200, 110, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  354. GUICtrlSetData(-1, "Barbarians|Archers|Giants", "Archers") ; "Barbarians|Archers|Giants|Goblins"
  355. $cmbBarrack4 = GUICtrlCreateCombo("", 275, 225, 110, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
  356. GUICtrlSetData(-1, "Barbarians|Archers|Giants", "Archers") ; "Barbarians|Archers|Giants|Goblins"
  357. GUICtrlCreateGroup("", -99, -99, 1, 1)
  358. $OtherBarrackSettings = GUICtrlCreateGroup("Other Settings", 20, 255, 375, 100)
  359. $btnLocateBarracks = GUICtrlCreateButton("Locate Barracks Manually", 30, 320, 355, 25)
  360. GUICtrlSetOnEvent(-1, "btnLocateBarracks")
  361. $btnLocateCollectors = GUICtrlCreateButton("Locate Collectors Manually", 30, 280, 355, 25)
  362. GUICtrlSetOnEvent(-1, "btnLocateCollectors")
  363. GUICtrlCreateGroup("", -99, -99, 1, 1)
  364. GUICtrlCreateTabItem("")
  365. $statLog = _GUICtrlStatusBar_Create($frmBot)
  366. _GUICtrlStatusBar_SetSimple($statLog)
  367. _GUICtrlStatusBar_SetText($statLog, "Status : Idle")
  368. GUISetState(@SW_SHOW)
  369. #EndRegion ### END Koda GUI section ###
  370. ;---------------------------------------------------
  371. If FileExists($config) Then
  372.     readConfig()
  373.     applyConfig()
  374. EndIf
  375.  
  376. GUIRegisterMsg($WM_COMMAND, "GUIControl")
  377. GUIRegisterMsg($WM_SYSCOMMAND, "GUIControl")
  378. ;---------------------------------------------------
  379. #Region ### Button Section ###
  380. Func GUIControl($hWind, $iMsg, $wParam, $lParam)
  381.     Local $nNotifyCode = BitShift($wParam, 16)
  382.     Local $nID = BitAND($wParam, 0x0000FFFF)
  383.     Local $hCtrl = $lParam
  384.     #forceref $hWind, $iMsg, $wParam, $lParam
  385.     Switch $iMsg
  386.         Case 273
  387.             Switch $nID
  388.                 Case $GUI_EVENT_CLOSE
  389.                     If WinExists("BlueStacks App Player") Then
  390.                         EnableBS($HWnD, $SC_MINIMIZE)
  391.                         EnableBS($HWnD, $SC_CLOSE)
  392.                         EnableBS($HWnD, $SC_MOVE)
  393.                     EndIf
  394.                     _GDIPlus_Shutdown()
  395.                     SaveConfig()
  396.                     Exit
  397.                 Case $btnStop
  398.                     If $RunState Then btnStop()
  399.                 Case $btnHide
  400.                     If $RunState Then btnHide()
  401.                 Case $cmbTroopComp
  402.                     cmbTroopComp()
  403.             EndSwitch
  404.         Case 274
  405.             Switch $wParam
  406.                 Case 0xf060
  407.                     If WinExists("BlueStacks App Player") Then
  408.                         EnableBS($HWnD, $SC_MINIMIZE)
  409.                         EnableBS($HWnD, $SC_CLOSE)
  410.                         EnableBS($HWnD, $SC_MOVE)
  411.                     EndIf
  412.                     _GDIPlus_Shutdown()
  413.                     SaveConfig()
  414.                     Exit
  415.             EndSwitch
  416.     EndSwitch
  417.     Return $GUI_RUNDEFMSG
  418. EndFunc   ;==>GUIControl
  419.  
  420. While 1
  421.     Sleep(10000)
  422. WEnd
  423.  
  424. Func btnStart()
  425.     _GDIPlus_Startup()
  426.     CreateLogFile()
  427.  
  428.     SaveConfig()
  429.     readConfig()
  430.     applyConfig()
  431.  
  432.     _GUICtrlEdit_SetText($txtLog, "")
  433.  
  434.     If WinExists("BlueStacks App Player") Then
  435.         DisableBS($HWnD, $SC_MINIMIZE)
  436.         DisableBS($HWnD, $SC_CLOSE)
  437.         DisableBS($HWnD, $SC_MOVE)
  438.         If IsArray(ControlGetPos("BlueStacks App Player", "_ctl.Window", "[CLASS:BlueStacksApp; INSTANCE:1]")) Then
  439.             Local $BSsize = [ControlGetPos("BlueStacks App Player", "_ctl.Window", "[CLASS:BlueStacksApp; INSTANCE:1]")[2], ControlGetPos("BlueStacks App Player", "_ctl.Window", "[CLASS:BlueStacksApp; INSTANCE:1]")[3]]
  440.             If $BSsize[0] <> 860 Or $BSsize[1] <> 720 Then
  441.                 SetLog("BlueStacks is not set to 860x720!")
  442.                 SetLog("Download the '860x720.reg' file and run it, restart BlueStacks")
  443.                 SetLog("Download the '860x720.reg' here: http://www.goo.gl/YgQ5II")
  444.             Else
  445.                 WinActivate("BlueStacks App Player")
  446.                 ;WinSetOnTop("BlueStacks App Player", "", 1)
  447.  
  448.                 SetLog("~~~~Welcome to " & @ScriptName & "!~~~~")
  449.                 SetLog($Compiled & " running on " & @OSArch & " OS")
  450.                 SetLog("Bot is starting...")
  451.  
  452.                 $RunState = True
  453.                 GUICtrlSetState($btnLocateBarracks, $GUI_DISABLE)
  454.                 GUICtrlSetState($btnSearchMode, $GUI_DISABLE)
  455.                 GUICtrlSetState($cmbTroopComp, $GUI_DISABLE)
  456.                 GUICtrlSetState($chkBackground, $GUI_DISABLE)
  457.                 GUICtrlSetState($btnLocateCollectors, $GUI_DISABLE)
  458.  
  459.                 GUICtrlSetState($btnStart, $GUI_HIDE)
  460.                 GUICtrlSetState($btnStop, $GUI_SHOW)
  461.                 runBot()
  462.             EndIf
  463.         Else
  464.             SetLog("Not in Game!")
  465.         EndIf
  466.     Else
  467.         SetLog("BlueStacks was not found!")
  468.     EndIf
  469. EndFunc   ;==>btnStart
  470.  
  471. Func btnStop()
  472.     If $RunState Then
  473.         $RunState = False
  474.         EnableBS($HWnD, $SC_MINIMIZE)
  475.         EnableBS($HWnD, $SC_CLOSE)
  476.         EnableBS($HWnD, $SC_MOVE)
  477.         GUICtrlSetState($btnLocateBarracks, $GUI_ENABLE)
  478.         GUICtrlSetState($btnSearchMode, $GUI_ENABLE)
  479.         GUICtrlSetState($cmbTroopComp, $GUI_ENABLE)
  480.         GUICtrlSetState($btnLocateCollectors, $GUI_ENABLE)
  481.         GUICtrlSetState($chkBackground, $GUI_ENABLE)
  482.  
  483.         GUICtrlSetState($btnStart, $GUI_SHOW)
  484.         GUICtrlSetState($btnStop, $GUI_HIDE)
  485.  
  486.         FileClose($hLogFileHandle)
  487.         SetLog("Bot has stopped")
  488.     EndIf
  489. EndFunc   ;==>btnStop
  490.  
  491. Func btnLocateBarracks()
  492.     $RunState = True
  493.     While 1
  494.         ZoomOut()
  495.         LocateBarrack()
  496.         ExitLoop
  497.     WEnd
  498.     $RunState = False
  499. EndFunc   ;==>btnLocateBarracks
  500.  
  501. Func btnLocateClanClastle()
  502.     $RunState = True
  503.     While 1
  504.         ZoomOut()
  505.         LocateClanClastle()
  506.         ExitLoop
  507.     WEnd
  508.     $RunState = False
  509. EndFunc   ;==>btnLocateClanClastle
  510.  
  511. Func btnSearchMode()
  512.     While 1
  513.         GUICtrlSetState($btnStart, $GUI_HIDE)
  514.         GUICtrlSetState($btnStop, $GUI_SHOW)
  515.  
  516.         GUICtrlSetState($btnLocateBarracks, $GUI_DISABLE)
  517.         GUICtrlSetState($btnSearchMode, $GUI_DISABLE)
  518.         GUICtrlSetState($cmbTroopComp, $GUI_DISABLE)
  519.         GUICtrlSetState($chkBackground, $GUI_DISABLE)
  520.         GUICtrlSetState($btnLocateCollectors, $GUI_DISABLE)
  521.  
  522.         $RunState = True
  523.         VillageSearch()
  524.         $RunState = False
  525.  
  526.         GUICtrlSetState($btnStart, $GUI_SHOW)
  527.         GUICtrlSetState($btnStop, $GUI_HIDE)
  528.  
  529.         GUICtrlSetState($btnLocateBarracks, $GUI_ENABLE)
  530.         GUICtrlSetState($btnSearchMode, $GUI_ENABLE)
  531.         GUICtrlSetState($cmbTroopComp, $GUI_ENABLE)
  532.         GUICtrlSetState($chkBackground, $GUI_ENABLE)
  533.         GUICtrlSetState($btnLocateCollectors, $GUI_ENABLE)
  534.         ExitLoop
  535.     WEnd
  536. EndFunc   ;==>btnSearchMode
  537.  
  538. Func btnHide()
  539.     If $Hide = False Then
  540.         GUICtrlSetData($btnHide, "Show")
  541.         $botPos[0] = WinGetPos("BlueStacks App Player")[0]
  542.         $botPos[1] = WinGetPos("BlueStacks App Player")[1]
  543.         WinMove("BlueStacks App Player", "", -32000, -32000)
  544.         $Hide = True
  545.     Else
  546.         GUICtrlSetData($btnHide, "Hide")
  547.  
  548.         If $botPos[0] = -32000 Then
  549.             WinMove("BlueStacks App Player", "", 0, 0)
  550.         Else
  551.             WinMove("BlueStacks App Player", "", $botPos[0], $botPos[1])
  552.         EndIf
  553.         $Hide = False
  554.     EndIf
  555. EndFunc   ;==>btnHide
  556.  
  557. Func cmbTroopComp()
  558.     If _GUICtrlComboBox_GetCurSel($cmbTroopComp) <> $icmbTroopComp Then
  559.         $icmbTroopComp = _GUICtrlComboBox_GetCurSel($cmbTroopComp)
  560.         SetComboTroopComp()
  561.     EndIf
  562. EndFunc   ;==>cmbTroopComp
  563.  
  564. Func SetComboTroopComp()
  565.     Switch _GUICtrlComboBox_GetCurSel($cmbTroopComp)
  566.         Case 0
  567.             GUICtrlSetState($cmbBarrack1, $GUI_DISABLE)
  568.             GUICtrlSetState($cmbBarrack2, $GUI_DISABLE)
  569.             GUICtrlSetState($cmbBarrack3, $GUI_DISABLE)
  570.             GUICtrlSetState($cmbBarrack4, $GUI_DISABLE)
  571.  
  572.             GUICtrlSetData($txtBarbarians, "50")
  573.             GUICtrlSetData($txtArchers, "50")
  574.             GUICtrlSetData($txtGoblins, "0")
  575.  
  576.             GUICtrlSetData($txtNumGiants, "0")
  577.             GUICtrlSetData($txtNumWallbreakers, "0")
  578.         Case 1
  579.             GUICtrlSetState($cmbBarrack1, $GUI_ENABLE)
  580.             GUICtrlSetState($cmbBarrack2, $GUI_ENABLE)
  581.             GUICtrlSetState($cmbBarrack3, $GUI_ENABLE)
  582.             GUICtrlSetState($cmbBarrack4, $GUI_ENABLE)
  583.     EndSwitch
  584. EndFunc   ;==>SetComboTroopComp
  585.  
  586. Func chkBackground()
  587.     If GUICtrlRead($chkBackground) = $GUI_CHECKED Then
  588.         $ichkBackground = 1
  589.         GUICtrlSetState($btnHide, $GUI_ENABLE)
  590.     Else
  591.         $ichkBackground = 0
  592.         GUICtrlSetState($btnHide, $GUI_DISABLE)
  593.     EndIf
  594. EndFunc   ;==>chkBackground
  595.  
  596. Func btnLocateCollectors()
  597.     $RunState = True
  598.     While 1
  599.         ZoomOut()
  600.         LocateCollectors()
  601.         ExitLoop
  602.     WEnd
  603.     $RunState = False
  604. EndFunc   ;==>btnLocateCollectors
  605.  
  606. #EndRegion ### Button Section ###
  607. ;---------------------------------------------------
  608. #Region ### General Functions ###
  609. Func runBot() ;Bot that runs everything in order
  610.     While 1
  611.         $Restart = False
  612.         If _Sleep(1000) Then ExitLoop
  613.         checkMainScreen()
  614.         If _Sleep(1000) Then ExitLoop
  615.         ZoomOut()
  616.         If _Sleep(1000) Then ExitLoop
  617.         Train()
  618.         If _Sleep(1000) Then ExitLoop
  619.         DonateCC()
  620.         If _Sleep(1000) Then ExitLoop
  621.         RequestCC()
  622.         If _Sleep(1000) Then ExitLoop
  623.         Collect()
  624.         If _Sleep(1000) Then ExitLoop
  625.         Idle()
  626.         If _Sleep(1000) Then ExitLoop
  627.         AttackMain()
  628.         If _Sleep(1000) Then ExitLoop
  629.     WEnd
  630. EndFunc   ;==>runBot
  631.  
  632. Func Idle() ;Sequence that runs until Full Army
  633.     Local $TimeIdle = 0 ;In Seconds
  634.     While 1
  635.         If $fullArmy = False Then
  636.             SetLog("~~~Waiting for full army~~~")
  637.             While $fullArmy = False
  638.                 Local $hTimer = TimerInit()
  639.                 If _Sleep(1000) Then ExitLoop
  640.                 checkMainScreen()
  641.                 If _Sleep(1000) Then ExitLoop
  642.                 ZoomOut()
  643.                 If _Sleep(30000) Then ExitLoop (2)
  644.                 If $iCollectCounter > $COLLECTATCOUNT Then ; This is prevent from collecting all the time which isn't needed anyway
  645.                     Collect()
  646.                     If _Sleep(1000) Or $RunState = False Then ExitLoop (2)
  647.                     $iCollectCounter = 0
  648.                 EndIf
  649.                 $iCollectCounter = $iCollectCounter + 1
  650.                 Train()
  651.                 If $fullArmy Then ExitLoop (2)
  652.                 If _Sleep(1000) Then ExitLoop (2)
  653.                 DropTrophy()
  654.                 $TimeIdle += Round(TimerDiff($hTimer) / 1000, 2) ;In Seconds
  655.                 SetLog("Time Idle: " & Floor(Floor($TimeIdle / 60) / 60) & " hours " & Floor(Mod(Floor($TimeIdle / 60), 60)) & " minutes " & Floor(Mod($TimeIdle, 60)) & " seconds")
  656.             WEnd
  657.         EndIf
  658.         ExitLoop
  659.     WEnd
  660. EndFunc   ;==>Idle
  661.  
  662. Func checkMainScreen() ;Checks if in main screen
  663.     SetLog("Trying to locate Main Screen")
  664.     _CaptureRegion()
  665.     While _ColorCheckVariation(_PixelGetColor_GetPixel(284, 28), Hex(0x41B1CD, 6), 20) = False
  666.         $HWnD = WinGetHandle("BlueStacks App Player")
  667.  
  668.         If _Sleep(1000) Then Return
  669.         If checkObstacles() = False Then
  670.             Click(126, 700, 1, 500)
  671.             Local $RunApp = StringReplace(_WinAPI_GetProcessFileName(WinGetProcess("BlueStacks App Player")), "Frontend", "RunApp")
  672.             Run($RunApp & " Android com.supercell.clashofclans com.supercell.clashofclans.GameApp")
  673.         EndIf
  674.         waitMainScreen()
  675.     WEnd
  676.     SetLog("Main Screen Located")
  677. EndFunc   ;==>checkMainScreen
  678.  
  679. Func checkObstacles() ;Checks if something is in the way for mainscreen
  680.     $Message = _PixelSearch(457, 300, 458, 330, Hex(0x33B5E5, 6), 10) ;Check for out of sync or inactivity
  681.     If IsArray($Message) Then
  682.         Click(416, 399);Check for out of sync or inactivity
  683.         Return True
  684.     EndIf
  685.  
  686.     _CaptureRegion()
  687.     If _ColorCheckVariation(_PixelGetColor_GetPixel(235, 209), Hex(0x9E3826, 6), 20) Then
  688.         Click(429, 493);See if village was attacked, clicks Okay
  689.         Return True
  690.     EndIf
  691.  
  692.     If _ColorCheckVariation(_PixelGetColor_GetPixel(284, 28), Hex(0x215B69, 6), 20) Then
  693.         Click(1, 1) ;Click away If things are open
  694.         Return True
  695.     EndIf
  696.  
  697.     If _ColorCheckVariation(_PixelGetColor_GetPixel(819, 55), Hex(0xD80400, 6), 20) Then
  698.         Click(819, 55) ;Clicks X
  699.         Return True
  700.     EndIf
  701.  
  702.     If _ColorCheckVariation(_PixelGetColor_GetPixel(822, 48), Hex(0xD80408, 6), 20) Or _ColorCheckVariation(_PixelGetColor_GetPixel(830, 59), Hex(0xD80408, 6), 20) Then
  703.         Click(822, 48) ;Clicks X
  704.         Return True
  705.     EndIf
  706.  
  707.     If _ColorCheckVariation(_PixelGetColor_GetPixel(331, 330), Hex(0xF0A03B, 6), 20) Then
  708.         Click(331, 330) ;Clicks chat thing
  709.         Return True
  710.     EndIf
  711.  
  712.     If _ColorCheckVariation(_PixelGetColor_GetPixel(429, 519), Hex(0xB8E35F, 6), 20) Then
  713.         Click(429, 519) ;If in that victory or defeat scene
  714.         Return True
  715.     EndIf
  716.  
  717.     If _ColorCheckVariation(_PixelGetColor_GetPixel(71, 530), Hex(0xC00000, 6), 20) Then
  718.         ReturnHome(False, False) ;If End battle is available
  719.         Return True
  720.     EndIf
  721.  
  722.     Return False
  723. EndFunc   ;==>checkObstacles
  724.  
  725. Func waitMainScreen() ;Waits for main screen to popup
  726.     SetLog("Waiting for Main Screen")
  727.     For $i = 0 To 150 ;150*2000 = 5 Minutes
  728.         _CaptureRegion()
  729.         If _ColorCheckVariation(_PixelGetColor_GetPixel(284, 28), Hex(0x41B1CD, 6), 20) = False Then
  730.             If _Sleep(2000) Then Return
  731.         Else
  732.             Return
  733.         EndIf
  734.     Next
  735.  
  736.     SetLog("Unable to load Clash Of Clans, Restarting...")
  737.     Local $RestartApp = StringReplace(_WinAPI_GetProcessFileName(WinGetProcess("BlueStacks App Player")), "Frontend", "Restart")
  738.     Run($RestartApp & " Android")
  739.     If _Sleep(10000) Then Return
  740.  
  741.     Do
  742.         If _Sleep(5000) Then Return
  743.     Until ControlGetHandle("BlueStacks App Player", "", "BlueStacksApp1") <> 0
  744. EndFunc   ;==>waitMainScreen
  745.  
  746. Func checkNextButton() ;Checks for Out of Sync or Connection Lost errors
  747.     $Message = _PixelSearch(458, 300, 458, 330, Hex(0x33B5E5, 6), 10) ;Check for out of sync or inactivity
  748.     If IsArray($Message) = False Then
  749.         Return False ;Button available
  750.     Else
  751.         Return True ;Out of sync or inactivity error.
  752.     EndIf
  753. EndFunc   ;==>checkNextButton
  754.  
  755. Func ZoomOut() ;Zooms out
  756.     Local $i = 0
  757.     While 1
  758.         If _Sleep(500) Then Return
  759.         _CaptureRegion(0, 0, 860, 2)
  760.         If _PixelGetColor_GetPixel(1, 1) = Hex(0x000000, 6) And _PixelGetColor_GetPixel(850, 1) = Hex(0x000000, 6) Then
  761.             ExitLoop
  762.         Else
  763.             ControlSend("BlueStacks App Player", "", "", "{DOWN}", 0)
  764.             $i += 1
  765.             If $i = 20 Then
  766.                 ExitLoop
  767.             EndIf
  768.         EndIf
  769.     WEnd
  770.     SetLog("Zoomed Out")
  771. EndFunc   ;==>ZoomOut
  772. #EndRegion ### General Functions ###
  773. ;---------------------------------------------------
  774. #Region ### Attack Functions ###
  775. Func AttackMain() ;Main control for attack functions
  776.     While 1
  777.         PrepareSearch()
  778.         If _Sleep(1000) Then ExitLoop
  779.         VillageSearch()
  780.         If _Sleep(1000) Or $Restart = True Then ExitLoop
  781.         PrepareAttack()
  782.         If _Sleep(1000) Then ExitLoop
  783.         Attack()
  784.         If _Sleep(1000) Then ExitLoop
  785.         ReturnHome()
  786.         If _Sleep(1000) Then ExitLoop
  787.         ExitLoop
  788.     WEnd
  789. EndFunc   ;==>AttackMain
  790.  
  791. Func ReturnHome($TakeSS = True, $GoldChangeCheck = True) ;Return main screen
  792.     While 1
  793.         If $GoldChangeCheck = True Then
  794.             If $checkKPower Or $checkQPower Then
  795.                 If _Sleep(50000 - $delayActivateKQ) Then ExitLoop
  796.             Else
  797.                 If _Sleep(50000) Then ExitLoop
  798.             EndIf
  799.             While GoldElixirChange()
  800.                 If _Sleep(1000) Then ExitLoop (2)
  801.             WEnd
  802.         EndIf
  803.  
  804.         $checkKPower = False
  805.         $checkQPower = False
  806.         SetLog("Returning Home")
  807.         If $RunState = False Then ExitLoop
  808.         Click(62, 519) ;Click Surrender
  809.         If _Sleep(500) Then ExitLoop
  810.         Click(512, 394) ;Click Confirm
  811.         If _Sleep(4000) Then ExitLoop
  812.  
  813.         If $TakeSS = True Then
  814.             Local $Date = @MDAY & "." & @MON & "." & @YEAR
  815.             Local $Time = @HOUR & "." & @MIN
  816.             _CaptureRegion()
  817.             _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Loots\" & $Date & " at " & $Time & ".jpg")
  818.         EndIf
  819.  
  820.         Click(428, 544) ;Click Return Home Button
  821.  
  822.         Local $counter = 0
  823.         While 1
  824.             If _Sleep(2000) Then ExitLoop (2)
  825.             _CaptureRegion()
  826.             If _ColorCheckVariation(_PixelGetColor_GetPixel(284, 28), Hex(0x41B1CD, 6), 20) Then
  827.                 _GUICtrlEdit_SetText($txtLog, "")
  828.                 ExitLoop (2)
  829.             EndIf
  830.  
  831.             $counter += 1
  832.  
  833.             If $counter >= 50 Then
  834.                 SetLog("Cannot return home.")
  835.                 checkMainScreen()
  836.                 ExitLoop (2)
  837.             EndIf
  838.         WEnd
  839.         ExitLoop
  840.     WEnd
  841. EndFunc   ;==>ReturnHome
  842.  
  843. Func GoldElixirChange() ;Checks 30 seconds if gold changes
  844.     Local $Gold1, $Gold2
  845.     While 1
  846.         $Gold1 = getGold(51, 66)
  847.         $Elixir1 = getElixir(51, 66 + 29)
  848.         Local $iBegin = TimerInit()
  849.         While TimerDiff($iBegin) < 30000
  850.             If $RunState = False Then ExitLoop
  851.             Sleep(100)
  852.             ;If Not _ColorCheckVariation(_PixelGetColor_GetPixel(71, 530), Hex(0xC00000, 6), 50) Then
  853.             ;   SetLog("End Battle button not dected")
  854.             ;EndIf
  855.         WEnd
  856.         $Gold2 = getGold(51, 66)
  857.         $Elixir2 = getElixir(51, 66 + 29)
  858.         If $Gold1 = $Gold2 Or $Elixir1 = $Elixir2 Or $Gold2 = "" Or $Elixir2 = "" Then
  859.             Return False
  860.         Else
  861.             SetLog("Gold & Elixir change detected, waiting...")
  862.             Return True
  863.         EndIf
  864.         ExitLoop
  865.     WEnd
  866. EndFunc   ;==>GoldElixirChange
  867.  
  868. Func Attack() ;Selects which algorithm
  869.     While 1
  870.         SetLog("======Beginning Attack======")
  871.         Switch $icmbAlgorithm
  872.             Case 0 ;Barbarians + Archers
  873.                 atkAlgorithmBarch()
  874.             Case 1 ;Use All Troops
  875.                 SetLog("all troops beta")
  876.                 atkAlgorithmAllTroops()
  877. ;               SetLog("Not Available yet, using Barch instead...")
  878. ;               If _Sleep(2000) Then ExitLoop
  879. ;               atkAlgorithmBarch()
  880.         EndSwitch
  881.         ExitLoop
  882.     WEnd
  883. EndFunc   ;==>Attack
  884.  
  885. Func atkAlgorithmBarch() ;Attack Algorithm for Barch
  886.     While 1
  887.         Local $Barb = -1, $Arch = -1, $CC = -1
  888.         Global $King = -1, $Queen = -1
  889.         For $i = 0 To 6
  890.             If $atkTroops[$i][0] = "Barbarian" Then
  891.                 $Barb = $i
  892.             ElseIf $atkTroops[$i][0] = "Archer" Then
  893.                 $Arch = $i
  894.             ElseIf $atkTroops[$i][0] = "Clan Castle" Then
  895.                 $CC = $i
  896.             ElseIf $atkTroops[$i][0] = "King" Then
  897.                 $King = $i
  898.             ElseIf $atkTroops[$i][0] = "Queen" Then
  899.                 $Queen = $i
  900.             EndIf
  901.         Next
  902.  
  903.         If _Sleep(500) Then ExitLoop
  904.         Switch $deploySettings
  905.             Case 0 ;Two sides ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  906.                 SetLog("~Attacking in two sides...")
  907.                 If _Sleep(1000) Then ExitLoop
  908.                 Local $numBarbPerSpot = Ceiling((($atkTroops[$Barb][1] / 2) / 5) / 2)
  909.                 Local $numArchPerSpot = Ceiling((($atkTroops[$Arch][1] / 2) / 5) / 2)
  910.  
  911.                 SetLog("Dropping first wave of Barbarians")
  912.                 For $i = 0 To 4 ;Drop first round of Barbarians
  913.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  914.                     If _Sleep(100) Then ExitLoop (2)
  915.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  916.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  917.                 Next
  918.  
  919.                 If _Sleep(1000) Then ExitLoop
  920.  
  921.                 SetLog("Dropping first wave of Archers")
  922.                 For $i = 0 To 4 ;Drop first round of Archers
  923.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  924.                     If _Sleep(100) Then ExitLoop (2)
  925.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  926.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  927.                 Next
  928.  
  929.                 If _Sleep(2000) Then ExitLoop ;-------------------------------------------
  930.  
  931.                 SetLog("Dropping second wave of Barbarians")
  932.                 For $i = 0 To 4 ;Drop second round of Barbarians
  933.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  934.                     If _Sleep(100) Then ExitLoop (2)
  935.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  936.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  937.                 Next
  938.  
  939.                 If _Sleep(1000) Then ExitLoop
  940.  
  941.                 SetLog("Dropping second wave of Archers")
  942.                 For $i = 0 To 4 ;Drop second round of Archers
  943.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  944.                     If _Sleep(100) Then ExitLoop (2)
  945.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  946.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  947.                 Next
  948.  
  949.                 dropHeroes($TopLeft[3][0], $TopLeft[3][1], $King, $Queen)
  950.                 If _Sleep(1000) Then ExitLoop
  951.                 If $CC <> -1 Then dropCC($TopLeft[3][0], $TopLeft[3][1], $CC)
  952.             Case 1 ;Three sides ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  953.                 SetLog("~Attacking in three sides...")
  954.                 If _Sleep(1000) Then ExitLoop
  955.                 Local $numBarbPerSpot = Ceiling((($atkTroops[$Barb][1] / 3) / 5) / 2)
  956.                 Local $numArchPerSpot = Ceiling((($atkTroops[$Arch][1] / 3) / 5) / 2)
  957.  
  958.                 SetLog("Dropping first wave of Barbarians")
  959.                 For $i = 0 To 4 ;Drop first round of Barbarians
  960.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  961.                     If _Sleep(100) Then ExitLoop (2)
  962.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  963.                     Click($TopRight[$i][0], $TopRight[$i][1], $numBarbPerSpot, 1)
  964.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  965.                 Next
  966.  
  967.                 If _Sleep(1000) Then ExitLoop
  968.  
  969.                 SetLog("Dropping first wave of Archers")
  970.                 For $i = 0 To 4 ;Drop first round of Archers
  971.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  972.                     If _Sleep(100) Then ExitLoop (2)
  973.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  974.                     Click($TopRight[$i][0], $TopRight[$i][1], $numArchPerSpot, 1)
  975.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  976.                 Next
  977.  
  978.                 If _Sleep(2000) Then ExitLoop ;-------------------------------------------
  979.  
  980.                 SetLog("Dropping second wave of Barbarians")
  981.                 For $i = 0 To 4 ;Drop second round of Barbarians
  982.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  983.                     If _Sleep(100) Then ExitLoop (2)
  984.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  985.                     Click($TopRight[$i][0], $TopRight[$i][1], $numBarbPerSpot, 1)
  986.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  987.                 Next
  988.  
  989.                 If _Sleep(1000) Then ExitLoop
  990.  
  991.                 SetLog("Dropping second wave of Archers")
  992.                 For $i = 0 To 4 ;Drop second round of Archers
  993.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  994.                     If _Sleep(100) Then ExitLoop (2)
  995.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  996.                     Click($TopRight[$i][0], $TopRight[$i][1], $numArchPerSpot, 1)
  997.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  998.                 Next
  999.  
  1000.                 dropHeroes($TopRight[3][0], $TopRight[3][1], $King, $Queen)
  1001.                 If _Sleep(1000) Then ExitLoop
  1002.                 If $CC <> -1 Then dropCC($TopRight[3][0], $TopRight[3][1], $CC)
  1003.             Case 2 ;Four sides ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1004.                 SetLog("~Attacking in all sides...")
  1005.                 If _Sleep(1000) Then ExitLoop
  1006.                 Local $numBarbPerSpot = Ceiling((($atkTroops[$Barb][1] / 4) / 5) / 2)
  1007.                 Local $numArchPerSpot = Ceiling((($atkTroops[$Arch][1] / 4) / 5) / 2)
  1008.  
  1009.                 SetLog("Dropping first wave of Barbarians")
  1010.                 For $i = 0 To 4 ;Drop first round of Barbarians
  1011.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  1012.                     If _Sleep(100) Then ExitLoop (2)
  1013.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  1014.                     Click($TopRight[$i][0], $TopRight[$i][1], $numBarbPerSpot, 1)
  1015.                     Click($BottomLeft[$i][0], $BottomLeft[$i][1], $numBarbPerSpot, 1)
  1016.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  1017.                 Next
  1018.  
  1019.                 If _Sleep(1000) Then ExitLoop
  1020.  
  1021.                 SetLog("Dropping first wave of Archers")
  1022.                 For $i = 0 To 4 ;Drop first round of Archers
  1023.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  1024.                     If _Sleep(100) Then ExitLoop (2)
  1025.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  1026.                     Click($TopRight[$i][0], $TopRight[$i][1], $numArchPerSpot, 1)
  1027.                     Click($BottomLeft[$i][0], $BottomLeft[$i][1], $numArchPerSpot, 1)
  1028.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  1029.                 Next
  1030.  
  1031.                 If _Sleep(2000) Then ExitLoop ;-------------------------------------------
  1032.  
  1033.                 SetLog("Dropping second wave of Barbarians")
  1034.                 For $i = 0 To 4 ;Drop second round of Barbarians
  1035.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  1036.                     If _Sleep(100) Then ExitLoop (2)
  1037.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  1038.                     Click($TopRight[$i][0], $TopRight[$i][1], $numBarbPerSpot, 1)
  1039.                     Click($BottomLeft[$i][0], $BottomLeft[$i][1], $numBarbPerSpot, 1)
  1040.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  1041.                 Next
  1042.  
  1043.                 If _Sleep(1000) Then ExitLoop
  1044.  
  1045.                 SetLog("Dropping second wave of Archers")
  1046.                 For $i = 0 To 4 ;Drop second round of Archers
  1047.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  1048.                     If _Sleep(100) Then ExitLoop (2)
  1049.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  1050.                     Click($TopRight[$i][0], $TopRight[$i][1], $numArchPerSpot, 1)
  1051.                     Click($BottomLeft[$i][0], $BottomLeft[$i][1], $numArchPerSpot, 1)
  1052.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  1053.                 Next
  1054.  
  1055.                 dropHeroes($BottomLeft[3][0], $BottomLeft[3][1], $King, $Queen)
  1056.                 If _Sleep(1000) Then ExitLoop
  1057.                 If $CC <> -1 Then dropCC($BottomLeft[3][0], $BottomLeft[3][1], $CC)
  1058.         EndSwitch
  1059.  
  1060.         If _Sleep(100) Then ExitLoop
  1061.         SetLog("Dropping left over troops")
  1062.         $atkTroops[$Barb][1] = Number(getNormal(40 + (72 * $Barb), 565))
  1063.         $atkTroops[$Arch][1] = Number(getNormal(40 + (72 * $Arch), 565))
  1064.  
  1065.         While $atkTroops[$Barb][1] <> 0
  1066.             Click(68 + (72 * $Barb), 595)
  1067.             Click($TopLeft[3][0], $TopLeft[3][1], $atkTroops[$Barb][1], 1)
  1068.  
  1069.             $atkTroops[$Barb][1] = Number(getNormal(40 + (72 * $Barb), 565))
  1070.         WEnd
  1071.  
  1072.         If _Sleep(1000) Then ExitLoop
  1073.  
  1074.         While $atkTroops[$Arch][1] <> 0
  1075.             Click(68 + (72 * $Arch), 595)
  1076.             Click($TopLeft[3][0], $TopLeft[3][1], $atkTroops[$Arch][1], 1)
  1077.  
  1078.             $atkTroops[$Arch][1] = Number(getNormal(40 + (72 * $Arch), 565))
  1079.         WEnd
  1080.  
  1081.         If _Sleep(100) Then ExitLoop
  1082.  
  1083.         ;Activate KQ's power
  1084.         If $checkKPower <> -1 Or $checkQPower <> -1 Then
  1085.             SetLog("Waiting " & $delayActivateKQ / 1000 & " seconds before activating King/Queen")
  1086.             _Sleep($delayActivateKQ)
  1087.             If $checkKPower <> -1 Then
  1088.                 SetLog("Activate King's power")
  1089.                 Click(68 + (72 * $checkKPower), 595)
  1090.             EndIf
  1091.             If $checkQPower <> -1 Then
  1092.                 SetLog("Activate Queen's power")
  1093.                 Click(68 + (72 * $checkQPower), 595)
  1094.             EndIf
  1095.         EndIf
  1096.  
  1097.         SetLog("~Finished Attacking, waiting to finish")
  1098.         ExitLoop
  1099.     WEnd
  1100. EndFunc   ;==>atkAlgorithmBarch
  1101.  
  1102. Func atkAlgorithmAllTroops()
  1103.     While 1
  1104.         Local $Giant = -1, $Barb = -1, $Arch = -1, $CC = -1
  1105.         Global $King = -1, $Queen = -1
  1106.         For $i = 0 To 6
  1107.             If $atkTroops[$i][0] = "Barbarian" Then
  1108.                 $Barb = $i
  1109.             ElseIf $atkTroops[$i][0] = "Archer" Then
  1110.                 $Arch = $i
  1111.             ElseIf $atkTroops[$i][0] = "Clan Castle" Then
  1112.                 $CC = $i
  1113.             ElseIf $atkTroops[$i][0] = "Giant" Then
  1114.                 $Giant = $i
  1115.             ElseIf $atkTroops[$i][0] = "King" Then
  1116.                 $King = $i
  1117.             ElseIf $atkTroops[$i][0] = "Queen" Then
  1118.                 $Queen = $i
  1119.             EndIf
  1120.         Next
  1121.  
  1122.         If _Sleep(500) Then ExitLoop
  1123.         Switch $deploySettings
  1124.         Case 0 ;Two sides ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1125.  
  1126.                 SetLog("~Attacking in two sides...")
  1127.                 If _Sleep(1000) Then ExitLoop
  1128.                 Local $numBarbPerSpot = Ceiling((($atkTroops[$Barb][1] / 2) / 5) / 2)
  1129.                 Local $numArchPerSpot = Ceiling((($atkTroops[$Arch][1] / 2) / 5) / 2)
  1130.                 Local $numGiantPerSpot = Ceiling((($atkTroops[$Giant][1] / 2) / 5) / 2)
  1131.  
  1132.                 SetLog("Dropping first wave of Giants")
  1133.                 For $i = 0 To 4 ;Drop first round of Giant
  1134.                     Click(68 + (72 * $Giant), 595) ;Select Troop
  1135.                     If _Sleep(100) Then ExitLoop (2)
  1136.                         If GUICtrlRead($chkAttackpoint) = $GUI_CHECKED THEN
  1137.                            Click(634,444,5)
  1138.                            Click(252,172,5)
  1139.                         EndIf
  1140.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numGiantPerSpot, 1)
  1141.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numGiantPerSpot, 1)
  1142.                  Next
  1143.  
  1144.                 SetLog("Dropping first wave of Barbarians")
  1145.                 For $i = 0 To 4 ;Drop first round of Barbarians
  1146.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  1147.                     If _Sleep(100) Then ExitLoop (2)
  1148.                            If GUICtrlRead($chkAttackpoint) = $GUI_CHECKED THEN
  1149.                            Click(634,444,10)
  1150.                            Click(252,172,10)
  1151.                         EndIf
  1152.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  1153.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  1154.                 Next
  1155.  
  1156.                 If _Sleep(1000) Then ExitLoop
  1157.  
  1158.                 SetLog("Dropping first wave of Archers")
  1159.                 For $i = 0 To 4 ;Drop first round of Archers
  1160.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  1161.                     If _Sleep(100) Then ExitLoop (2)
  1162.                         If GUICtrlRead($chkAttackpoint) = $GUI_CHECKED THEN
  1163.                            Click(634,444,10)
  1164.                            Click(252,172,10)
  1165.                         EndIf
  1166.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  1167.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  1168.                 Next
  1169.  
  1170.                 If _Sleep(2000) Then ExitLoop ;-------------------------------------------
  1171.  
  1172.                 SetLog("Dropping second wave of Giants")
  1173.                 For $i = 0 To 4 ;Drop s
  1174.                     Click(68 + (72 * $Giant), 595) ;Select Troop
  1175.                     If _Sleep(100) Then ExitLoop (2)
  1176.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numGiantPerSpot, 1)
  1177.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numGiantPerSpot, 1)
  1178.                  Next
  1179.  
  1180.                 SetLog("Dropping second wave of Barbarians")
  1181.                 For $i = 0 To 4 ;Drop second round of Barbarians
  1182.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  1183.                     If _Sleep(100) Then ExitLoop (2)
  1184.                         If GUICtrlRead($chkAttackpoint) = $GUI_CHECKED THEN
  1185.                            Click(634,444,10)
  1186.                            Click(252,172,10)
  1187.                         EndIf
  1188.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  1189.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  1190.                 Next
  1191.  
  1192.                 If _Sleep(1000) Then ExitLoop
  1193.  
  1194.                 SetLog("Dropping second wave of Archers")
  1195.                 For $i = 0 To 4 ;Drop second round of Archers
  1196.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  1197.                     If _Sleep(100) Then ExitLoop (2)
  1198.                         If GUICtrlRead($chkAttackpoint) = $GUI_CHECKED THEN
  1199.                            Click(634,444,10)
  1200.                            Click(252,172,10)
  1201.                         EndIf
  1202.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  1203.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  1204.                 Next
  1205.  
  1206.                 dropHeroes($TopLeft[3][0], $TopLeft[3][1], $King, $Queen)
  1207.                 If _Sleep(1000) Then ExitLoop
  1208.                 If $CC <> -1 Then dropCC($TopLeft[3][0], $TopLeft[3][1], $CC)
  1209.             Case 1 ;Three sides ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1210.                 SetLog("~Attacking in three sides...")
  1211.                 If _Sleep(1000) Then ExitLoop
  1212.                 Local $numBarbPerSpot = Ceiling((($atkTroops[$Barb][1] / 3) / 5) / 2)
  1213.                 Local $numArchPerSpot = Ceiling((($atkTroops[$Arch][1] / 3) / 5) / 2)
  1214.                 Local $numGiantPerSpot = Ceiling((($atkTroops[$Giant][1] / 2) / 5) / 2)
  1215.  
  1216.                 SetLog("Dropping first wave of Giants")
  1217.                 For $i = 0 To 4 ;Drop first round of Giant
  1218.                     Click(68 + (72 * $Giant), 595) ;Select Troop
  1219.                     If _Sleep(100) Then ExitLoop (2)
  1220.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numGiantPerSpot, 1)
  1221.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numGiantPerSpot, 1)
  1222.                  Next
  1223.  
  1224.  
  1225.                 SetLog("Dropping first wave of Barbarians")
  1226.                 For $i = 0 To 4 ;Drop first round of Barbarians
  1227.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  1228.                     If _Sleep(100) Then ExitLoop (2)
  1229.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  1230.                     Click($TopRight[$i][0], $TopRight[$i][1], $numBarbPerSpot, 1)
  1231.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  1232.                 Next
  1233.  
  1234.                 If _Sleep(1000) Then ExitLoop
  1235.  
  1236.                 SetLog("Dropping first wave of Archers")
  1237.                 For $i = 0 To 4 ;Drop first round of Archers
  1238.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  1239.                     If _Sleep(100) Then ExitLoop (2)
  1240.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  1241.                     Click($TopRight[$i][0], $TopRight[$i][1], $numArchPerSpot, 1)
  1242.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  1243.                 Next
  1244.  
  1245.                 If _Sleep(2000) Then ExitLoop ;-------------------------------------------
  1246.  
  1247.                 SetLog("Dropping first wave of Giants")
  1248.                 For $i = 0 To 4 ;Drop first round of Giant
  1249.                     Click(68 + (72 * $Giant), 595) ;Select Troop
  1250.                     If _Sleep(100) Then ExitLoop (2)
  1251.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numGiantPerSpot, 1)
  1252.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numGiantPerSpot, 1)
  1253.                  Next
  1254.  
  1255.                 SetLog("Dropping second wave of Barbarians")
  1256.                 For $i = 0 To 4 ;Drop second round of Barbarians
  1257.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  1258.                     If _Sleep(100) Then ExitLoop (2)
  1259.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  1260.                     Click($TopRight[$i][0], $TopRight[$i][1], $numBarbPerSpot, 1)
  1261.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  1262.                 Next
  1263.  
  1264.                 If _Sleep(1000) Then ExitLoop
  1265.  
  1266.                 SetLog("Dropping second wave of Archers")
  1267.                 For $i = 0 To 4 ;Drop second round of Archers
  1268.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  1269.                     If _Sleep(100) Then ExitLoop (2)
  1270.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  1271.                     Click($TopRight[$i][0], $TopRight[$i][1], $numArchPerSpot, 1)
  1272.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  1273.                 Next
  1274.  
  1275.                 dropHeroes($TopRight[3][0], $TopRight[3][1], $King, $Queen)
  1276.                 If _Sleep(1000) Then ExitLoop
  1277.                 If $CC <> -1 Then dropCC($TopRight[3][0], $TopRight[3][1], $CC)
  1278.             Case 2 ;Four sides ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1279.                 SetLog("~Attacking in all sides...")
  1280.                 If _Sleep(1000) Then ExitLoop
  1281.                 Local $numBarbPerSpot = Ceiling((($atkTroops[$Barb][1] / 4) / 5) / 2)
  1282.                 Local $numArchPerSpot = Ceiling((($atkTroops[$Arch][1] / 4) / 5) / 2)
  1283.                 Local $numGiantPerSpot = Ceiling((($atkTroops[$Giant][1] / 2) / 5) / 2)
  1284.  
  1285.                 SetLog("Dropping first wave of Giants")
  1286.                 For $i = 0 To 4 ;Drop first round of Giant
  1287.                     Click(68 + (72 * $Giant), 595) ;Select Troop
  1288.                     If _Sleep(100) Then ExitLoop (2)
  1289.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numGiantPerSpot, 1)
  1290.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numGiantPerSpot, 1)
  1291.                  Next
  1292.  
  1293.                 SetLog("Dropping first wave of Barbarians")
  1294.                 For $i = 0 To 4 ;Drop first round of Barbarians
  1295.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  1296.                     If _Sleep(100) Then ExitLoop (2)
  1297.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  1298.                     Click($TopRight[$i][0], $TopRight[$i][1], $numBarbPerSpot, 1)
  1299.                     Click($BottomLeft[$i][0], $BottomLeft[$i][1], $numBarbPerSpot, 1)
  1300.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  1301.                 Next
  1302.  
  1303.                 If _Sleep(1000) Then ExitLoop
  1304.  
  1305.                 SetLog("Dropping first wave of Archers")
  1306.                 For $i = 0 To 4 ;Drop first round of Archers
  1307.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  1308.                     If _Sleep(100) Then ExitLoop (2)
  1309.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  1310.                     Click($TopRight[$i][0], $TopRight[$i][1], $numArchPerSpot, 1)
  1311.                     Click($BottomLeft[$i][0], $BottomLeft[$i][1], $numArchPerSpot, 1)
  1312.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  1313.                 Next
  1314.  
  1315.                 If _Sleep(2000) Then ExitLoop ;-------------------------------------------
  1316.  
  1317.                 SetLog("Dropping second wave of Giants")
  1318.                 For $i = 0 To 4 ;Drop first round of Giant
  1319.                     Click(68 + (72 * $Giant), 595) ;Select Troop
  1320.                     If _Sleep(100) Then ExitLoop (2)
  1321.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numGiantPerSpot, 1)
  1322.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numGiantPerSpot, 1)
  1323.                  Next
  1324.  
  1325.                 SetLog("Dropping second wave of Barbarians")
  1326.                 For $i = 0 To 4 ;Drop second round of Barbarians
  1327.                     Click(68 + (72 * $Barb), 595) ;Select Troop
  1328.                     If _Sleep(100) Then ExitLoop (2)
  1329.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numBarbPerSpot, 1)
  1330.                     Click($TopRight[$i][0], $TopRight[$i][1], $numBarbPerSpot, 1)
  1331.                     Click($BottomLeft[$i][0], $BottomLeft[$i][1], $numBarbPerSpot, 1)
  1332.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numBarbPerSpot, 1)
  1333.                 Next
  1334.  
  1335.                 If _Sleep(1000) Then ExitLoop
  1336.  
  1337.                 SetLog("Dropping second wave of Archers")
  1338.                 For $i = 0 To 4 ;Drop second round of Archers
  1339.                     Click(68 + (72 * $Arch), 595) ;Select Troop
  1340.                     If _Sleep(100) Then ExitLoop (2)
  1341.                     Click($TopLeft[$i][0], $TopLeft[$i][1], $numArchPerSpot, 1)
  1342.                     Click($TopRight[$i][0], $TopRight[$i][1], $numArchPerSpot, 1)
  1343.                     Click($BottomLeft[$i][0], $BottomLeft[$i][1], $numArchPerSpot, 1)
  1344.                     Click($BottomRight[$i][0], $BottomRight[$i][1], $numArchPerSpot, 1)
  1345.                 Next
  1346.  
  1347.                 dropHeroes($BottomLeft[3][0], $BottomLeft[3][1], $King, $Queen)
  1348.                 If _Sleep(1000) Then ExitLoop
  1349.                 If $CC <> -1 Then dropCC($BottomLeft[3][0], $BottomLeft[3][1], $CC)
  1350.         EndSwitch
  1351.  
  1352.         If _Sleep(100) Then ExitLoop
  1353.         SetLog("Dropping left over troops")
  1354.         $atkTroops[$Barb][1] = Number(getNormal(40 + (72 * $Barb), 565))
  1355.         $atkTroops[$Arch][1] = Number(getNormal(40 + (72 * $Arch), 565))
  1356.  
  1357.         While $atkTroops[$Barb][1] <> 0
  1358.             Click(68 + (72 * $Barb), 595)
  1359.             Click($TopLeft[3][0], $TopLeft[3][1], $atkTroops[$Barb][1], 1)
  1360.  
  1361.             $atkTroops[$Barb][1] = Number(getNormal(40 + (72 * $Barb), 565))
  1362.         WEnd
  1363.  
  1364.         If _Sleep(1000) Then ExitLoop
  1365.  
  1366.         While $atkTroops[$Arch][1] <> 0
  1367.             Click(68 + (72 * $Arch), 595)
  1368.             Click($TopLeft[3][0], $TopLeft[3][1], $atkTroops[$Arch][1], 1)
  1369.  
  1370.             $atkTroops[$Arch][1] = Number(getNormal(40 + (72 * $Arch), 565))
  1371.         WEnd
  1372.  
  1373.         If _Sleep(100) Then ExitLoop
  1374.  
  1375.         ;Activate KQ's power
  1376.         If $checkKPower <> -1 Or $checkQPower <> -1 Then
  1377.             SetLog("Waiting " & $delayActivateKQ / 1000 & " seconds before activating King/Queen")
  1378.             _Sleep($delayActivateKQ)
  1379.             If $checkKPower <> -1 Then
  1380.                 SetLog("Activate King's power")
  1381.                 Click(68 + (72 * $checkKPower), 595)
  1382.             EndIf
  1383.             If $checkQPower <> -1 Then
  1384.                 SetLog("Activate Queen's power")
  1385.                 Click(68 + (72 * $checkQPower), 595)
  1386.             EndIf
  1387.         EndIf
  1388.  
  1389.         SetLog("~Finished Attacking, waiting to finish")
  1390.         ExitLoop
  1391.      WEnd
  1392. EndFunc
  1393.  
  1394. Func dropHeroes($x, $y, $KingSlot = -1, $QueenSlot = -1) ;Drops for king and queen
  1395.     While 1
  1396.         If _Sleep(2000) Then ExitLoop
  1397.         Switch $iradAttackMode
  1398.             Case 0 ;Dead Base
  1399.                 If $KingSlot <> -1 And ($KingAttack[0] = 1 Or $KingAttack[2] = 1) Then
  1400.                     SetLog("Dropping King")
  1401.                     Click(68 + (72 * $KingSlot), 595) ;Select King
  1402.                     Click($x, $y)
  1403.                     $checkKPower = $KingSlot
  1404.                 EndIf
  1405.  
  1406.                 If _Sleep(1000) Then ExitLoop
  1407.  
  1408.                 If $QueenSlot <> -1 And ($QueenAttack[0] = 1 Or $QueenAttack[2] = 1) Then
  1409.                     SetLog("Dropping Queen")
  1410.                     Click(68 + (72 * $QueenSlot), 595) ;Select Queen
  1411.                     Click($x, $y)
  1412.                     $checkQPower = $QueenSlot
  1413.                 EndIf
  1414.             Case 1 ;Weak Base
  1415.                 ;--------------------------------
  1416.             Case 2 ;All Base
  1417.                 If $KingSlot <> -1 And $KingAttack[2] = 1 Then
  1418.                     SetLog("Dropping King")
  1419.                     Click(68 + (72 * $KingSlot), 595) ;Select King
  1420.                     Click($x, $y)
  1421.                     $checkKPower = $KingSlot
  1422.                 EndIf
  1423.  
  1424.                 If _Sleep(1000) Then ExitLoop
  1425.  
  1426.                 If $QueenSlot <> -1 And $QueenAttack[2] = 1 Then
  1427.                     SetLog("Dropping Queen")
  1428.                     Click(68 + (72 * $QueenSlot), 595) ;Select Queen
  1429.                     Click($x, $y)
  1430.                     $checkQPower = $QueenSlot
  1431.                 EndIf
  1432.         EndSwitch
  1433.         ExitLoop
  1434.     WEnd
  1435. EndFunc   ;==>dropHeroes
  1436.  
  1437. Func dropCC($x, $y, $slot) ;Drop clan castle
  1438.     SetLog("Dropping Clan Castle")
  1439.     Click(68 + (72 * $slot), 595, 1, 500)
  1440.     Click($x, $y)
  1441. EndFunc   ;==>dropCC
  1442.  
  1443. Func PrepareAttack() ;Assigns troops
  1444.     While 1
  1445.         SetLog("Preparing to attack")
  1446.         For $i = 0 To 6
  1447.             _CaptureRegion()
  1448.             $Troop = _PixelGetColor_GetPixel(68 + (72 * $i), 595)
  1449.             If _ColorCheckVariation($Troop, Hex(0xF8B020, 6), 5) Then ;Check if slot is Barbarian
  1450.                 $atkTroops[$i][0] = "Barbarian"
  1451.                 $atkTroops[$i][1] = Number(getNormal(40 + (72 * $i), 565))
  1452.             ElseIf _ColorCheckVariation($Troop, Hex(0xD83F68, 6), 5) Then ;Check if slot is Archer
  1453.                 $atkTroops[$i][0] = "Archer"
  1454.                 $atkTroops[$i][1] = Number(getNormal(40 + (72 * $i), 565))
  1455.             ElseIf _ColorCheckVariation($Troop, Hex(0x7BC950, 6), 5) Then ;Check if slot is Goblin
  1456.                 $atkTroops[$i][0] = "Goblin"
  1457.                 $atkTroops[$i][1] = Number(getNormal(40 + (72 * $i), 565))
  1458.             ElseIf _ColorCheckVariation($Troop, Hex(0xF8D49E, 6), 5) Then ;Check if slot is Giant
  1459.                 $atkTroops[$i][0] = "Giant"
  1460.                 $atkTroops[$i][1] = Number(getNormal(40 + (72 * $i), 565))
  1461.             ElseIf _ColorCheckVariation($Troop, Hex(0x60A4D0, 6), 5) Then ;Check if slot is Wallbreaker
  1462.                 $atkTroops[$i][0] = "Wallbreaker"
  1463.                 $atkTroops[$i][1] = Number(getNormal(40 + (72 * $i), 565))
  1464.             ElseIf _ColorCheckVariation($Troop, Hex(0xF8EB79, 6), 5) Then ;Check if slot is King
  1465.                 $atkTroops[$i][0] = "King"
  1466.                 $atkTroops[$i][1] = 1
  1467.             ElseIf _ColorCheckVariation(_PixelGetColor_GetPixel(68 + (72 * $i), 588), Hex(0x7031F0, 6), 5) Then ;Check if slot is Queen
  1468.                 $atkTroops[$i][0] = "Queen"
  1469.                 $atkTroops[$i][1] = 1
  1470.             ElseIf _ColorCheckVariation(_PixelGetColor_GetPixel(68 + (72 * $i), 588), Hex(0xF6BF50, 6), 5) Then ;Check if slot is Clan Castle
  1471.                 $atkTroops[$i][0] = "Clan Castle"
  1472.                 $atkTroops[$i][1] = 1
  1473.             Else
  1474.                 $atkTroops[$i][0] = ""
  1475.                 $atkTroops[$i][1] = 0
  1476.             EndIf
  1477.             If $atkTroops[$i][0] <> "" Then SetLog("-" & $atkTroops[$i][0] & " " & $atkTroops[$i][1])
  1478.         Next
  1479.         ExitLoop
  1480.     WEnd
  1481. EndFunc   ;==>PrepareAttack
  1482.  
  1483. Func VillageSearch() ;Control for searching a village that meets conditions
  1484.     While 1
  1485.         Switch $iradAttackMode
  1486.             Case 0
  1487.                 SetLog("============Searching For Dead Base============")
  1488.             Case 1
  1489.                 SetLog("============Searching For Weak Base============")
  1490.             Case 2
  1491.                 SetLog("============Searching For All Base============")
  1492.         EndSwitch
  1493.         SetLog("~Gold: " & $MinGold & "; Elixir: " & $MinElixir & "; Dark: " & $MinDark & "; Trophy: " & $MinTrophy)
  1494.  
  1495.         $SearchCount = 0
  1496.         While 1
  1497.             If _Sleep(1000) Then ExitLoop (2)
  1498.             GetResources() ;Reads Resource Values
  1499.  
  1500.             If $Restart = True Then ExitLoop (2)
  1501.             If CompareResources() Then
  1502.                 If $iradAttackMode = 0 Then
  1503.                     If ZombieSearch() Then
  1504.                         SetLog("~~~~~~~Dead Base Found!~~~~~~~")
  1505.                         ExitLoop
  1506.                     Else
  1507.                         SetLog("~~~~~~~Not dead base, skipping~~~~~~~")
  1508.                         Click(750, 500) ;Click Next
  1509.                     EndIf
  1510.                 Else
  1511.                     ExitLoop
  1512.                 EndIf
  1513.             Else
  1514.                 Click(750, 500) ;Click Next
  1515.             EndIf
  1516.         WEnd
  1517.         If GUICtrlRead($chkAlertSearch) = $GUI_CHECKED Then
  1518.             TrayTip("Match Found!", "Gold: " & $searchGold & "; Elixir: " & $searchElixir & "; Dark: " & $searchDark & "; Trophy: " & $searchTrophy, "", 0)
  1519.             SoundPlay(@WindowsDir & "\media\Festival\Windows Exclamation.wav", 1)
  1520.         EndIf
  1521.         SetLog("===============Searching Complete===============")
  1522.         readConfig()
  1523.         ExitLoop
  1524.     WEnd
  1525. EndFunc   ;==>VillageSearch
  1526.  
  1527. Func GetResources() ;Reads resources
  1528.     While 1
  1529.         Local $i = 0
  1530.         While getGold(51, 66) = "" ; Loops until gold is readable
  1531.             If _Sleep(500) Then ExitLoop (2)
  1532.             $i += 1
  1533.             If $i >= 20 Then ; If gold cannot be read by 10 seconds
  1534.                 If checkNextButton() Then ;Checks for Out of Sync or Connection Error during search
  1535.                     Click(750, 500) ;Click Next
  1536.                 Else
  1537.                     SetLog("Cannot locate Next button, Restarting Bot")
  1538.                     checkMainScreen()
  1539.                     $Restart = True
  1540.                     ExitLoop (2)
  1541.                 EndIf
  1542.                 $i = 0
  1543.             EndIf
  1544.         WEnd
  1545.         If _Sleep(300) Then ExitLoop (2)
  1546.  
  1547.         $searchGold = getGold(51, 66)
  1548.         $searchElixir = getElixir(51, 66 + 29)
  1549.         $searchTrophy = getTrophy(51, 66 + 90)
  1550.  
  1551.         If $searchTrophy <> "" Then
  1552.             $searchDark = getDarkElixir(51, 66 + 57)
  1553.         Else
  1554.             $searchDark = 0
  1555.             $searchTrophy = getTrophy(51, 66 + 60)
  1556.         EndIf
  1557.  
  1558.         $SearchCount += 1 ; Counter for number of searches
  1559.         SetLog("(" & $SearchCount & ") [G]: " & $searchGold & Tab($searchGold, 12) & "[E]: " & $searchElixir & Tab($searchElixir, 12) & "[D]: " & $searchDark & Tab($searchDark, 12) & "[T]: " & $searchTrophy)
  1560.         ExitLoop
  1561.     WEnd
  1562. EndFunc   ;==>GetResources
  1563.  
  1564. Func CompareResources() ;Compares resources and returns true if conditions meet, otherwise returns false
  1565.     If $SearchCount <> 0 And Mod($SearchCount, 20) = 0 Then
  1566.         If $MinGold - 2000 >= 0 Then $MinGold -= 2000
  1567.         If $MinElixir - 2000 >= 0 Then $MinElixir -= 2000
  1568.         If $MinDark - 100 >= 0 Then $MinDark -= 100
  1569.         If $MinTrophy - 2 >= 0 Then $MinTrophy -= 2
  1570.         SetLog("~Gold: " & $MinGold & "; Elixir: " & $MinElixir & "; Dark: " & $MinDark & "; Trophy: " & $MinTrophy)
  1571.     EndIf
  1572.  
  1573.     Local $G = (Number($searchGold) >= Number($MinGold)), $E = (Number($searchElixir) >= Number($MinElixir)), $D = (Number($searchDark) >= Number($MinDark)), $T = (Number($searchTrophy) >= Number($MinTrophy))
  1574.     Local $Boolean = False
  1575.  
  1576.     If $G Or $E Then $Boolean = True
  1577.  
  1578.     If $chkConditions[0] = 1 Then
  1579.         If $G = False Or $E = False Then $Boolean = False
  1580.         Return $Boolean
  1581.     EndIf
  1582.  
  1583.     If $chkConditions[1] = 1 Then
  1584.         If $D = False Then $Boolean = False
  1585.         Return $Boolean
  1586.     EndIf
  1587.  
  1588.     If $chkConditions[2] = 1 Then
  1589.         If $T = False Then $Boolean = False
  1590.         Return $Boolean
  1591.     EndIf
  1592.  
  1593.     Return $Boolean
  1594. EndFunc   ;==>CompareResources
  1595.  
  1596. Func PrepareSearch() ;Click attack button and find match button, will break shield
  1597.     While 1
  1598.         Click(60, 614);Click Attack Button
  1599.         If _Sleep(1000) Then ExitLoop
  1600.         Click(217, 510);Click Find a Match Button
  1601.         If _Sleep(3000) Then ExitLoop
  1602.         _CaptureRegion()
  1603.         If _ColorCheckVariation(_PixelGetColor_GetPixel(513, 416), Hex(0x5DAC10, 6), 50) Then
  1604.             Click(513, 416);Click Okay To Break Shield
  1605.         EndIf
  1606.         ExitLoop
  1607.     WEnd
  1608. EndFunc   ;==>PrepareSearch
  1609. #EndRegion ### Attack Functions ###
  1610. ;---------------------------------------------------
  1611. #Region ### Troops Settings ###
  1612. Func LocateCollectors()
  1613.     SetLog("Locating Collectors...")
  1614.     Local $MsgBox
  1615.     For $i = 0 To 16
  1616.         $MsgBox = MsgBox(6 + 262144, "Locate collector #" & $i + 1, "Click Continue then click on your collector #" & $i + 1 & ". Cancel if not available. Try again to start over.", 0, $frmBot)
  1617.         If $MsgBox = 11 Then
  1618.             $collectorPos[$i][0] = FindPos()[0]
  1619.             $collectorPos[$i][1] = FindPos()[1]
  1620.         ElseIf $MsgBox = 10 Then
  1621.             ExitLoop (2)
  1622.         Else
  1623.             $collectorPos[$i][0] = ""
  1624.             $collectorPos[$i][1] = ""
  1625.         EndIf
  1626.         SetLog("-Collector #" & $i + 1 & " = " & "(" & $collectorPos[$i][0] & "," & $collectorPos[$i][1] & ")")
  1627.     Next
  1628.     SaveConfig()
  1629.     SetLog("-Locating Complete-")
  1630. EndFunc   ;==>LocateCollectors
  1631.  
  1632. Func LocateBarrack()
  1633.     SetLog("Locating Barracks...")
  1634.     Local $MsgBox
  1635.     While 1
  1636.         While 1
  1637.             $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)
  1638.             If $MsgBox = 11 Then
  1639.                 $barrackPos[0][0] = FindPos()[0]
  1640.                 $barrackPos[0][1] = FindPos()[1]
  1641.             ElseIf $MsgBox = 10 Then
  1642.                 ExitLoop
  1643.             Else
  1644.                 $barrackPos[0][0] = ""
  1645.                 $barrackPos[0][1] = ""
  1646.             EndIf
  1647.             If _Sleep(500) Then ExitLoop
  1648.             $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)
  1649.             If $MsgBox = 11 Then
  1650.                 $barrackPos[1][0] = FindPos()[0]
  1651.                 $barrackPos[1][1] = FindPos()[1]
  1652.             ElseIf $MsgBox = 10 Then
  1653.                 ExitLoop
  1654.             Else
  1655.                 $barrackPos[1][0] = ""
  1656.                 $barrackPos[1][1] = ""
  1657.             EndIf
  1658.             If _Sleep(500) Then ExitLoop
  1659.             $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)
  1660.             If $MsgBox = 11 Then
  1661.                 $barrackPos[2][0] = FindPos()[0]
  1662.                 $barrackPos[2][1] = FindPos()[1]
  1663.             ElseIf $MsgBox = 10 Then
  1664.                 ExitLoop
  1665.             Else
  1666.                 $barrackPos[2][0] = ""
  1667.                 $barrackPos[2][1] = ""
  1668.             EndIf
  1669.             If _Sleep(500) Then ExitLoop
  1670.             $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)
  1671.             If $MsgBox = 11 Then
  1672.                 $barrackPos[3][0] = FindPos()[0]
  1673.                 $barrackPos[3][1] = FindPos()[1]
  1674.             ElseIf $MsgBox = 10 Then
  1675.                 ExitLoop
  1676.             Else
  1677.                 $barrackPos[3][0] = ""
  1678.                 $barrackPos[3][1] = ""
  1679.             EndIf
  1680.             If GUICtrlRead($chkRequest) = $GUI_CHECKED And $CCPos[0] = -1 Then LocateClanClastle()
  1681.             ExitLoop (2)
  1682.         WEnd
  1683.     WEnd
  1684.     SaveConfig()
  1685.     SetLog("-Locating Complete-")
  1686.     SetLog("-Barrack 1 = " & "(" & $barrackPos[0][0] & "," & $barrackPos[0][1] & ")")
  1687.     SetLog("-Barrack 2 = " & "(" & $barrackPos[1][0] & "," & $barrackPos[1][1] & ")")
  1688.     SetLog("-Barrack 3 = " & "(" & $barrackPos[2][0] & "," & $barrackPos[2][1] & ")")
  1689.     SetLog("-Barrack 4 = " & "(" & $barrackPos[3][0] & "," & $barrackPos[3][1] & ")")
  1690. EndFunc   ;==>LocateBarrack
  1691.  
  1692. Func LocateClanClastle()
  1693.     While 1
  1694.         $MsgBox = MsgBox(1 + 262144, "Locate Clan Castle", "Click OK then click on your Clan Castle", 0, $frmBot)
  1695.         If $MsgBox = 1 Then
  1696.             $CCPos[0] = FindPos()[0]
  1697.             $CCPos[1] = FindPos()[1]
  1698.             SetLog("-Clan Castle =  " & "(" & $CCPos[0] & "," & $CCPos[1] & ")")
  1699.         EndIf
  1700.         ExitLoop
  1701.     WEnd
  1702. EndFunc   ;==>LocateClanClastle
  1703.  
  1704. Func Train()
  1705.     If $barrackPos[0][0] = "" Then
  1706.         LocateBarrack()
  1707.         SaveConfig()
  1708.         If _Sleep(2000) Then Return
  1709.     EndIf
  1710.     SetLog("Training Troops...")
  1711.  
  1712.     While 1
  1713.         For $i = 0 To 3
  1714.             If _Sleep(500) Then ExitLoop (2)
  1715.  
  1716.             Click(1, 1) ;Click Away
  1717.  
  1718.             If _Sleep(500) Then ExitLoop (2)
  1719.  
  1720.             Click($barrackPos[$i][0], $barrackPos[$i][1]) ;Click Barrack
  1721.  
  1722.             If _Sleep(500) Then ExitLoop (2)
  1723.  
  1724.             Local $TrainPos = _PixelSearch(155, 603, 694, 605, Hex(0x603818, 6), 5) ;Finds Train Troops button
  1725.             If IsArray($TrainPos) = False Then
  1726.                 SetLog("Barrack " & $i + 1 & " is not available")
  1727.                 If _Sleep(500) Then ExitLoop (2)
  1728.             Else
  1729.                 Click($TrainPos[0], $TrainPos[1]) ;Click Train Troops button
  1730.                 If _Sleep(500) Then ExitLoop (2)
  1731.  
  1732.                 CheckFullArmy()
  1733.  
  1734.                 _CaptureRegion()
  1735.                 Switch $barrackTroop[$i]
  1736.                     Case 0
  1737.                         While _ColorCheckVariation(_PixelGetColor_GetPixel(329, 297), Hex(0xDC3F70, 6), 20)
  1738.                             _CaptureRegion()
  1739.                             Click(220, 320) ;Barbarian
  1740.                             If _Sleep(10) Then ExitLoop
  1741.                         WEnd
  1742.                     Case 1
  1743.                         While _ColorCheckVariation(_PixelGetColor_GetPixel(217, 297), Hex(0xF8AD20, 6), 20)
  1744.                             _CaptureRegion()
  1745.                             Click(331, 320) ;Archer
  1746.                             If _Sleep(10) Then ExitLoop
  1747.                         WEnd
  1748.                     Case 2
  1749.                         While _ColorCheckVariation(_PixelGetColor_GetPixel(217, 297), Hex(0xF8AD20, 6), 20)
  1750.                             _CaptureRegion()
  1751.                             Click(432, 320) ;Giant
  1752.                             If _Sleep(10) Then ExitLoop
  1753.                         WEnd
  1754.                     Case 3
  1755.                         While _ColorCheckVariation(_PixelGetColor_GetPixel(217, 297), Hex(0xF8AD20, 6), 20)
  1756.                             _CaptureRegion()
  1757.                             Click(546, 320) ;Goblins
  1758.                             If _Sleep(10) Then ExitLoop
  1759.                         WEnd
  1760.                 EndSwitch
  1761.             EndIf
  1762.             If _Sleep(500) Then ExitLoop (2)
  1763.             Click(1, 1, 2, 250); Click away twice with 250ms delay
  1764.         Next
  1765.  
  1766.         SetLog("Training Troops Complete")
  1767.         ExitLoop
  1768.     WEnd
  1769. EndFunc   ;==>Train
  1770.  
  1771.  
  1772. Func DonateCC()
  1773.    If GUICtrlRead($donatec) = $GUI_CHECKED THEN
  1774.       While 1
  1775.          SetLog("Donating for Clan Castle's Troops")
  1776.          Click(10, 334)
  1777.          If _Sleep(10000) Then ExitLoop
  1778.          Click(189, 24)
  1779.          $DonateTroop = _PixelSearch(112, 150, 122, 685, Hex(0xC0E460, 6), 10)
  1780.             While IsArray($DonateTroop)
  1781.             SetLog("Found donate button on " & $DonateTroop[0] & "," & $DonateTroop[1])
  1782.             Click($DonateTroop[0], $DonateTroop[1]) ; click button donate
  1783.                If _Sleep(10000) Then ExitLoop
  1784.                Click(($DonateTroop[0]+200), ($DonateTroop[1]-20),5) ; donate archer
  1785.  
  1786.                If _Sleep(10000) Then ExitLoop
  1787.          $DonateTroop = _PixelSearch(112, 150, 122, ($DonateTroop[1]-20), Hex(0xC0E460, 6), 10)
  1788.       WEnd
  1789.  
  1790. If _Sleep(1000) Then ExitLoop
  1791. Click(330, 334)
  1792. ExitLoop
  1793. WEnd
  1794. EndIf
  1795. EndFunc
  1796.  
  1797. Func RequestCC()
  1798.     If GUICtrlRead($chkRequest) = $GUI_CHECKED Then
  1799.         If GUICtrlRead($txtRequest) <> "" Then
  1800.             While 1
  1801.                 SetLog("Requesting for Clan Castle's Troops")
  1802.                 Click($CCPos[0], $CCPos[1])
  1803.                 If _Sleep(1000) Then ExitLoop
  1804.                 _CaptureRegion()
  1805.                 $RequestTroop = _PixelSearch(310, 580, 553, 622, Hex(0x608C90, 6), 10)
  1806.                 If IsArray($RequestTroop) Then
  1807.                     Click($RequestTroop[0], $RequestTroop[1])
  1808.                 Else
  1809.                     SetLog("Clan Castle not available")
  1810.                 EndIf
  1811.                 If _Sleep(1000) Then ExitLoop
  1812.                 Click(430, 140)
  1813.                 If _Sleep(1000) Then ExitLoop
  1814.                 $TextRequest = GUICtrlRead($txtRequest)
  1815.                 ControlSend("BlueStacks App Player", "", "", $TextRequest, 0)
  1816.                 If _Sleep(1000) Then ExitLoop
  1817.                 Click(524, 228)
  1818.                 ;Click(340,228)
  1819.                 ExitLoop
  1820.             WEnd
  1821.         EndIf
  1822.     EndIf
  1823. EndFunc   ;==>RequestCC
  1824.  
  1825.  
  1826. Func CheckFullArmy()
  1827.     _CaptureRegion()
  1828.     $Pixel = _ColorCheckVariation(_PixelGetColor_GetPixel(327, 520), Hex(0xD03838, 6), 20)
  1829.     If $Pixel Then
  1830.         $fullArmy = True
  1831.     Else
  1832.         $fullArmy = False
  1833.     EndIf
  1834. EndFunc   ;==>CheckFullArmy
  1835. #EndRegion ### Troops Settings ###
  1836. ;---------------------------------------------------
  1837. #Region ### Village Functions ###
  1838. Func DropTrophy()
  1839.     Local $TrophyCount = getOther(50, 74, "Trophy")
  1840.     While Number($TrophyCount) > Number($itxtMaxTrophy)
  1841.         $TrophyCount = getOther(50, 74, "Trophy")
  1842.         SetLog("Trophy Count : " & $TrophyCount)
  1843.         If Number($TrophyCount) > Number($itxtMaxTrophy) Then
  1844.             SetLog("Dropping Trophies")
  1845.             If _Sleep(2000) Then ExitLoop
  1846.  
  1847.             ZoomOut()
  1848.             PrepareSearch()
  1849.  
  1850.             If _Sleep(5000) Then ExitLoop
  1851.  
  1852.             Click(34, 310) ;Drop one troop
  1853.  
  1854.             If _Sleep(1000) Then ExitLoop
  1855.  
  1856.             ReturnHome(False, False) ;Return home no screenshot
  1857.         Else
  1858.             SetLog("Trophy Drop Complete")
  1859.         EndIf
  1860.     WEnd
  1861. EndFunc   ;==>DropTrophy
  1862.  
  1863. Func Collect()
  1864.     If $collectorPos[0][0] = "" Then
  1865.         LocateCollectors()
  1866.         SaveConfig()
  1867.         If _Sleep(2000) Then Return
  1868.     EndIf
  1869.     SetLog("Collecting Resources")
  1870.     _Sleep(250)
  1871.     Click(1, 1) ;Click Away
  1872.     For $i = 0 To 16
  1873.         If _Sleep(250) Or $RunState = False Then ExitLoop
  1874.         Click($collectorPos[$i][0], $collectorPos[$i][1]) ;Click collector
  1875.         If _Sleep(250) Or $RunState = False Then ExitLoop
  1876.         Click(1, 1) ;Click Away
  1877.     Next
  1878.     SetLog("Collecting Complete")
  1879. EndFunc   ;==>Collect
  1880. #EndRegion ### Village Functions ###
  1881. ;---------------------------------------------------
  1882. #Region ### Other Functions ###
  1883. Func readConfig() ;Reads config and sets it to the variables
  1884.     If FileExists($config) Then
  1885.         ;Search Settings------------------------------------------------------------------------
  1886.         $MinGold = IniRead($config, "search", "searchGold", "0")
  1887.         $MinElixir = IniRead($config, "search", "searchElixir", "0")
  1888.         $MinDark = IniRead($config, "search", "searchDark", "0")
  1889.         $MinTrophy = IniRead($config, "search", "searchTrophy", "0")
  1890.  
  1891.         $chkConditions[0] = IniRead($config, "search", "conditionGoldElixir", "0")
  1892.         $chkConditions[1] = IniRead($config, "search", "conditionDark", "0")
  1893.         $chkConditions[2] = IniRead($config, "search", "conditionTrophy", "0")
  1894.         ;Attack Settings-------------------------------------------------------------------------
  1895.         $deploySettings = IniRead($config, "attack", "deploy", "0")
  1896.         $icmbAlgorithm = IniRead($config, "attack", "algorithm", "0")
  1897.         $iradAttackMode = IniRead($config, "attack", "mode", "0")
  1898.  
  1899.         $KingAttack[0] = IniRead($config, "attack", "king-dead", "0")
  1900.         $KingAttack[2] = IniRead($config, "attack", "king-all", "0")
  1901.  
  1902.         $QueenAttack[0] = IniRead($config, "attack", "queen-dead", "0")
  1903.         $QueenAttack[2] = IniRead($config, "attack", "queen-all", "0")
  1904.         ;Donate Settings-------------------------------------------------------------------------
  1905.         $CCPos[0] = IniRead($config, "donate", "xCCPos", "0")
  1906.         $CCPos[1] = IniRead($config, "donate", "yCCPos", "0")
  1907.         $CheckRequest = IniRead($config, "donate", "request", "0")
  1908.         $TextRequest = IniRead($config, "donate", "textrequest", "")
  1909.         ;Troop Settings--------------------------------------------------------------------------
  1910.         $icmbTroopComp = IniRead($config, "troop", "composition", 0)
  1911.  
  1912.         For $i = 0 To 3 ;Covers all 4 Barracks
  1913.             $barrackPos[$i][0] = IniRead($config, "troop", "xBarrack" & $i + 1, "0")
  1914.             $barrackPos[$i][1] = IniRead($config, "troop", "yBarrack" & $i + 1, "0")
  1915.             $barrackTroop[$i] = IniRead($config, "troop", "troop" & $i + 1, "0")
  1916.         Next
  1917.     Else
  1918.         Return False
  1919.     EndIf
  1920.     ;General Settings--------------------------------------------------------------------------
  1921.     $frmBotPosX = IniRead($config, "general", "frmBotPosX", "207")
  1922.     $frmBotPosY = IniRead($config, "general", "frmBotPosY", "158")
  1923.     $itxtMaxTrophy = IniRead($config, "general", "MaxTrophy", "3000")
  1924.     $ichkBackground = IniRead($config, "general", "Background", "0")
  1925.  
  1926.     For $i = 0 To 16 ;Covers all Collectors
  1927.         $collectorPos[$i][0] = IniRead($config, "general", "xCollector" & $i + 1, "0")
  1928.         $collectorPos[$i][1] = IniRead($config, "general", "yCollector" & $i + 1, "0")
  1929.     Next
  1930. EndFunc   ;==>readConfig
  1931.  
  1932. Func applyConfig() ;Applies the data from config to the controls in GUI
  1933.     ;Search Settings------------------------------------------------------------------------
  1934.     GUICtrlSetData($txtMinGold, $MinGold)
  1935.     GUICtrlSetData($txtMinElixir, $MinElixir)
  1936.     GUICtrlSetData($txtMinDarkElixir, $MinDark)
  1937.     GUICtrlSetData($txtMinTrophy, $MinTrophy)
  1938.  
  1939.     If $chkConditions[0] = 1 Then
  1940.         GUICtrlSetState($chkMeetGxE, $GUI_CHECKED)
  1941.     ElseIf $chkConditions[0] = 0 Then
  1942.         GUICtrlSetState($chkMeetGxE, $GUI_UNCHECKED)
  1943.     EndIf
  1944.  
  1945.     If $chkConditions[1] = 1 Then
  1946.         GUICtrlSetState($chkMeetDE, $GUI_CHECKED)
  1947.     ElseIf $chkConditions[1] = 0 Then
  1948.         GUICtrlSetState($chkMeetDE, $GUI_UNCHECKED)
  1949.     EndIf
  1950.  
  1951.     If $chkConditions[2] = 1 Then
  1952.         GUICtrlSetState($chkMeetTrophy, $GUI_CHECKED)
  1953.     ElseIf $chkConditions[2] = 0 Then
  1954.         GUICtrlSetState($chkMeetTrophy, $GUI_UNCHECKED)
  1955.     EndIf
  1956.     ;Attack Settings-------------------------------------------------------------------------
  1957.     _GUICtrlComboBox_SetCurSel($cmbDeploy, $deploySettings)
  1958.     _GUICtrlComboBox_SetCurSel($cmbAlgorithm, $icmbAlgorithm)
  1959.  
  1960.     Switch $iradAttackMode
  1961.         Case 0
  1962.             GUICtrlSetState($radDeadBases, $GUI_CHECKED)
  1963.             GUICtrlSetState($radWeakBases, $GUI_UNCHECKED)
  1964.             GUICtrlSetState($radAllBases, $GUI_UNCHECKED)
  1965.         Case 1
  1966.             GUICtrlSetState($radDeadBases, $GUI_UNCHECKED)
  1967.             GUICtrlSetState($radWeakBases, $GUI_CHECKED)
  1968.             GUICtrlSetState($radAllBases, $GUI_UNCHECKED)
  1969.         Case 2
  1970.             GUICtrlSetState($radDeadBases, $GUI_UNCHECKED)
  1971.             GUICtrlSetState($radWeakBases, $GUI_UNCHECKED)
  1972.             GUICtrlSetState($radAllBases, $GUI_CHECKED)
  1973.     EndSwitch
  1974.  
  1975.     If $KingAttack[0] = 1 Then
  1976.         GUICtrlSetState($chkKingAttackDeadBases, $GUI_CHECKED)
  1977.     Else
  1978.         GUICtrlSetState($chkKingAttackDeadBases, $GUI_UNCHECKED)
  1979.     EndIf
  1980.     If $KingAttack[2] = 1 Then
  1981.         GUICtrlSetState($chkKingAttackAllBases, $GUI_CHECKED)
  1982.     Else
  1983.         GUICtrlSetState($chkKingAttackAllBases, $GUI_UNCHECKED)
  1984.     EndIf
  1985.  
  1986.     If $QueenAttack[0] = 1 Then
  1987.         GUICtrlSetState($chkQueenAttackDeadBases, $GUI_CHECKED)
  1988.     Else
  1989.         GUICtrlSetState($chkQueenAttackDeadBases, $GUI_UNCHECKED)
  1990.     EndIf
  1991.     If $QueenAttack[2] = 1 Then
  1992.         GUICtrlSetState($chkQueenAttackAllBases, $GUI_CHECKED)
  1993.     Else
  1994.         GUICtrlSetState($chkQueenAttackAllBases, $GUI_UNCHECKED)
  1995.     EndIf
  1996.     ;Donate Settings-------------------------------------------------------------------------
  1997.     If $CheckRequest = 1 Then
  1998.         GUICtrlSetState($chkRequest, $GUI_CHECKED)
  1999.     Else
  2000.         GUICtrlSetState($chkRequest, $GUI_UNCHECKED)
  2001.     EndIf
  2002.  
  2003.     GUICtrlSetData($txtRequest, $TextRequest)
  2004.  
  2005.     ;Troop Settings--------------------------------------------------------------------------
  2006.     _GUICtrlComboBox_SetCurSel($cmbTroopComp, $icmbTroopComp)
  2007.     SetComboTroopComp()
  2008.  
  2009.     _GUICtrlComboBox_SetCurSel($cmbBarrack1, $barrackTroop[0])
  2010.     _GUICtrlComboBox_SetCurSel($cmbBarrack2, $barrackTroop[1])
  2011.     _GUICtrlComboBox_SetCurSel($cmbBarrack3, $barrackTroop[2])
  2012.     _GUICtrlComboBox_SetCurSel($cmbBarrack4, $barrackTroop[3])
  2013.     ;General Settings--------------------------------------------------------------------------
  2014.     WinMove($sBotTitle, "", $frmBotPosX, $frmBotPosY)
  2015.     GUICtrlSetData($txtMaxTrophy, $itxtMaxTrophy)
  2016.  
  2017.     If $ichkBackground = 1 Then
  2018.         GUICtrlSetState($chkBackground, $GUI_CHECKED)
  2019.     Else
  2020.         GUICtrlSetState($chkBackground, $GUI_UNCHECKED)
  2021.     EndIf
  2022.     chkBackground() ;Applies it to hidden button
  2023. EndFunc   ;==>applyConfig
  2024.  
  2025. Func SaveConfig() ;Saves the controls settings to the config
  2026.     ;Search Settings------------------------------------------------------------------------
  2027.     IniWrite($config, "search", "searchGold", GUICtrlRead($txtMinGold))
  2028.     IniWrite($config, "search", "searchElixir", GUICtrlRead($txtMinElixir))
  2029.     IniWrite($config, "search", "searchDark", GUICtrlRead($txtMinDarkElixir))
  2030.     IniWrite($config, "search", "searchTrophy", GUICtrlRead($txtMinTrophy))
  2031.  
  2032.     If GUICtrlRead($chkMeetGxE) = $GUI_CHECKED Then
  2033.         IniWrite($config, "search", "conditionGoldElixir", 1)
  2034.     Else
  2035.         IniWrite($config, "search", "conditionGoldElixir", 0)
  2036.     EndIf
  2037.  
  2038.     If GUICtrlRead($chkMeetDE) = $GUI_CHECKED Then
  2039.         IniWrite($config, "search", "conditionDark", 1)
  2040.     Else
  2041.         IniWrite($config, "search", "conditionDark", 0)
  2042.     EndIf
  2043.  
  2044.     If GUICtrlRead($chkMeetTrophy) = $GUI_CHECKED Then
  2045.         IniWrite($config, "search", "conditionTrophy", 1)
  2046.     Else
  2047.         IniWrite($config, "search", "conditionTrophy", 0)
  2048.     EndIf
  2049.     ;Donate Settings-------------------------------------------------------------------------
  2050.     If GUICtrlRead($chkRequest) = $GUI_CHECKED Then
  2051.         IniWrite($config, "donate", "request", 1)
  2052.     Else
  2053.         IniWrite($config, "donate", "request", 0)
  2054.     EndIf
  2055.     IniWrite($config, "donate", "xCCPos", $CCPos[0])
  2056.     IniWrite($config, "donate", "yCCPos", $CCPos[1])
  2057.  
  2058.     IniWrite($config, "donate", "textrequest", GUICtrlRead($txtRequest))
  2059.     ;Attack Settings-------------------------------------------------------------------------
  2060.     IniWrite($config, "attack", "deploy", _GUICtrlComboBox_GetCurSel($cmbDeploy))
  2061.     IniWrite($config, "attack", "algorithm", _GUICtrlComboBox_GetCurSel($cmbAlgorithm))
  2062.  
  2063.     If GUICtrlRead($radDeadBases) = $GUI_CHECKED Then
  2064.         IniWrite($config, "attack", "mode", 0)
  2065.     ElseIf GUICtrlRead($radWeakBases) = $GUI_CHECKED Then
  2066.         IniWrite($config, "attack", "mode", 1)
  2067.     ElseIf GUICtrlRead($radAllBases) = $GUI_CHECKED Then
  2068.         IniWrite($config, "attack", "mode", 2)
  2069.     EndIf
  2070.  
  2071.     If GUICtrlRead($chkKingAttackDeadBases) = $GUI_CHECKED Then
  2072.         IniWrite($config, "attack", "king-dead", 1)
  2073.     Else
  2074.         IniWrite($config, "attack", "king-dead", 0)
  2075.     EndIf
  2076.     If GUICtrlRead($chkKingAttackAllBases) = $GUI_CHECKED Then
  2077.         IniWrite($config, "attack", "king-all", 1)
  2078.     Else
  2079.         IniWrite($config, "attack", "king-all", 0)
  2080.     EndIf
  2081.  
  2082.     If GUICtrlRead($chkQueenAttackDeadBases) = $GUI_CHECKED Then
  2083.         IniWrite($config, "attack", "queen-dead", 1)
  2084.     Else
  2085.         IniWrite($config, "attack", "queen-dead", 0)
  2086.     EndIf
  2087.     If GUICtrlRead($chkQueenAttackAllBases) = $GUI_CHECKED Then
  2088.         IniWrite($config, "attack", "queen-all", 1)
  2089.     Else
  2090.         IniWrite($config, "attack", "queen-all", 0)
  2091.     EndIf
  2092.     ;Donate Settings-------------------------------------------------------------------------
  2093.  
  2094.     ;Troop Settings--------------------------------------------------------------------------
  2095.     IniWrite($config, "troop", "composition", _GUICtrlComboBox_GetCurSel($cmbTroopComp))
  2096.  
  2097.     IniWrite($config, "troop", "troop1", _GUICtrlComboBox_GetCurSel($cmbBarrack1))
  2098.     IniWrite($config, "troop", "troop2", _GUICtrlComboBox_GetCurSel($cmbBarrack2))
  2099.     IniWrite($config, "troop", "troop3", _GUICtrlComboBox_GetCurSel($cmbBarrack3))
  2100.     IniWrite($config, "troop", "troop4", _GUICtrlComboBox_GetCurSel($cmbBarrack4))
  2101.     For $i = 0 To 3 ;Covers all 4 Barracks
  2102.         IniWrite($config, "troop", "xBarrack" & $i + 1, $barrackPos[$i][0])
  2103.         IniWrite($config, "troop", "yBarrack" & $i + 1, $barrackPos[$i][1])
  2104.     Next
  2105.     ;General Settings--------------------------------------------------------------------------
  2106.     Local $frmBotPos = WinGetPos($sBotTitle)
  2107.     IniWrite($config, "general", "frmBotPosX", $frmBotPos[0])
  2108.     IniWrite($config, "general", "frmBotPosY", $frmBotPos[1])
  2109.     IniWrite($config, "general", "MaxTrophy", GUICtrlRead($txtMaxTrophy))
  2110.  
  2111.     If GUICtrlRead($chkBackground) = $GUI_CHECKED Then
  2112.         IniWrite($config, "general", "Background", 1)
  2113.     Else
  2114.         IniWrite($config, "general", "Background", 0)
  2115.     EndIf
  2116.  
  2117.     For $i = 0 To 16 ;Covers all Collectors
  2118.         IniWrite($config, "general", "xCollector" & $i + 1, $collectorPos[$i][0])
  2119.         IniWrite($config, "general", "yCollector" & $i + 1, $collectorPos[$i][1])
  2120.     Next
  2121. EndFunc   ;==>SaveConfig
  2122. ;========================================================================================
  2123. Func SetLog($string) ;Sets the text for the log
  2124.     _GUICtrlEdit_AppendText($txtLog, Time() & $string & @CRLF)
  2125.     _GUICtrlStatusBar_SetText($statLog, "Status : " & $string)
  2126.     _FileWriteLog($hLogFileHandle, $string)
  2127. EndFunc   ;==>SetLog
  2128.  
  2129. Func Time() ;Gives the time in '[00:00:00 AM/PM]' format
  2130.     Return "[" & _NowTime(3) & "] "
  2131. EndFunc   ;==>Time
  2132.  
  2133. Func _Sleep($iDelay, $iSleep = True)
  2134.     Local $iBegin = TimerInit()
  2135.     While TimerDiff($iBegin) < $iDelay
  2136.         If $RunState = False Then Return True
  2137.         If $iSleep = True Then Sleep(100)
  2138.     WEnd
  2139.     Return False
  2140. EndFunc   ;==>_Sleep
  2141.  
  2142. Func Click($x, $y, $times = 1, $speed = 0)
  2143.     If $times <> 1 Then
  2144.         For $i = 0 To ($times - 1)
  2145.             ControlClick("BlueStacks App Player", "", "", "left", "1", $x, $y)
  2146.             If _Sleep($speed, False) Then ExitLoop
  2147.         Next
  2148.     Else
  2149.         ControlClick("BlueStacks App Player", "", "", "left", "1", $x, $y)
  2150.     EndIf
  2151. EndFunc   ;==>Click
  2152.  
  2153. Func getBSPos()
  2154.     $aPos = ControlGetPos("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]")
  2155.     $tPoint = DllStructCreate("int X;int Y")
  2156.     DllStructSetData($tPoint, "X", $aPos[0])
  2157.     DllStructSetData($tPoint, "Y", $aPos[1])
  2158.     _WinAPI_ClientToScreen(WinGetHandle(WinGetTitle("BlueStacks App Player")), $tPoint)
  2159.  
  2160.     $BSpos[0] = DllStructGetData($tPoint, "X")
  2161.     $BSpos[1] = DllStructGetData($tPoint, "Y")
  2162.  
  2163.     $CtrlHandle = ControlGetHandle("BlueStacks App Player", "", "BlueStacksApp1")
  2164. EndFunc   ;==>getBSPos
  2165.  
  2166. Func FindPos()
  2167.     getBSPos()
  2168.     Local $Pos[2]
  2169.     While 1
  2170.         If _IsPressed("01") Then
  2171.             $Pos[0] = MouseGetPos()[0] - $BSpos[0]
  2172.             $Pos[1] = MouseGetPos()[1] - $BSpos[1]
  2173.             Return $Pos
  2174.         EndIf
  2175.     WEnd
  2176. EndFunc   ;==>FindPos
  2177.  
  2178. Func Tab($a, $b)
  2179.     $Tab = ""
  2180.     For $i = StringLen($a) To $b Step 1
  2181.         $Tab &= " "
  2182.     Next
  2183.     Return $Tab
  2184. EndFunc   ;==>Tab
  2185.  
  2186. Func CreateLogFile()
  2187.     $sLogPath = @ScriptDir & "\logs\" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "." & @MIN & "." & @SEC & ".log"
  2188.     $hLogFileHandle = FileOpen($sLogPath, $FO_APPEND)
  2189. EndFunc   ;==>CreateLogFile
  2190.  
  2191.  
  2192. Func DisableBS($HWnD, $iButton)
  2193.     ConsoleWrite('+ Window Handle: ' & $HWnD & @CRLF)
  2194.     $hSysMenu = _GUICtrlMenu_GetSystemMenu($HWnD, 0)
  2195.     _GUICtrlMenu_RemoveMenu($hSysMenu, $iButton, False)
  2196.     _GUICtrlMenu_DrawMenuBar($HWnD)
  2197. EndFunc   ;==>DisableBS
  2198.  
  2199. Func EnableBS($HWnD, $iButton)
  2200.     ConsoleWrite('+ Window Handle: ' & $HWnD & @CRLF)
  2201.     $hSysMenu = _GUICtrlMenu_GetSystemMenu($HWnD, 1)
  2202.     _GUICtrlMenu_RemoveMenu($hSysMenu, $iButton, False)
  2203.     _GUICtrlMenu_DrawMenuBar($HWnD)
  2204. EndFunc   ;==>EnableBS
  2205.  
  2206. #EndRegion ### Other Functions ###
  2207. ;---------------------------------------------------
  2208. #Region ### Get Resources+Get Pixels Functions ###
  2209. ;==============================================================================================================
  2210. ;===Main Function==============================================================================================
  2211. ;--------------------------------------------------------------------------------------------------------------
  2212. ;Checks if the color components exceed $sVari and returns true if they are below $sVari.
  2213. ;--------------------------------------------------------------------------------------------------------------
  2214.  
  2215. Func getGold($x_start, $y_start)
  2216.     _CaptureRegion(0, 0, $x_start + 90, $y_start + 20)
  2217.     ;-----------------------------------------------------------------------------
  2218.     Local $x = $x_start, $y = $y_start
  2219.     Local $Gold, $i = 0
  2220.     While getDigit($x, $y + $i, "Gold") = ""
  2221.         If $i >= 15 Then ExitLoop
  2222.         $i += 1
  2223.     WEnd
  2224.     $x = $x_start
  2225.     $Gold &= getDigit($x, $y + $i, "Gold")
  2226.     $Gold &= getDigit($x, $y + $i, "Gold")
  2227.     $Gold &= getDigit($x, $y + $i, "Gold")
  2228.     $x += 6
  2229.     $Gold &= getDigit($x, $y + $i, "Gold")
  2230.     $Gold &= getDigit($x, $y + $i, "Gold")
  2231.     $Gold &= getDigit($x, $y + $i, "Gold")
  2232.     Return $Gold
  2233. EndFunc   ;==>getGold
  2234.  
  2235. Func getElixir($x_start, $y_start)
  2236.     _CaptureRegion(0, 0, $x_start + 90, $y_start + 20)
  2237.     ;-----------------------------------------------------------------------------
  2238.     Local $x = $x_start, $y = $y_start
  2239.     Local $Elixir, $i = 0
  2240.     While getDigit($x, $y + $i, "Elixir") = ""
  2241.         If $i >= 15 Then ExitLoop
  2242.         $i += 1
  2243.     WEnd
  2244.     $x = $x_start
  2245.     $Elixir &= getDigit($x, $y + $i, "Elixir")
  2246.     $Elixir &= getDigit($x, $y + $i, "Elixir")
  2247.     $Elixir &= getDigit($x, $y + $i, "Elixir")
  2248.     $x += 6
  2249.     $Elixir &= getDigit($x, $y + $i, "Elixir")
  2250.     $Elixir &= getDigit($x, $y + $i, "Elixir")
  2251.     $Elixir &= getDigit($x, $y + $i, "Elixir")
  2252.     Return $Elixir
  2253. EndFunc   ;==>getElixir
  2254.  
  2255. Func getDarkElixir($x_start, $y_start)
  2256.     _CaptureRegion(0, 0, $x_start + 90, $y_start + 20)
  2257.     ;-----------------------------------------------------------------------------
  2258.     Local $x = $x_start, $y = $y_start
  2259.     Local $DarkElixir, $i = 0
  2260.     While getDigit($x, $y + $i, "DarkElixir") = ""
  2261.         If $i >= 15 Then ExitLoop
  2262.         $i += 1
  2263.     WEnd
  2264.     $x = $x_start
  2265.     $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  2266.     $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  2267.     $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  2268.     $x += 6
  2269.     $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  2270.     $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  2271.     $DarkElixir &= getDigit($x, $y + $i, "DarkElixir")
  2272.     Return $DarkElixir
  2273. EndFunc   ;==>getDarkElixir
  2274.  
  2275. Func getTrophy($x_start, $y_start)
  2276.     _CaptureRegion(0, 0, $x_start + 90, $y_start + 20)
  2277.     ;-----------------------------------------------------------------------------
  2278.     Local $x = $x_start, $y = $y_start
  2279.     Local $Trophy, $i = 0
  2280.     While getDigit($x, $y + $i, "Trophy") = ""
  2281.         If $i >= 15 Then ExitLoop
  2282.         $i += 1
  2283.     WEnd
  2284.     $x = $x_start
  2285.     $Trophy &= getDigit($x, $y + $i, "Trophy")
  2286.     $Trophy &= getDigit($x, $y + $i, "Trophy")
  2287.     Return $Trophy
  2288. EndFunc   ;==>getTrophy
  2289.  
  2290. Func getNormal($x_start, $y_start)
  2291.     _CaptureRegion(0, 0, $x_start + 90, $y_start + 20)
  2292.     ;-----------------------------------------------------------------------------
  2293.     Local $x = $x_start, $y = $y_start
  2294.     Local $Normal, $i = 0
  2295.  
  2296.     $Normal = getDigit($x, $y, "Normal")
  2297.  
  2298.     While $Normal = ""
  2299.         If $i >= 50 Then ExitLoop
  2300.         $i += 1
  2301.         $x += 1
  2302.         $Normal = getDigit($x, $y, "Normal")
  2303.     WEnd
  2304.  
  2305.  
  2306.     $Normal &= getDigit($x, $y, "Normal")
  2307.     $Normal &= getDigit($x, $y, "Normal")
  2308.  
  2309.     Return $Normal
  2310. EndFunc   ;==>getNormal
  2311.  
  2312. Func getOther($x_start, $y_start, $type)
  2313.     _CaptureRegion(0, 0, $x_start + 90, $y_start + 20)
  2314.     ;-----------------------------------------------------------------------------
  2315.     Local $x = $x_start, $y = $y_start
  2316.     Local $Number, $i = 0
  2317.  
  2318.     Switch $type
  2319.         Case "Trophy"
  2320.             $Number = getDigit($x, $y, "Other")
  2321.  
  2322.             While $Number = ""
  2323.                 If $i >= 50 Then ExitLoop
  2324.                 $i += 1
  2325.                 $x += 1
  2326.                 $Number = getDigit($x, $y, "Other")
  2327.             WEnd
  2328.  
  2329.             $Number &= getDigit($x, $y, "Other")
  2330.             $Number &= getDigit($x, $y, "Other")
  2331.             $Number &= getDigit($x, $y, "Other")
  2332.     EndSwitch
  2333.  
  2334.     Return $Number
  2335. EndFunc   ;==>getOther
  2336.  
  2337. ;==============================================================================================================
  2338. ;==============================================================================================================
  2339. ;===Color Variation============================================================================================
  2340. ;--------------------------------------------------------------------------------------------------------------
  2341. ;Checks if the color components exceed $sVari and returns true if they are below $sVari.
  2342. ;--------------------------------------------------------------------------------------------------------------
  2343.  
  2344. Func _ColorCheckVariation($nColor1, $nColor2, $sVari = 5)
  2345.     Local $Red1, $Red2, $Blue1, $Blue2, $Green1, $Green2
  2346.  
  2347.     $Red1 = Dec(StringMid(String($nColor1), 1, 2))
  2348.     $Blue1 = Dec(StringMid(String($nColor1), 3, 2))
  2349.     $Green1 = Dec(StringMid(String($nColor1), 5, 2))
  2350.  
  2351.     $Red2 = Dec(StringMid(String($nColor2), 1, 2))
  2352.     $Blue2 = Dec(StringMid(String($nColor2), 3, 2))
  2353.     $Green2 = Dec(StringMid(String($nColor2), 5, 2))
  2354.  
  2355.     If Abs($Blue1 - $Blue2) > $sVari Then Return False
  2356.     If Abs($Green1 - $Green2) > $sVari Then Return False
  2357.     If Abs($Red1 - $Red2) > $sVari Then Return False
  2358.     Return True
  2359. EndFunc   ;==>_ColorCheckVariation
  2360.  
  2361. ;==============================================================================================================
  2362. ;===Check Pixels===============================================================================================
  2363. ;--------------------------------------------------------------------------------------------------------------
  2364. ;Using _ColorCheckVariation, checks compares multiple pixels and returns true if they all pass _ColorCheckVariation.
  2365. ;--------------------------------------------------------------------------------------------------------------
  2366.  
  2367. Func boolPixelSearch($pixel1, $pixel2, $pixel3)
  2368.     Local $Color1 = _PixelGetColor_GetPixel($pixel1[0], $pixel1[1])
  2369.     Local $Color2 = _PixelGetColor_GetPixel($pixel2[0], $pixel2[1])
  2370.     Local $Color3 = _PixelGetColor_GetPixel($pixel3[0], $pixel3[1])
  2371.     If _ColorCheckVariation($Color1, $pixel1[2], 10) And _ColorCheckVariation($Color2, $pixel2[2], 10) And _ColorCheckVariation($Color3, $pixel3[2], 10) Then Return True
  2372.     Return False
  2373. EndFunc   ;==>boolPixelSearch
  2374.  
  2375. ;==============================================================================================================
  2376. ;===Get Digit Gold=============================================================================================
  2377. ;--------------------------------------------------------------------------------------------------------------
  2378. ;Finds pixel color pattern of specific X and Y values, returns digit if pixel color pattern found.
  2379. ;--------------------------------------------------------------------------------------------------------------
  2380.  
  2381. Func getDigit(ByRef $x, $y, $type)
  2382.     Local $width = 0
  2383.  
  2384.     ;Search for digit 0
  2385.     $width = 13
  2386.     Select
  2387.         Case $type = "Gold"
  2388.             Local $c1 = Hex(0x989579, 6), $c2 = Hex(0x39382E, 6), $c3 = Hex(0x272720, 6)
  2389.         Case $type = "Elixir"
  2390.             Local $c1 = Hex(0x978A96, 6), $c2 = Hex(0x393439, 6), $c3 = Hex(0x272427, 6)
  2391.         Case $type = "DarkElixir"
  2392.             Local $c1 = Hex(0x909090, 6), $c2 = Hex(0x363636, 6), $c3 = Hex(0x262626, 6)
  2393.         Case Else
  2394.             Local $c1 = Hex(0x979797, 6), $c2 = Hex(0x393939, 6), $c3 = Hex(0x272727, 6)
  2395.     EndSelect
  2396.     Local $pixel1[3] = [$x + 6, $y + 4, $c1], $pixel2[3] = [$x + 7, $y + 7, $c2], $pixel3[3] = [$x + 10, $y + 13, $c3]
  2397.     Local $pixel1[3] = [$x + 6, $y + 4, $c1], $pixel2[3] = [$x + 7, $y + 7, $c2], $pixel3[3] = [$x + 10, $y + 13, $c3]
  2398.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2399.         $x += $width ;Adds to x coordinate to get the next digit
  2400.         Return 0
  2401.     Else
  2402.         $x -= 1 ;Solves the problem when the spaces between the middle goes from 6 to 5 pixels
  2403.         Local $pixel1[3] = [$x + 6, $y + 4, $c1], $pixel2[3] = [$x + 7, $y + 7, $c2], $pixel3[3] = [$x + 10, $y + 13, $c3]
  2404.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2405.             $x += $width ;Changes x coordinate for the next digit.
  2406.             Return 0
  2407.         Else
  2408.             $x += 2 ;Solves the problem when there is 1 pixel space between a set of numbers
  2409.             Local $pixel1[3] = [$x + 6, $y + 4, $c1], $pixel2[3] = [$x + 7, $y + 7, $c2], $pixel3[3] = [$x + 10, $y + 13, $c3]
  2410.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2411.                 $x += $width
  2412.                 Return 0
  2413.             Else
  2414.                 $x -= 1
  2415.             EndIf
  2416.         EndIf
  2417.     EndIf
  2418.  
  2419.     ;Search for digit 1
  2420.     $width = 6
  2421.     Select
  2422.         Case $type = "Gold"
  2423.             Local $c1 = Hex(0x979478, 6), $c2 = Hex(0x313127, 6), $c3 = Hex(0xD7D4AC, 6)
  2424.         Case $type = "Elixir"
  2425.             Local $c1 = Hex(0x968895, 6), $c2 = Hex(0x312D31, 6), $c3 = Hex(0xD8C4D6, 6)
  2426.         Case $type = "DarkElixir"
  2427.             Local $c1 = Hex(0x8F8F8F, 6), $c2 = Hex(0x2F2F2F, 6), $c3 = Hex(0xCDCDCD, 6)
  2428.         Case Else
  2429.             Local $c1 = Hex(0x969696, 6), $c2 = Hex(0x313131, 6), $c3 = Hex(0xD8D8D8, 6)
  2430.  
  2431.     EndSelect
  2432.     Local $pixel1[3] = [$x + 1, $y + 1, $c1], $pixel2[3] = [$x + 1, $y + 12, $c2], $pixel3[3] = [$x + 4, $y + 12, $c3]
  2433.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2434.         $x += $width
  2435.         Return 1
  2436.     Else
  2437.         $x -= 1
  2438.         Local $pixel1[3] = [$x + 1, $y + 1, $c1], $pixel2[3] = [$x + 1, $y + 12, $c2], $pixel3[3] = [$x + 4, $y + 12, $c3]
  2439.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2440.             $x += $width
  2441.             Return 1
  2442.         Else
  2443.             $x += 2
  2444.             Local $pixel1[3] = [$x + 1, $y + 1, $c1], $pixel2[3] = [$x + 1, $y + 12, $c2], $pixel3[3] = [$x + 4, $y + 12, $c3]
  2445.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2446.                 $x += $width
  2447.                 Return 1
  2448.             Else
  2449.                 $x -= 1
  2450.             EndIf
  2451.         EndIf
  2452.     EndIf
  2453.  
  2454.     ;Search for digit 2
  2455.     $width = 10
  2456.     Select
  2457.         Case $type = "Gold"
  2458.             Local $c1 = Hex(0xA09E80, 6), $c2 = Hex(0xD8D4AC, 6), $c3 = Hex(0x979579, 6)
  2459.         Case $type = "Elixir"
  2460.             Local $c1 = Hex(0xA0919F, 6), $c2 = Hex(0xD8C4D6, 6), $c3 = Hex(0x978A96, 6)
  2461.         Case $type = "DarkElixir"
  2462.             Local $c1 = Hex(0x989898, 6), $c2 = Hex(0xCDCDCD, 6), $c3 = Hex(0x909090, 6)
  2463.         Case Else
  2464.             Local $c1 = Hex(0xA0A0A0, 6), $c2 = Hex(0xD8D8D8, 6), $c3 = Hex(0x979797, 6)
  2465.     EndSelect
  2466.     Local $pixel1[3] = [$x + 1, $y + 7, $c1], $pixel2[3] = [$x + 3, $y + 6, $c2], $pixel3[3] = [$x + 7, $y + 7, $c3]
  2467.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2468.         $x += $width
  2469.         Return 2
  2470.     Else
  2471.         $x -= 1
  2472.         Local $pixel1[3] = [$x + 1, $y + 7, $c1], $pixel2[3] = [$x + 3, $y + 6, $c2], $pixel3[3] = [$x + 7, $y + 7, $c3]
  2473.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2474.             $x += $width
  2475.             Return 2
  2476.         Else
  2477.             $x += 2
  2478.             Local $pixel1[3] = [$x + 1, $y + 7, $c1], $pixel2[3] = [$x + 3, $y + 6, $c2], $pixel3[3] = [$x + 7, $y + 7, $c3]
  2479.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2480.                 $x += $width
  2481.                 Return 2
  2482.             Else
  2483.                 $x -= 1
  2484.             EndIf
  2485.         EndIf
  2486.     EndIf
  2487.  
  2488.     ;Search for digit 3
  2489.     $width = 10
  2490.     Select
  2491.         Case $type = "Gold"
  2492.             Local $c1 = Hex(0x7F7D65, 6), $c2 = Hex(0x070706, 6), $c3 = Hex(0x37362C, 6)
  2493.         Case $type = "Elixir"
  2494.             Local $c1 = Hex(0x7F737E, 6), $c2 = Hex(0x070607, 6), $c3 = Hex(0x373236, 6)
  2495.         Case $type = "DarkElixir"
  2496.             Local $c1 = Hex(0x797979, 6), $c2 = Hex(0x070707, 6), $c3 = Hex(0x343434, 6)
  2497.         Case Else
  2498.             Local $c1 = Hex(0x7F7F7F, 6), $c2 = Hex(0x070707, 6), $c3 = Hex(0x373737, 6)
  2499.     EndSelect
  2500.     Local $pixel1[3] = [$x + 2, $y + 3, $c1], $pixel2[3] = [$x + 4, $y + 8, $c2], $pixel3[3] = [$x + 5, $y + 13, $c3]
  2501.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2502.         $x += $width
  2503.         Return 3
  2504.     Else
  2505.         $x -= 1
  2506.         Local $pixel1[3] = [$x + 2, $y + 3, $c1], $pixel2[3] = [$x + 4, $y + 8, $c2], $pixel3[3] = [$x + 5, $y + 13, $c3]
  2507.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2508.             $x += $width
  2509.             Return 3
  2510.         Else
  2511.             $x += 2
  2512.             Local $pixel1[3] = [$x + 2, $y + 3, $c1], $pixel2[3] = [$x + 4, $y + 8, $c2], $pixel3[3] = [$x + 5, $y + 13, $c3]
  2513.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2514.                 $x += $width
  2515.                 Return 3
  2516.             Else
  2517.                 $x -= 1
  2518.             EndIf
  2519.         EndIf
  2520.     EndIf
  2521.  
  2522.     ;Search for digit 4
  2523.     $width = 12
  2524.     Select
  2525.         Case $type = "Gold"
  2526.             Local $c1 = Hex(0x282720, 6), $c2 = Hex(0x080806, 6), $c3 = Hex(0x403F33, 6)
  2527.         Case $type = "Elixir"
  2528.             Local $c1 = Hex(0x282428, 6), $c2 = Hex(0x080708, 6), $c3 = Hex(0x403A40, 6)
  2529.         Case $type = "DarkElixir"
  2530.             Local $c1 = Hex(0x262626, 6), $c2 = Hex(0x070707, 6), $c3 = Hex(0x3D3D3D, 6)
  2531.         Case Else
  2532.             Local $c1 = Hex(0x282828, 6), $c2 = Hex(0x080808, 6), $c3 = Hex(0x404040, 6)
  2533.     EndSelect
  2534.     Local $pixel1[3] = [$x + 2, $y + 3, $c1], $pixel2[3] = [$x + 3, $y + 1, $c2], $pixel3[3] = [$x + 1, $y + 5, $c3]
  2535.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2536.         $x += $width
  2537.         Return 4
  2538.     Else
  2539.         $x -= 1
  2540.         Local $pixel1[3] = [$x + 2, $y + 3, $c1], $pixel2[3] = [$x + 3, $y + 1, $c2], $pixel3[3] = [$x + 1, $y + 5, $c3]
  2541.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2542.             $x += $width
  2543.             Return 4
  2544.         Else
  2545.             $x += 2
  2546.             Local $pixel1[3] = [$x + 2, $y + 3, $c1], $pixel2[3] = [$x + 3, $y + 1, $c2], $pixel3[3] = [$x + 1, $y + 5, $c3]
  2547.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2548.                 $x += $width
  2549.                 Return 4
  2550.             Else
  2551.                 $x -= 1
  2552.             EndIf
  2553.         EndIf
  2554.     EndIf
  2555.  
  2556.     ;Search for digit 5
  2557.     $width = 10
  2558.     Select
  2559.         Case $type = "Gold"
  2560.             Local $c1 = Hex(0x060604, 6), $c2 = Hex(0x040403, 6), $c3 = Hex(0xB7B492, 6)
  2561.         Case $type = "Elixir"
  2562.             Local $c1 = Hex(0x060606, 6), $c2 = Hex(0x040404, 6), $c3 = Hex(0xB7A7B6, 6)
  2563.         Case $type = "DarkElixir"
  2564.             Local $c1 = Hex(0x060606, 6), $c2 = Hex(0x040404, 6), $c3 = Hex(0xAFAFAF, 6)
  2565.         Case Else
  2566.             Local $c1 = Hex(0x060606, 6), $c2 = Hex(0x040404, 6), $c3 = Hex(0xB7B7B7, 6)
  2567.     EndSelect
  2568.     Local $pixel1[3] = [$x + 5, $y + 4, $c1], $pixel2[3] = [$x + 4, $y + 9, $c2], $pixel3[3] = [$x + 6, $y + 12, $c3]
  2569.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2570.         $x += $width
  2571.         Return 5
  2572.     Else
  2573.         $x -= 1
  2574.         Local $pixel1[3] = [$x + 5, $y + 4, $c1], $pixel2[3] = [$x + 4, $y + 9, $c2], $pixel3[3] = [$x + 6, $y + 12, $c3]
  2575.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2576.             $x += $width
  2577.             Return 5
  2578.         Else
  2579.             $x += 2
  2580.             Local $pixel1[3] = [$x + 5, $y + 4, $c1], $pixel2[3] = [$x + 4, $y + 9, $c2], $pixel3[3] = [$x + 6, $y + 12, $c3]
  2581.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2582.                 $x += $width
  2583.                 Return 5
  2584.             Else
  2585.                 $x -= 1
  2586.             EndIf
  2587.         EndIf
  2588.     EndIf
  2589.  
  2590.     ;Search for digit 6
  2591.     $width = 11
  2592.     Select
  2593.         Case $type = "Gold"
  2594.             Local $c1 = Hex(0x070605, 6), $c2 = Hex(0x040403, 6), $c3 = Hex(0x181713, 6)
  2595.         Case $type = "Elixir"
  2596.             Local $c1 = Hex(0x070707, 6), $c2 = Hex(0x040404, 6), $c3 = Hex(0x181618, 6)
  2597.         Case $type = "DarkElixir"
  2598.             Local $c1 = Hex(0x060606, 6), $c2 = Hex(0x030303, 6), $c3 = Hex(0x161616, 6)
  2599.         Case Else
  2600.             Local $c1 = Hex(0x070707, 6), $c2 = Hex(0x040404, 6), $c3 = Hex(0x181818, 6)
  2601.     EndSelect
  2602.     Local $pixel1[3] = [$x + 5, $y + 4, $c1], $pixel2[3] = [$x + 5, $y + 9, $c2], $pixel3[3] = [$x + 8, $y + 5, $c3]
  2603.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2604.         $x += $width
  2605.         Return 6
  2606.     Else
  2607.         $x -= 1
  2608.         Local $pixel1[3] = [$x + 5, $y + 4, $c1], $pixel2[3] = [$x + 5, $y + 9, $c2], $pixel3[3] = [$x + 8, $y + 5, $c3]
  2609.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2610.             $x += $width
  2611.             Return 6
  2612.         Else
  2613.             $x += 2
  2614.             Local $pixel1[3] = [$x + 5, $y + 4, $c1], $pixel2[3] = [$x + 5, $y + 9, $c2], $pixel3[3] = [$x + 8, $y + 5, $c3]
  2615.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2616.                 $x += $width
  2617.                 Return 6
  2618.             Else
  2619.                 $x -= 1
  2620.             EndIf
  2621.         EndIf
  2622.     EndIf
  2623.  
  2624.     ;Search for digit 7
  2625.     $width = 10
  2626.     Select
  2627.         Case $type = "Gold"
  2628.             Local $c1 = Hex(0x5E5C4B, 6), $c2 = Hex(0x87856C, 6), $c3 = Hex(0x5D5C4B, 6)
  2629.         Case $type = "Elixir"
  2630.             Local $c1 = Hex(0x5F565E, 6), $c2 = Hex(0x877B86, 6), $c3 = Hex(0x5F565E, 6)
  2631.         Case $type = "DarkElixir"
  2632.             Local $c1 = Hex(0x5A5A5A, 6), $c2 = Hex(0x818181, 6), $c3 = Hex(0x5A5A5A, 6)
  2633.         Case Else
  2634.             Local $c1 = Hex(0x5F5F5F, 6), $c2 = Hex(0x878787, 6), $c3 = Hex(0x5F5F5F, 6)
  2635.     EndSelect
  2636.     Local $pixel1[3] = [$x + 5, $y + 11, $c1], $pixel2[3] = [$x + 4, $y + 3, $c2], $pixel3[3] = [$x + 7, $y + 7, $c3]
  2637.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2638.         $x += $width
  2639.         Return 7
  2640.     Else
  2641.         $x -= 1
  2642.         Local $pixel1[3] = [$x + 5, $y + 11, $c1], $pixel2[3] = [$x + 4, $y + 3, $c2], $pixel3[3] = [$x + 7, $y + 7, $c3]
  2643.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2644.             $x += $width
  2645.             Return 7
  2646.         Else
  2647.             $x += 2
  2648.             Local $pixel1[3] = [$x + 5, $y + 11, $c1], $pixel2[3] = [$x + 4, $y + 3, $c2], $pixel3[3] = [$x + 7, $y + 7, $c3]
  2649.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2650.                 $x += $width
  2651.                 Return 7
  2652.             Else
  2653.                 $x -= 1
  2654.             EndIf
  2655.         EndIf
  2656.     EndIf
  2657.  
  2658.     ;Search for digit 8
  2659.     $width = 11
  2660.     Select
  2661.         Case $type = "Gold"
  2662.             Local $c1 = Hex(0x27261F, 6), $c2 = Hex(0x302F26, 6), $c3 = Hex(0x26261F, 6)
  2663.         Case $type = "Elixir"
  2664.             Local $c1 = Hex(0x272427, 6), $c2 = Hex(0x302B2F, 6), $c3 = Hex(0x26261F, 6)
  2665.         Case $type = "DarkElixir"
  2666.             Local $c1 = Hex(0x252525, 6), $c2 = Hex(0x2D2D2D, 6), $c3 = Hex(0x242424, 6)
  2667.         Case Else
  2668.             Local $c1 = Hex(0x272727, 6), $c2 = Hex(0x303030, 6), $c3 = Hex(0x262626, 6)
  2669.     EndSelect
  2670.     Local $pixel1[3] = [$x + 5, $y + 3, $c1], $pixel2[3] = [$x + 5, $y + 10, $c2], $pixel3[3] = [$x + 1, $y + 6, $c3]
  2671.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2672.         $x += $width
  2673.         Return 8
  2674.     Else
  2675.         $x -= 1
  2676.         Local $pixel1[3] = [$x + 5, $y + 3, $c1], $pixel2[3] = [$x + 5, $y + 10, $c2], $pixel3[3] = [$x + 1, $y + 6, $c3]
  2677.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2678.             $x += $width
  2679.             Return 8
  2680.         Else
  2681.             $x += 2
  2682.             Local $pixel1[3] = [$x + 5, $y + 3, $c1], $pixel2[3] = [$x + 5, $y + 10, $c2], $pixel3[3] = [$x + 1, $y + 6, $c3]
  2683.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2684.                 $x += $width
  2685.                 Return 8
  2686.             Else
  2687.                 $x -= 1
  2688.             EndIf
  2689.         EndIf
  2690.     EndIf
  2691.  
  2692.     ;Search for digit 9
  2693.     $width = 11
  2694.     Select
  2695.         Case $type = "Gold"
  2696.             Local $c1 = Hex(0x302F26, 6), $c2 = Hex(0x050504, 6), $c3 = Hex(0x272720, 6)
  2697.         Case $type = "Elixir"
  2698.             Local $c1 = Hex(0x302C30, 6), $c2 = Hex(0x050505, 6), $c3 = Hex(0x282427, 6)
  2699.         Case $type = "DarkElixir"
  2700.             Local $c1 = Hex(0x2E2E2E, 6), $c2 = Hex(0x050505, 6), $c3 = Hex(0x262626, 6)
  2701.         Case Else
  2702.             Local $c1 = Hex(0x303030, 6), $c2 = Hex(0x050505, 6), $c3 = Hex(0x272727, 6)
  2703.     EndSelect
  2704.     Local $pixel1[3] = [$x + 5, $y + 5, $c1], $pixel2[3] = [$x + 5, $y + 9, $c2], $pixel3[3] = [$x + 8, $y + 12, $c3]
  2705.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2706.         $x += $width
  2707.         Return 9
  2708.     Else
  2709.         $x -= 1
  2710.         Local $pixel1[3] = [$x + 5, $y + 5, $c1], $pixel2[3] = [$x + 5, $y + 9, $c2], $pixel3[3] = [$x + 8, $y + 12, $c3]
  2711.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2712.             $x += $width
  2713.             Return 9
  2714.         Else
  2715.             $x += 2
  2716.             Local $pixel1[3] = [$x + 5, $y + 5, $c1], $pixel2[3] = [$x + 5, $y + 9, $c2], $pixel3[3] = [$x + 8, $y + 12, $c3]
  2717.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2718.                 $x += $width
  2719.                 Return 9
  2720.             Else
  2721.                 $x -= 1
  2722.             EndIf
  2723.         EndIf
  2724.     EndIf
  2725.  
  2726.     ;Search for digit 74
  2727.     $width = 21
  2728.     Select
  2729.         Case $type = "Gold"
  2730.             Local $c1 = Hex(0x414034, 6), $c2 = Hex(0x4C4B3D, 6), $c3 = Hex(0xD3D0A9, 6)
  2731.         Case $type = "Elixir"
  2732.             Local $c1 = Hex(0x413E38, 6), $c2 = Hex(0x4C4941, 6), $c3 = Hex(0xD3CEAB, 6)
  2733.         Case $type = "DarkElixir"
  2734.             Local $c1 = Hex(0x3F3F3F, 6), $c2 = Hex(0x4A4A4A, 6), $c3 = Hex(0xD1D1D1, 6)
  2735.         Case Else
  2736.             Local $c1 = Hex(0x414141, 6), $c2 = Hex(0x4C4C4C, 6), $c3 = Hex(0xD3D3D3, 6)
  2737.     EndSelect
  2738.     Local $pixel1[3] = [$x + 13, $y + 7, $c1], $pixel2[3] = [$x + 7, $y + 7, $c2], $pixel3[3] = [$x + 1, $y + 12, $c3]
  2739.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2740.         $x += $width
  2741.         Return 9
  2742.     Else
  2743.         $x -= 1
  2744.         Local $pixel1[3] = [$x + 13, $y + 7, $c1], $pixel2[3] = [$x + 7, $y + 7, $c2], $pixel3[3] = [$x + 1, $y + 12, $c3]
  2745.         If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2746.             $x += $width
  2747.             Return 9
  2748.         Else
  2749.             $x += 2
  2750.             Local $pixel1[3] = [$x + 13, $y + 7, $c1], $pixel2[3] = [$x + 7, $y + 7, $c2], $pixel3[3] = [$x + 1, $y + 12, $c3]
  2751.             If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  2752.                 $x += $width
  2753.                 Return 9
  2754.             Else
  2755.                 $x -= 1
  2756.             EndIf
  2757.         EndIf
  2758.     EndIf
  2759.     Return ""
  2760. EndFunc   ;==>getDigit
  2761.  
  2762. ;==============================================================================================================
  2763. ;===Other Functions============================================================================================
  2764. ;==============================================================================================================
  2765.  
  2766. Func _CaptureRegion($iLeft = 0, $iTop = 0, $iRight = 860, $iBottom = 720, $ReturnBMP = False)
  2767.     _GDIPlus_BitmapDispose($hBitmap)
  2768.     _WinAPI_DeleteObject($hHBitmap)
  2769.  
  2770.     If $ichkBackground = 1 Then
  2771.         Local $iW = Number($iRight) - Number($iLeft), $iH = Number($iBottom) - Number($iTop)
  2772.  
  2773.         Local $hDC_Capture = _WinAPI_GetWindowDC(ControlGetHandle("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]"))
  2774.         Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
  2775.         $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $iW, $iH)
  2776.         Local $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
  2777.  
  2778.         DllCall("user32.dll", "int", "PrintWindow", "hwnd", $HWnD, "handle", $hMemDC, "int", 0)
  2779.         _WinAPI_SelectObject($hMemDC, $hHBitmap)
  2780.         _WinAPI_BitBlt($hMemDC, 0, 0, $iW, $iH, $hDC_Capture, $iLeft, $iTop, 0x00CC0020)
  2781.  
  2782.         Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
  2783.  
  2784.         _WinAPI_DeleteDC($hMemDC)
  2785.         _WinAPI_SelectObject($hMemDC, $hObjectOld)
  2786.         _WinAPI_ReleaseDC($HWnD, $hDC_Capture)
  2787.     Else
  2788.         getBSPos()
  2789.         $hHBitmap = _ScreenCapture_Capture("", $iLeft + $BSpos[0], $iTop + $BSpos[1], $iRight + $BSpos[0], $iBottom + $BSpos[1])
  2790.         Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
  2791.     EndIf
  2792.  
  2793.     If $ReturnBMP Then Return $hBitmap
  2794. EndFunc   ;==>_CaptureRegion
  2795.  
  2796. Func _PixelGetColor_GetPixel($iX, $iY)
  2797.     Local $aPixelColor = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
  2798.     Return Hex($aPixelColor, 6)
  2799. EndFunc   ;==>_PixelGetColor_GetPixel
  2800.  
  2801. Func _PixelSearch($iLeft, $iTop, $iRight, $iBottom, $iColor, $iColorVariation)
  2802.     _CaptureRegion($iLeft, $iTop, $iRight, $iBottom)
  2803.     For $x = $iRight - $iLeft To 0 Step -1
  2804.         For $y = $iBottom - $iTop To 0 Step -1
  2805.             Local $nColor1 = $iColor
  2806.             Local $nColor2 = _PixelGetColor_GetPixel($x, $y)
  2807.             If _ColorCheckVariation($nColor1, $nColor2, $iColorVariation) Then
  2808.                 Local $Pos[2] = [$iLeft + $x, $iTop + $y]
  2809.                 Return $Pos
  2810.             EndIf
  2811.         Next
  2812.     Next
  2813.     Return 0
  2814. EndFunc   ;==>_PixelSearch
  2815.  
  2816.  
  2817. #EndRegion ### Get Resources+Get Pixels Functions ###
  2818. ;---------------------------------------------------
  2819. #Region ### Check Dead Base Functions ###
  2820. ;==============================================================================================================
  2821. ;===Main Function==============================================================================================
  2822. ;--------------------------------------------------------------------------------------------------------------
  2823. ;Uses imagesearch to see whether a collector is full or semi-full to indicate that it is a dead base
  2824. ;Returns True if it is, returns false if it is not a dead base
  2825. ;--------------------------------------------------------------------------------------------------------------
  2826.  
  2827. Func ZombieSearch()
  2828.     ;GUICtrlSetData($Results, "Checking for Zombie. Tolerance: " & $Tolerance & @CRLF, -1)
  2829.     $ZombieCount = 0
  2830.     For $i = 0 To 3 Step 1 ;Search per area
  2831.         IS_Area($i, $Tolerance)
  2832.         $ZombieCount += $ZC
  2833.     Next
  2834.     If $ZombieCount > 0 Then ;if $ZombieCount =1 : $Tolerance=50
  2835.         ;GUICtrlSetData($Results, "Zombie detected. $ZombieCount = " & $ZombieCount & @CRLF, -1)
  2836.         Return True
  2837.     Else
  2838.         ;GUICtrlSetData($Results, "Not Zombie. $ZombieCount = " & $ZombieCount & @CRLF, -1)
  2839.         Return False
  2840.     EndIf
  2841. EndFunc   ;==>ZombieSearch
  2842.  
  2843. Func IS_Area($i, $Tolerance) ;Search per area then search per file. If not succeed variant 1 proceed 2 else proceed 3.
  2844.     $ZC = 0
  2845.     For $s = 0 To ($ZombieFileSets - 1) Step 1
  2846.         For $p = 0 To 4 Step 1
  2847.             $Area[$p][$i] = _ImageSearchArea($E[$s][$p], 0, $Lx[$i], $Ly[$i], $Rx[$i], $Ry[$i], $IS_x[$p][$i], $IS_y[$p][$i], $Tolerance)
  2848.             If $Area[$p][$i] > 0 Then
  2849.                 $ZC = 1
  2850.                 ExitLoop (2)
  2851.             EndIf
  2852.         Next
  2853.     Next
  2854. EndFunc   ;==>IS_Area
  2855.  
  2856. ;==============================================================================================================
  2857. ;===Other Functions============================================================================================
  2858. ;==============================================================================================================
  2859.  
  2860. Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $Tolerance, $HBMP = 0)
  2861.     Return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $Tolerance, $HBMP)
  2862. EndFunc   ;==>_ImageSearch
  2863.  
  2864. Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $Right, $Bottom, ByRef $x, ByRef $y, $Tolerance, $HBMP = 0)
  2865.     ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
  2866.     If $Tolerance > 0 Then $findImage = "*" & $Tolerance & " " & $findImage
  2867.     #cs
  2868.         If IsString($findImage) Then
  2869.         $result = DllCall("COCBot64.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
  2870.         If IsArray($result) = False Then $result = DllCall("COCBot32.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
  2871.         Else
  2872.         $result = DllCall("COCBot64.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP)
  2873.         If IsArray($result) = False Then $result = DllCall("COCBot32.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP)
  2874.         EndIf
  2875.     #ce
  2876.     Switch @OSArch
  2877.         Case "X64"
  2878.             If IsString($findImage) Then
  2879.                 $result = DllCall("COCBot64.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $Right, "int", $Bottom, "str", $findImage, "ptr", $HBMP)
  2880.             Else
  2881.                 $result = DllCall("COCBot64.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $Right, "int", $Bottom, "ptr", $findImage, "ptr", $HBMP)
  2882.             EndIf
  2883.         Case "X86"
  2884.             If IsString($findImage) Then
  2885.                 $result = DllCall("COCBot32.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $Right, "int", $Bottom, "str", $findImage, "ptr", $HBMP)
  2886.             Else
  2887.                 $result = DllCall("COCBot32.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $Right, "int", $Bottom, "ptr", $findImage, "ptr", $HBMP)
  2888.             EndIf
  2889.     EndSwitch
  2890.  
  2891.     ; If error exit
  2892.     If IsArray($result) Then
  2893.         If $result[0] = "0" Then Return 0
  2894.     Else
  2895.         SetLog("Error cannot check for Dead Base, Attacking...")
  2896.         Return 1
  2897.     EndIf
  2898.  
  2899.     ; Otherwise get the x,y location of the match and the size of the image to
  2900.     ; compute the centre of search
  2901.     $array = StringSplit($result[0], "|")
  2902.  
  2903.     $x = Int(Number($array[2]))
  2904.     $y = Int(Number($array[3]))
  2905.     If $resultPosition = 1 Then
  2906.         $x = $x + Int(Number($array[4]) / 2)
  2907.         $y = $y + Int(Number($array[5]) / 2)
  2908.     EndIf
  2909.     Return 1
  2910. EndFunc   ;==>_ImageSearchArea
  2911. #EndRegion ### Check Dead Base Functions ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement