12-15-2014, 04:25 PM
I've added a small feature to the Search Function script to help see the data from which is returned when tesseract reads the gold and elixir.
It is basically a textbox, like in LF Robot, that displays the gold and elixir everytime it searches.
It is basically a textbox, like in LF Robot, that displays the gold and elixir everytime it searches.
Code:
#RequireAdmin
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>
#include <Misc.au3>
#include "Tesseract.au3"
Opt ("MouseClickDelay", 10)
Opt ("MouseClickDownDelay", 10)
Opt ("MouseCoordMode", 0)
Opt ('PixelCoordMode', 0)
$Title = "BlueStacks App Player"
$Full = WinGetTitle ($Title)
$HWnD = WinGetHandle ($Full)
WinActivate ($HWnD)
Global $Left = 45, $Top = 70, $Right = 660, $Bottom = 490
Global $BSsize = WinGetClientSize($hWnd)
Global $x_ratio = $BSsize[0]/800, $y_ratio = $BSsize[1]/600
Global $Gold, $Elixir, $MinGold = 50000, $MinElixir = 50000, $SearchCount = 0
Global $SearchMode = 1, $SearchCheck = 0, $ErrorCheck = 0
HotKeySet("+{ESC}","Terminate")
#Region ### GUI ###
$BotGUI = GUICreate("Clash of Clans Bot", 280, 500)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
$MeetAll = GUICtrlCreateCheckbox("Meet all conditions", 150, 20, 140, 17)
GUICtrlCreateLabel("Min Gold:", 150, 48, 58, 17)
$MinGoldInput = GUICtrlCreateInput("", 200, 44, 55, 21, $ES_NUMBER)
GUICtrlSetLimit(-1, 6)
GUICtrlCreateLabel("Min Elixir:", 150, 72, 57, 17)
$MinElixirInput = GUICtrlCreateInput("", 200, 68, 55, 21, $ES_NUMBER)
GUICtrlSetLimit(-1, 6)
$Barrack01 = GUICtrlCreateCombo("Barrack 01", 30, 16, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
$Barrack02 = GUICtrlCreateCombo("Barrack 02", 30, 40, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
$Barrack03 = GUICtrlCreateCombo("Barrack 03", 30, 64, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
$Barrack04 = GUICtrlCreateCombo("Barrack 04", 30, 88, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
$StartButton = GUICtrlCreateButton("START (Shift+ESC to Exit)", 30, 120, 220, 40)
$Results = GUICtrlCreateEdit("", 10, 170, 260, 300)
GUISetState(@SW_SHOW)
#EndRegion ### GUI ###
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
$ExitCheck = MsgBox(4+65536, "Confirm Exit", "Are you sure you want to exit?", 0, $BotGUI)
If $ExitCheck = 6 Then
Exit
EndIf
Case $StartButton
Start()
EndSwitch
WEnd
Func Start()
ControlClick ($HWnD, "","", "left", "1", 715*$x_ratio, 405*$y_ratio)
;While 1
;CheckIdle() ;Check disconnect message and click on reload
GetInput() ;Read user's input
;ZoomOut()
;LocateBarrack() ;If barrack not located, ask user to manually click on barrack to locate position
;Train() ;Train troop according to user's input
;Sleep(900000) ;Wait 15 mins for troops training
;AssignTroop() ;Assign troop type to troop position in attack (unfinished)
;PrepareAttack() ;Click Attack
VillageSearch()
;DropTroop() ;Drop troop in order: Giant, Barbarian, Archer (unfinished)
;DropAll() ;Drop everything
;Sleep(180000) ;Wait 3 mins
;ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 450*$y_ratio) ;Click Return Home
;Sleep(10000)
;WEnd
EndFunc
Func GetInput()
$MinGold = Number(GUICtrlRead($MinGoldInput))
$MinElixir = Number(GUICtrlRead($MinElixirInput))
If GUICtrlRead($MeetAll) = $GUI_CHECKED Then
$SearchMode = 2
Else
$SearchMode = 1
EndIf
EndFunc
Func CheckScreen()
Local $Check = ""
$i = 0
While $Check = ""
$Check = _TesseractWinCapture($HWnD,"",0,"",1,2,$Left*$x_ratio,$Top*$y_ratio,$Right*$x_ratio,$Bottom*$y_ratio,0)
$Check = StringStripWS($Check, 8)
Sleep(200)
$i += 1
If $i > 150 Then
MsgBox(0,"Search Time Out","Exiting..")
Exit
EndIf
WEnd
EndFunc
Func VillageSearch()
CheckScreen()
ReadValue()
CompareValue()
While $SearchCheck = 0
ControlClick ($HWnD, "","", "left", "1", 715*$x_ratio, 405*$y_ratio) ;Click Next
CheckScreen()
ReadValue()
CompareValue()
WEnd
TrayTip ("Enemy Found!","Requirement met: Gold: " & $Gold & ". Elixir: " & $Elixir, 0, $TIP_ICONASTERISK)
EndFunc
Func ReadValue()
$Read = _TesseractWinCapture($HWnD,"",0,"",1,2,($Left+10)*$x_ratio,($Top + 10)*$y_ratio,($Right)*$x_ratio,($Bottom)*$y_ratio,0) ;Capture screen region with gold and elixir
$Read = StringRegExpReplace(StringRegExpReplace($Read, "(\v)+", @CRLF), "\A\v|\v\Z", "")
$Read = StringSplit($Read, @CRLF, 1) ;Strip whitespaces & blank lines and split into array
$Gold = Number(StringRegExpReplace($Read[1], "[^[:digit:]]", "")) ;Convert gold to number
$Elixir = Number(StringRegExpReplace($Read[2], "[^[:digit:]]", "")) ;Convert exlir to number
GUICtrlSetData(-1, "(" & $SearchCount & ") Gold: " & $Gold & ". Elixir: " & $Elixir & @CRLF & String(GUICtrlRead($Results))) ;Sends Gold and Elixir to textbox
$SearchCount = $SearchCount + 1 ; Counter for number of searches
Sleep(2000)
EndFunc
Func CompareValue()
If $Gold >= $MinGold Then
If $Elixir >= $MinElixir Then
Select
Case $SearchMode = 1
$SearchCheck = 1
Case $SearchMode = 2
$SearchCheck = 1
Case Else
$SearchCheck = 0
EndSelect
Else
Select
Case $SearchMode = 1
$SearchCheck = 1
Case $SearchMode = 2
$SearchCheck = 0
Case Else
$SearchCheck = 0
EndSelect
EndIf
Else
If $Elixir >= $MinElixir Then
Select
Case $SearchMode = 1
$SearchCheck = 1
Case $SearchMode = 2
$SearchCheck = 0
Case Else
$SearchCheck = 0
EndSelect
Else
Select
Case $SearchMode = 1
$SearchCheck = 0
Case $SearchMode = 2
$SearchCheck = 0
Case Else
$SearchCheck = 0
EndSelect
EndIf
EndIf
EndFunc