Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cs ----------------------------------------------------------------------------
- AutoIt Version: 3.3.14.5
- Script Function:
- BlueStacks ClashRoyale 2vs2 Bot (Randomly places units when they are available)
- #ce ----------------------------------------------------------------------------
- ; Script Start - Add your code below here
- #include <MsgBoxConstants.au3>
- #include <AutoItConstants.au3>
- #include <Array.au3>
- Opt("MouseCoordMode", 2)
- Opt("PixelCoordMode", 2)
- $hwnd = WinActivate("BlueStacks", "")
- ;~ ConsoleWrite($hwnd & @CRLF)
- If $hwnd Then
- ; ok
- Else
- MsgBox($MB_OK, "MaunoBot", "BlueStack is not running!")
- Exit
- EndIf
- Sleep(100)
- ; TODO start 2vs2
- ;~ MouseMove(353, 645)
- ;~ MouseClick($MOUSE_CLICK_LEFT)
- ;~ MouseMove(353, 575)
- ;~ MouseClick($MOUSE_CLICK_LEFT)
- ; slot positions
- Dim $slotX[4]
- $slotX[0] = 173
- $slotX[1] = 276
- $slotX[2] = 372
- $slotX[3] = 472
- $slotY = 881
- ; colors
- $slotBorder = 0x87674A
- $cardActiveMin=11476139 ;11672748 ;11803821
- $cardActiveMax=12131505
- ; unit placement positions, TODO pick with probability
- Dim $locationsX[5]
- Dim $locationsY[5]
- $locationsX[0] = 131 ; behind left tower
- $locationsY[0] = 675
- $locationsX[1] = 270 ; behind middle tower
- $locationsY[1] = 743
- $locationsX[2] = 409 ; behind right tower
- $locationsY[2] = 658
- $locationsX[3] = 133 ; left bridge
- $locationsY[3] = 478
- $locationsX[4] = 409 ; right bridge
- $locationsY[4] = 471
- ; wait for game to start, check pixel color from slotbar
- While True
- Sleep(100)
- ; check if slotborder visible
- $c = PixelGetColor(105, 819)
- ;~ ConsoleWrite(Hex($c) & @CRLF)
- if $c == $slotBorder Then
- ConsoleWrite("Game started.." & @CRLF)
- ExitLoop
- EndIf
- WEnd
- ConsoleWrite("...running..." & @CRLF)
- Func Shake($distance)
- Return Random(-$distance,$distance,1)
- EndFunc
- ; wait for game to finish, check pixel color from slotbar
- While True
- Sleep(300+Random(0,250,1))
- ; check if slotborder still visible (round is still running)
- $c = PixelGetColor(105, 819)
- if $c <> $slotBorder Then
- ConsoleWrite("Game ended.." & @CRLF)
- ExitLoop
- EndIf
- ; TODO check if elixir bar is full, for the first round only
- ; check if unit is available.. from slot elixir color
- $c1 = PixelGetColor(171, 939)
- $c2 = PixelGetColor(270, 939)
- $c3 = PixelGetColor(369, 939)
- $c4 = PixelGetColor(468, 939)
- ; ready cards array
- Dim $readyCards[0]
- ; get active states, true or false
- $a1 = (($c1 >= $cardActiveMin) And ($c1 <= $cardActiveMax))?1:0
- $a2 = (($c2 >= $cardActiveMin) And ($c2 <= $cardActiveMax))?1:0
- $a3 = (($c3 >= $cardActiveMin) And ($c3 <= $cardActiveMax))?1:0
- $a4 = (($c4 >= $cardActiveMin) And ($c4 <= $cardActiveMax))?1:0
- if $a1==1 Then _ArrayAdd($readyCards,0)
- if $a2==1 Then _ArrayAdd($readyCards,1)
- if $a3==1 Then _ArrayAdd($readyCards,2)
- if $a4==1 Then _ArrayAdd($readyCards,3)
- ;~ ConsoleWrite("slot1=" & $a1 & " c1:" & Hex($c1) & " col=" & $c1 & " arr:" & UBound($readyCards) & @CRLF)
- ;~ ConsoleWrite("slot2=" & $a2 & " c2:" & Hex($c2) & " col=" & $c2 & " arr:" & UBound($readyCards) & @CRLF)
- ; ConsoleWrite("slot3=" & $a3 & " c3:" & Hex($c3) & " col=" & $c3 & " arr:" & UBound($readyCards) & @CRLF)
- ;~ ConsoleWrite("slot4=" & $a4 & " c4:" & Hex($c4) & " col=" & $c4 & " arr:" & UBound($readyCards) & @CRLF)
- if UBound($readyCards) > 0 Then
- ; click random unit button to select it (or wait for more to be active?)
- $randomIndex = Random(0, UBound($readyCards)-1, 1)
- ;~ ConsoleWrite("CardIndex: " & $readyCards[$randomIndex] & " cardX=" & $slotX[$readyCards[$randomIndex]] & @CRLF)
- MouseMove( $slotX[$readyCards[$randomIndex]]+Shake(15),$slotY+Shake(15))
- MouseClick($MOUSE_CLICK_LEFT)
- ; place unit to random positions
- $r = Random(0,UBound($locationsX)-1,1)
- MouseMove($locationsX[$r]+Shake(15),$locationsY[$r]+Shake(15))
- MouseClick($MOUSE_CLICK_LEFT)
- EndIf
- WEnd
- ;~ MsgBox($MB_OK, "MaunoBot", "Finished")
Add Comment
Please, Sign In to add comment