Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Made a function to get exact amount of troops in camp
#1
NB: camp location is hard coded!!! this need to be changed to locate camp and use those coords!

this is for the devs that want to use this in their bot version
enclosed files reads the exact amount of troops in camp. this way you can start when troop in camp is >95%
nb: in the last script the camp location is hard coded. this need to be changed to do a locate, just like barracks
I've tested it, it works 100% for me
functions\Read Text\getCamp.au3
Code:
;==============================================================================================================
;===Get Digit=============================================================================================
;--------------------------------------------------------------------------------------------------------------
;Finds pixel color pattern of specific X and Y values, returns digit if pixel color pattern found.
;--------------------------------------------------------------------------------------------------------------
Func getCamp(ByRef $x, $y, $type)
Local $width = 0
;Search for digit 1
$width = 5
Select
Case $type = "Gold"
Local $c1 = Hex(0x070706, 6), $c2 = Hex(0xbebebe, 6), $c3 = Hex(0x9c9c9c, 6)
EndSelect
Local $pixel1[3] = [$x + 1, $y , $c1], $pixel2[3] = [$x + 2, $y + 3, $c2], $pixel3[3] = [$x + 2, $y + 9, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 1
Else ;Solves the problem when the spaces between the middle goes from 6 to 5 pixels
Local $pixel1[3] = [$x , $y , $c1], $pixel2[3] = [$x + 1, $y + 3, $c2], $pixel3[3] = [$x + 1, $y + 9, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 1
EndIf
EndIf
;Search for digit 2
$width = 8
Select
Case $type = "Gold"
Local $c1 = Hex(0x9f9f9f, 6), $c2 = Hex(0x010101, 6), $c3 = Hex(0x060606, 6)
EndSelect
Local $pixel1[3] = [$x + 4, $y + 7 , $c1], $pixel2[3] = [$x + 6, $y + 7, $c2], $pixel3[3] = [$x + 2, $y + 3, $c3]
;= [$x +1 , $y + 8, $c2], $pixel3[3] = [$x + 4, $y + 9, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 2
Else ;Solves the problem when the spaces between the middle goes from 6 to 5 pixels
Local $pixel1[3] = [$x + 3, $y + 7 , $c1], $pixel2[3] = [$x + 5, $y + 7, $c2], $pixel3[3] = [$x + 1, $y + 3, $c3]
;= [$x +1 , $y + 8, $c2], $pixel3[3] = [$x + 4, $y + 9, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 2
EndIf
EndIf
;Search for digit 3
$width = 8
Select
Case $type = "Gold"
Local $c1 = Hex(0x0e0e0e, 6), $c2 = Hex(0x000000, 6), $c3 = Hex(0x191919, 6)
EndSelect
Local $pixel1[3] = [$x + 4, $y + 3 , $c1], $pixel2[3] = [$x + 2, $y + 5, $c2], $pixel3[3] = [$x + 4, $y + 7, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 3
Else
Local $pixel1[3] = [$x + 3, $y + 3 , $c1], $pixel2[3] = [$x + 1, $y + 5, $c2], $pixel3[3] = [$x + 3, $y + 7, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 3
EndIf
EndIf
;Get digit 4
$width = 9
Select
Case $type = "Gold"
Local $c1 = Hex(0xb0b0b0, 6), $c2 = Hex(0xc9c9c9, 6), $c3 = Hex(0x7b7b7b, 6)
EndSelect
Local $pixel1[3] = [$x + 3, $y + 2, $c1], $pixel2[3] = [$x + 2, $y + 4, $c2], $pixel3[3] = [$x + 1, $y + 7, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 4
Else
Local $pixel1[3] = [$x + 2, $y + 2, $c1], $pixel2[3] = [$x + 1, $y + 4, $c2], $pixel3[3] = [$x , $y + 7, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 4
EndIf
EndIf
;Digit is 5
$width = 8
Select
Case $type = "Gold"
Local $c1 = Hex(0xb7b7b7, 6), $c2 = Hex(0x404040, 6), $c3 = Hex(0xa6a6a6, 6)
EndSelect
Local $pixel1[3] = [$x + 2, $y + 8 , $c1], $pixel2[3] = [$x + 1, $y + 1, $c2], $pixel3[3] = [$x + 4, $y + 6, $c3]
;= [$x +1 , $y + 8, $c2], $pixel3[3] = [$x + 4, $y + 9, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 5
Else
Local $pixel1[3] = [$x + 1, $y + 8 , $c1], $pixel2[3] = [$x , $y + 1, $c2], $pixel3[3] = [$x + 3, $y + 6, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 5
EndIf
EndIf
;Digit is 6
$width = 9
Select
Case $type = "Gold"
Local $c1 = Hex(0xa6a6a6, 6), $c2 = Hex(0x040404, 6), $c3 = Hex(0x030303, 6)
EndSelect
Local $pixel1[3] = [$x + 4, $y + 3 , $c1], $pixel2[3] = [$x + 5, $y + 7, $c2], $pixel3[3] = [$x + 7, $y + 3, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 6
Else
Local $pixel1[3] = [$x + 3, $y + 3 , $c1], $pixel2[3] = [$x + 4, $y + 7, $c2], $pixel3[3] = [$x + 6, $y + 3, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 6
EndIf
EndIf
;Digit is 7
$width = 8
Select
Case $type = "Gold"
Local $c1 = Hex(0xbfbfbf, 6), $c2 = Hex(0xcfcfcf, 6), $c3 = Hex(0xcfcfcf, 6)
EndSelect
Local $pixel1[3] = [$x + 4, $y + 2 , $c1], $pixel2[3] = [$x + 7, $y + 3, $c2], $pixel3[3] = [$x + 6, $y + 5, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 7
Else
Local $pixel1[3] = [$x + 3, $y + 2 , $c1], $pixel2[3] = [$x + 6, $y + 3, $c2], $pixel3[3] = [$x + 5, $y + 5, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 7
EndIf
EndIf
;Digit is 8
$width = 9
Select
Case $type = "Gold"
Local $c1 = Hex(0xd0d0d0, 6), $c2 = Hex(0x6f6f6f, 6), $c3 = Hex(0x040404, 6)
EndSelect
Local $pixel1[3] = [$x + 5, $y + 4 , $c1], $pixel2[3] = [$x + 5, $y + 2, $c2], $pixel3[3] = [$x + 5, $y + 7, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 8
Else
Local $pixel1[3] = [$x + 4, $y + 4 , $c1], $pixel2[3] = [$x + 4, $y + 2, $c2], $pixel3[3] = [$x + 4, $y + 7, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 8
EndIf
EndIf
;Digit is 9
$width = 9
Select
Case $type = "Gold"
Local $c1 = Hex(0xbfbfbf, 6), $c2 = Hex(0x4d4d4d, 6), $c3 = Hex(0x070707, 6)
EndSelect
Local $pixel1[3] = [$x + 5, $y + 6 , $c1], $pixel2[3] = [$x + 5, $y + 7, $c2], $pixel3[3] = [$x + 5, $y + 3, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 9
Else
Local $pixel1[3] = [$x + 4, $y + 6 , $c1], $pixel2[3] = [$x + 4, $y + 7, $c2], $pixel3[3] = [$x + 4, $y + 3, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 9
EndIf
EndIf
;Digit is 0
$width = 10
Select
Case $type = "Gold"
Local $c1 = Hex(0x050505, 6), $c2 = Hex(0x080808, 6), $c3 = Hex(0xbdbdbd, 6)
EndSelect
Local $pixel1[3] = [$x + 5, $y + 4 , $c1], $pixel2[3] = [$x + 6, $y + 6, $c2], $pixel3[3] = [$x + 4, $y + 6, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 0
Else
Local $pixel1[3] = [$x + 4, $y + 4 , $c1], $pixel2[3] = [$x + 5, $y + 6, $c2], $pixel3[3] = [$x + 3, $y + 6, $c3]
If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
$x += $width
Return 0
EndIf
EndIf
Return ""
EndFunc ;==>getDigit
functions\Read Text\fullCamp.au3
Code:
Func fullCamp($x_start, $y_start)
_CaptureRegion($x_start, $y_start, $x_start + 30, $y_start + 12)
;-----------------------------------------------------------------------------
;cause our picture is not the complete bs window, reset x and y
Local $x = 2, $y = 1
Local $Gold, $tests,$kweet, $tweede, $derde, $i = 0
$Gold = getCamp($x, $y, "Gold")
While $Gold = ""
If $i >= 4 Then ExitLoop
$i += 1
$x += 1
$Gold &= getCamp($x, $y, "Gold")
WEnd
;$x = 1
;while $x < 10
            ;   $tests = _GetPixelColor($x, $y)
            ;   setlog("y = 1 en x " & $x & " en " & $tests)
             ;  $tests = _GetPixelColor($x, $y + 1)
            ;   setlog("y = 2 en x " & $x & " en " & $tests)
            ;   $x += 1
           ; WEnd

            ;$x = 1
            $Gold &= getCamp($x, $y, "Gold")
            $Gold &= getCamp($x, $y, "Gold")
            ;$Gold &= getCamp($x, $y, "Gold")
            ;$Gold &= getCamp($x, $y, "Gold")
         setlog("final waarde " & $Gold )

    Return $Gold
EndFunc


and the final function to run it all
NB: the camp location need to be fixed. in this script its hard coded and need to be change to locate camp just like barracks,
functions\Village\CheckFullArmy.au3
Code:
;checks camp to see how much troops are in it. if troops > 95% we attack
Func CheckFullArmy()

   ClickP($TopLeftClient)
   Sleep(1000)
    Click(506,462)  ;need to make this the same as barracks, locate 1 camp!
    sleep(2000)
    Click(380,600)
    sleep(2000)
    local $result = fullCamp(586, 192)
    if ($result / $icmbTroopCap * 100) > 95 Then
       $fullArmy = true
       Setlog("Lets Attack! " & $result & " of total " & $icmbTroopCap & " Troops")
       ClickP($TopLeftClient)
       return True
    Else
      Setlog("Not Enough troops " & $result & " of total " & $icmbTroopCap & " Troops")
      $fullArmy = false
      ClickP($TopLeftClient)
      sleep(500)
      ClickP($TopLeftClient)
      return false
   EndIf

EndFunc
Reply
 


Messages In This Thread
Made a function to get exact amount of troops in camp - by Henk500 - 02-20-2015, 08:19 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)

About The Bytecode Club

We're a community forum focused on Reverse Engineering, we try to target Java/Android but we also include other langauges/platforms. We pride ourselves in supporting and free and open sourced applications.

Website