Advertisement
Guest User

Untitled

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