Advertisement
CocBotTBC

v5.4.2.3

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