Guest User

Untitled

a guest
Jul 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. #cs ----------------------------------------------------------------------------
  2.  
  3. AutoIt Version: 3.3.14.5
  4.  
  5. Script Function:
  6. BlueStacks ClashRoyale 2vs2 Bot (Randomly places units when they are available)
  7.  
  8. #ce ----------------------------------------------------------------------------
  9.  
  10. ; Script Start - Add your code below here
  11.  
  12. #include <MsgBoxConstants.au3>
  13. #include <AutoItConstants.au3>
  14. #include <Array.au3>
  15.  
  16. Opt("MouseCoordMode", 2)
  17. Opt("PixelCoordMode", 2)
  18.  
  19. $hwnd = WinActivate("BlueStacks", "")
  20. ;~ ConsoleWrite($hwnd & @CRLF)
  21. If $hwnd Then
  22. ; ok
  23. Else
  24. MsgBox($MB_OK, "MaunoBot", "BlueStack is not running!")
  25. Exit
  26. EndIf
  27.  
  28. Sleep(100)
  29.  
  30. ; TODO start 2vs2
  31. ;~ MouseMove(353, 645)
  32. ;~ MouseClick($MOUSE_CLICK_LEFT)
  33. ;~ MouseMove(353, 575)
  34. ;~ MouseClick($MOUSE_CLICK_LEFT)
  35.  
  36. ; slot positions
  37. Dim $slotX[4]
  38. $slotX[0] = 173
  39. $slotX[1] = 276
  40. $slotX[2] = 372
  41. $slotX[3] = 472
  42. $slotY = 881
  43.  
  44. ; colors
  45. $slotBorder = 0x87674A
  46. $cardActiveMin=11476139 ;11672748 ;11803821
  47. $cardActiveMax=12131505
  48.  
  49. ; unit placement positions, TODO pick with probability
  50. Dim $locationsX[5]
  51. Dim $locationsY[5]
  52. $locationsX[0] = 131 ; behind left tower
  53. $locationsY[0] = 675
  54. $locationsX[1] = 270 ; behind middle tower
  55. $locationsY[1] = 743
  56. $locationsX[2] = 409 ; behind right tower
  57. $locationsY[2] = 658
  58. $locationsX[3] = 133 ; left bridge
  59. $locationsY[3] = 478
  60. $locationsX[4] = 409 ; right bridge
  61. $locationsY[4] = 471
  62.  
  63.  
  64. ; wait for game to start, check pixel color from slotbar
  65. While True
  66. Sleep(100)
  67. ; check if slotborder visible
  68. $c = PixelGetColor(105, 819)
  69. ;~ ConsoleWrite(Hex($c) & @CRLF)
  70. if $c == $slotBorder Then
  71. ConsoleWrite("Game started.." & @CRLF)
  72. ExitLoop
  73. EndIf
  74. WEnd
  75.  
  76. ConsoleWrite("...running..." & @CRLF)
  77.  
  78. Func Shake($distance)
  79. Return Random(-$distance,$distance,1)
  80. EndFunc
  81.  
  82. ; wait for game to finish, check pixel color from slotbar
  83. While True
  84. Sleep(300+Random(0,250,1))
  85. ; check if slotborder still visible (round is still running)
  86. $c = PixelGetColor(105, 819)
  87. if $c <> $slotBorder Then
  88. ConsoleWrite("Game ended.." & @CRLF)
  89. ExitLoop
  90. EndIf
  91.  
  92. ; TODO check if elixir bar is full, for the first round only
  93.  
  94. ; check if unit is available.. from slot elixir color
  95. $c1 = PixelGetColor(171, 939)
  96. $c2 = PixelGetColor(270, 939)
  97. $c3 = PixelGetColor(369, 939)
  98. $c4 = PixelGetColor(468, 939)
  99.  
  100. ; ready cards array
  101. Dim $readyCards[0]
  102.  
  103. ; get active states, true or false
  104. $a1 = (($c1 >= $cardActiveMin) And ($c1 <= $cardActiveMax))?1:0
  105. $a2 = (($c2 >= $cardActiveMin) And ($c2 <= $cardActiveMax))?1:0
  106. $a3 = (($c3 >= $cardActiveMin) And ($c3 <= $cardActiveMax))?1:0
  107. $a4 = (($c4 >= $cardActiveMin) And ($c4 <= $cardActiveMax))?1:0
  108.  
  109. if $a1==1 Then _ArrayAdd($readyCards,0)
  110. if $a2==1 Then _ArrayAdd($readyCards,1)
  111. if $a3==1 Then _ArrayAdd($readyCards,2)
  112. if $a4==1 Then _ArrayAdd($readyCards,3)
  113.  
  114. ;~ ConsoleWrite("slot1=" & $a1 & " c1:" & Hex($c1) & " col=" & $c1 & " arr:" & UBound($readyCards) & @CRLF)
  115. ;~ ConsoleWrite("slot2=" & $a2 & " c2:" & Hex($c2) & " col=" & $c2 & " arr:" & UBound($readyCards) & @CRLF)
  116. ; ConsoleWrite("slot3=" & $a3 & " c3:" & Hex($c3) & " col=" & $c3 & " arr:" & UBound($readyCards) & @CRLF)
  117. ;~ ConsoleWrite("slot4=" & $a4 & " c4:" & Hex($c4) & " col=" & $c4 & " arr:" & UBound($readyCards) & @CRLF)
  118.  
  119. if UBound($readyCards) > 0 Then
  120. ; click random unit button to select it (or wait for more to be active?)
  121. $randomIndex = Random(0, UBound($readyCards)-1, 1)
  122. ;~ ConsoleWrite("CardIndex: " & $readyCards[$randomIndex] & " cardX=" & $slotX[$readyCards[$randomIndex]] & @CRLF)
  123. MouseMove( $slotX[$readyCards[$randomIndex]]+Shake(15),$slotY+Shake(15))
  124. MouseClick($MOUSE_CLICK_LEFT)
  125.  
  126. ; place unit to random positions
  127. $r = Random(0,UBound($locationsX)-1,1)
  128. MouseMove($locationsX[$r]+Shake(15),$locationsY[$r]+Shake(15))
  129. MouseClick($MOUSE_CLICK_LEFT)
  130. EndIf
  131.  
  132. WEnd
  133.  
  134. ;~ MsgBox($MB_OK, "MaunoBot", "Finished")
Add Comment
Please, Sign In to add comment