Jump to content
Sign in to follow this  
leex2912

BBAttacks Drop On Near Redline And Drop Orders

Recommended Posts

BBAttacks Drop On Near Redline And Drop Orders

Base on the code from post below

 

 

 

giphy.gif

 

 

Edit AttackBB.au3

; #FUNCTION# ====================================================================================================================
; Name ..........: PrepareAttackBB
; Description ...: This file controls attacking preperation of the builders base
; Syntax ........:
; Parameters ....: None
; Return values .: None
; Author ........: Chilly-Chill (04-2019)
; Modified ......:
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2017
;                  MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================

Func AttackBB()
	If Not $g_bChkEnableBBAttack Then Return

	local $iSide = Random(0, 1, 1) ; randomly choose top left or top right
	Local $iBM_Pos = -1
	local $aBMPos = 0
	ClickP($aAway)
	SetLog("Going to attack.", $COLOR_BLUE)

	; check for troops, loot and Batlle Machine
	If Not PrepareAttackBB() Then Return
	SetDebugLog("PrepareAttackBB(): Success.")

	; search for a match
	If _Sleep(2000) Then Return
	local $aBBFindNow = [521, 308, 0xffc246, 30] ; search button
	If _CheckPixel($aBBFindNow, True) Then
		PureClick($aBBFindNow[0], $aBBFindNow[1])
	Else
		SetLog("Could not locate search button to go find an attack.", $COLOR_ERROR)
		Return
	EndIf

	; wait for the clouds to clear
	SetLog("Searching for Opponent.", $COLOR_BLUE)
	local $timer = __TimerInit()
	local $iPrevTime = 0
	While Not CheckBattleStarted()
		local $iTime = Int(__TimerDiff($timer)/ 60000)
		If $iTime > $iPrevTime Then ; if we have increased by a minute
			SetLog("Clouds: " & $iTime & "-Minute(s)")
			$iPrevTime = $iTime
		EndIf
		If _Sleep($DELAYRESPOND) Then Return
	WEnd

	; Get troops on attack bar and their quantities
	local $aBBAttackBar = GetAttackBarBB()
	If _Sleep($DELAYRESPOND) Then Return

	; Deploy all troops
	local $bTroopsDropped = False, $bBMDeployed = False
	SetLog( $g_bBBDropOrderSet = True ? "Deploying Troops in Custom Order." : "Deploying Troops in Order of Attack Bar.", $COLOR_BLUE)
	While Not $bTroopsDropped
		local $iNumSlots = UBound($aBBAttackBar, 1)
		If $g_bBBDropOrderSet = True Then
			local $asBBDropOrder = StringSplit($g_sBBDropOrder, "|")
			For $i=0 To $g_iBBTroopCount - 1 ; loop through each name in the drop order
				local $j=0, $bDone = 0
				While $j < $iNumSlots And Not $bDone
					If $aBBAttackBar[$j][0] = $asBBDropOrder[$i+1] Then
						DeployBBTroop($aBBAttackBar[$j][0], $aBBAttackBar[$j][1], $aBBAttackBar[$j][2], $aBBAttackBar[$j][4], $iSide)
						If $j = $iNumSlots-1 Or $aBBAttackBar[$j][0] <> $aBBAttackBar[$j+1][0] Then
							$bDone = True
							If _Sleep($g_iBBNextTroopDelay) Then Return ; wait before next troop
						EndIf
					EndIf
					$j+=1
				WEnd
			Next
		Else
			For $i=0 To $iNumSlots - 1
				DeployBBTroop($aBBAttackBar[$i][0], $aBBAttackBar[$i][1], $aBBAttackBar[$i][2], $aBBAttackBar[$i][4], $iSide)
				If $i = $iNumSlots-1 Or $aBBAttackBar[$i][0] <> $aBBAttackBar[$i+1][0] Then
					If _Sleep($g_iBBNextTroopDelay) Then Return ; wait before next troop
				Else
					If _Sleep($DELAYRESPOND) Then Return ; we are still on same troop so lets drop them all down a bit faster
				EndIf
			Next
		EndIf
		$aBBAttackBar = GetAttackBarBB(True)
		If $aBBAttackBar = "" Then $bTroopsDropped = True
	WEnd
	SetLog("All Troops Deployed", $COLOR_SUCCESS)

	; place hero and activate ability
	If $g_bBBMachineReady And Not $bBMDeployed Then SetLog("Deploying Battle Machine.", $COLOR_BLUE)
	While Not $bBMDeployed And $g_bBBMachineReady

		; Check if BM is available
				;Setlog("BB: Look for Battle Machine [If Exists]", $COLOR_GREEN)
				$iBM_Pos = BB_Mach_Slot()

		$aBMPos = GetMachinePos()
		If IsArray($aBMPos) Then
			;If IsArray($iBM_Pos) Then
			local $iPoint = Random(0, 9, 1)
			If $iSide Then

				BB_Mach_Deploy( $iBM_Pos )
				;PureClick($g_apTR[$iPoint][0], $g_apTR[$iPoint][1])
			Else

			    BB_Mach_Deploy( $iBM_Pos )
				;PureClick($g_apTL[$iPoint][0], $g_apTL[$iPoint][1])
			EndIf
			If _Sleep(500) Then Return ; wait before clicking ability
			PureClickP($aBMPos)
		Else
			$bBMDeployed = True
		EndIf
	WEnd
	If $bBMDeployed Then SetLog("Battle Machine Deployed", $COLOR_SUCCESS)

	; Continue with abilities until death
	local $bMachineAlive = True
	while $bMachineAlive And $bBMDeployed
		If _Sleep($g_iBBMachAbilityTime) Then Return ; wait for machine to be available
		local $timer = __TimerInit() ; give a bit of time to check if hero is dead because of the random lightning strikes through graphic
		$aBMPos = GetMachinePos()
		While __TimerDiff($timer) < 3000 And Not IsArray($aBMPos) ; give time to find
			$aBMPos = GetMachinePos()
		WEnd

		If Not IsArray($aBMPos) Then ; if machine wasnt found then it is dead, if not we hit ability
			$bMachineAlive = False
		Else
			PureClickP($aBMPos)
		EndIf
	WEnd
	If $bBMDeployed And Not $bMachineAlive Then SetLog("Battle Machine Dead")

	; wait for end of battle
	SetLog("Waiting for end of battle.", $COLOR_BLUE)
	If Not Okay() Then Return
	SetLog("Battle Ended.")
	If _Sleep(3000) Then Return

	; wait for ok after both attacks are finished
	;SetLog("Waiting for opponent.", $COLOR_BLUE)
	;Okay()
	;SetLog("Done.", $COLOR_SUCCESS)
	;ZoomOut()
EndFunc

Func CheckBattleStarted()
	local $sSearchDiamond = GetDiamondFromRect("376,11,420,26")

	local $aCoords = decodeSingleCoord(findImage("BBBattleStarted", $g_sImgBBBattleStarted, $sSearchDiamond, 1, True))
	If IsArray($aCoords) And UBound($aCoords) = 2 Then
		SetLog("Battle Started", $COLOR_SUCCESS)
		Return True
	EndIf

	Return False ; If battle not started
EndFunc

Func GetMachinePos()
	If Not $g_bBBMachineReady Then Return

	local $sSearchDiamond = GetDiamondFromRect("0,630,860,732")
	local $aCoords = decodeSingleCoord(findImage("BBBattleMachinePos", $g_sImgBBBattleMachine, $sSearchDiamond, 1, True))

	If IsArray($aCoords) And UBound($aCoords) = 2 Then
		Return $aCoords
	Else
		If $g_bDebugImageSave Then DebugImageSave("BBBattleMachinePos")
	EndIf

	Return
EndFunc

Func Okay()
	;local $timer = __TimerInit()

	;While 1
		;local $aCoords = decodeSingleCoord(findImage("OkayButton", $g_sImgOkButton, "FV", 1, True))
		;If IsArray($aCoords) And UBound($aCoords) = 2 Then
			;ClickP($aCoords)
			;Return True
		;EndIf

		;If __TimerDiff($timer) >= 180000 Then
			;SetLog("Could not find button 'Okay'", $COLOR_ERROR)
			;If $g_bDebugImageSave Then DebugImageSave("BBFindOkay")
			;Return False
		;EndIf

		;If Mod(__TimerDiff($timer), 3000) Then
			;If _Sleep($DELAYRESPOND) Then Return
		;EndIf

	;WEnd

	           ; BB: Wait for Battle End
    Local $i = 0
	Local $j = 0

	Local $iSide      = 1
	Local $iBM_Pos    = -1
	Local $cPixColor  = ''
	Local $cSideNames = "TR|TL"

	Local $bDegug     = True
	Local $bContinue  = True

	Local $aOkButtom[4]      = [ 400, 495 + $g_iBottomOffsetY, 0xE2F98B, 20 ]
	Local $aOkButtomColor[2] = [ 0xE2F98B, 0xE2FA8C ]

	Local $aOkBatleEnd[4]      = [ 630, 400 + $g_iBottomOffsetY, 0xDDF685, 20 ]
	Local $aOkBatleEndColor[2] = [ 0xDDF685, 0xE2FA8C ]

	Local $aOkWaitBattle[4] = [ 400, 500 + $g_iBottomOffsetY, 0xF0F0F0, 20 ]
	Local $aTroopSlot[4]    = [  78, 580 + $g_iBottomOffsetY, 0x404040, 20 ]
	Local $aSlotActive[8]   = [0x4C92D3, 0x5198E0, 0x5298E0, 0x5498E0, 0x5598E0, 0x65ADEC, 0x66ADEC, 0x6AB4F1]
	Local $aSlotOff[2]      = [0x464646, 0x454545]

	Local $iTroopsTo = 0
	Local $iWait64   = 64
	Local $iWait128  = 128
	Local $iWait256  = 256
	Local $aAux[2]   = [ 0, 0]

				Setlog("BB: Confirm Battle End [ok]", $COLOR_INFO)
				$j = 0
				While $j < $iWait64
					If _Sleep($DELAYRUNBOT1) Then Return
					$cPixColor = _GetPixelColor($aOkWaitBattle[0], $aOkWaitBattle[1], True)
					If _ColorCheck( $cPixColor, Hex($aOkWaitBattle[2], 6), 20) Then $j = 32
					If _Sleep($DELAYRUNBOT1) Then Return
					$cPixColor = _GetPixelColor($aOkButtom[0], $aOkButtom[1], True)
					If _ColorCheck( $cPixColor, Hex($aOkButtom[2], 6), 20) Then
						$j = $iWait64
					Else
						$j += 1
					Endif
					BB_StatusMsg("Wait for Battle End" & " [ " & String( $j ) & " ]")
				WEnd

				If _Sleep($DELAYRUNBOT1) Then Return

	; If $aOkWaitBattle Exists
				Local $cPixColor  = ''
				Local $aOkWaitBattle[4] = [ 400, 500 + $g_iBottomOffsetY, 0xF0F0F0, 20 ]
				local $aCoords = decodeSingleCoord(findImage("OkayButton", $g_sImgOkButton, "FV", 1, True))
		        $cPixColor = _GetPixelColor($aOkWaitBattle[0], $aOkWaitBattle[1], True)
				If IsArray($aCoords) And UBound($aCoords) = 2 Then

				If _ColorCheck( $cPixColor, Hex($aOkWaitBattle[2], 6), 20) Then
					If $bDegug Then SetLog("BB: Okay Buttom [no wait battle end], color: " & $cPixColor, $COLOR_DEBUG)
					ClickP($aOkWaitBattle, 1, 0, "#0000")
				EndIf

				If _Sleep($DELAYRUNBOT1) Then Return

				; wait $aOkButtom to appear
				$j = 0
				$cPixColor = _GetPixelColor($aOkButtom[0], $aOkButtom[1], True)
				While Not BB_ColorCheck( $aOkButtom, $aOkButtomColor )
					If $bDegug Then BB_StatusMsg("Wait Okay Buttom. [Ok]. color: " & $cPixColor & " [ " & String( $j ) & " ]")
					If _Sleep($DELAYRUNBOT1) Then Return
					$j += 1
					If $j > $iWait128 Then ExitLoop
					$cPixColor = _GetPixelColor($aOkButtom[0], $aOkButtom[1], True)
				WEnd
				If $j < $iWait128 Then
					SetLog("BB: Click Buttom. [Ok]. color: " & $cPixColor & " [ " & String( $j ) & " ]", $COLOR_DEBUG)
					ClickP($aOkButtom, 1, 0, "#0000")
				Else
					SetLog("BB: Can't Find Buttom [Ok]. color: " & $cPixColor, $COLOR_ERROR)
				EndIf

				If _Sleep($DELAYRUNBOT1) Then Return

				; wait $aOkBatleEnd to appear
				If $j < $iWait64 Then
					$j = 0
					$cPixColor = _GetPixelColor($aOkBatleEnd[0], $aOkBatleEnd[1], True)
					While Not BB_ColorCheck( $aOkBatleEnd, $aOkBatleEndColor )
						If $bDegug Then BB_StatusMsg("Wait Okay Buttom. [end]. color: " & $cPixColor & " [ " & String( $j ) & " ]")
						If _Sleep($DELAYRUNBOT1) Then Return
						$j += 1
						If $j > $iWait64 Then ExitLoop
						$cPixColor = _GetPixelColor($aOkBatleEnd[0], $aOkBatleEnd[1], True)
				
			         Return True
				  

					WEnd
					If $j < $iWait64 Then
						SetLog("BB: Click Buttom [end], color: " & $cPixColor & " [ " & String( $j ) & " ]", $COLOR_DEBUG)
						ClickP($aOkBatleEnd, 1, 0, "#0000")
						ClickP($aAway, 1, 0, "#0000")
					Else
						SetLog("BB: Can't Find Buttom [End]. color: " & $cPixColor, $COLOR_ERROR)
					EndIf
				Else

					If _Sleep($DELAYRUNBOT1) Then Return
					ClickP($aAway, 1, 0, "#0000")

				EndIf

			EndIf

	Return True
EndFunc

Func DeployBBTroop($sName, $x, $y, $iAmount, $iSide)
	Local $cSideNames = "TR|TL"
	Local $iBM_Pos    = -1
	SetLog("Deploying " & $sName & "x" & String($iAmount), $COLOR_ACTION)
	PureClick($x, $y) ; select troop
	If _Sleep($g_iBBSameTroopDelay) Then Return ; slow down selecting then dropping troops
	For $j=0 To $iAmount - 1
		local $iPoint = Random(0, 9, 1)
		If $iSide Then ; pick random point on random side
			BB_Attack()
			;PureClick($g_apTR[$iPoint][0], $g_apTR[$iPoint][1])
		Else
			BB_Attack()
			;BB_Mach_Deploy( $iBM_Pos )
			;PureClick($g_apTL[$iPoint][0], $g_apTL[$iPoint][1])
		EndIf
		If _Sleep($g_iBBSameTroopDelay) Then Return ; slow down dropping of troops
	Next
 EndFunc

 Func BB_Attack($Nside = 1, $SIDESNAMES = "TR|TL", $iTroopToDeploy = 4 )
    Local $iSide = Random(0, 1, 1) ; randomly choose top left or top right
	Local $iPoint = Random(0, 9, 1)
	Local $cSideNames = "TR|TL"
	Local $aBB_DiamondTop[4]    = [420,  300 + $g_iBottomOffsetY, 0x7D6559, 10]
	Local $aBB_DiamondBottom[4] = [430, 570 + $g_iBottomOffsetY, 0x2B4847, 10]
	Local $aBB_DiamondLeft[4]   = [300, 340 + $g_iBottomOffsetY, 0x213E3E, 10]
	Local $aBB_DiamondRight[4]  = [700, 430 + $g_iBottomOffsetY, 0x2F5351, 10]
	Local $aBB_LineCenter[2]    = [  0,   0]
	Local $i                    = 0
	Local $iHalf                = 0
	Local $iRest                = 0
	Local $aDropCoord[2]        = [  0,   0]
	Local $aDropPointX[4]       = [  0,   0, 0x7D6559, 10]
	Local $aDropPointY[4]       = [  0,   0, 0x7D6559, 10]
	Local $iBB_MaxDrop          = 20

	If $iTroopToDeploy < 4 Then $iTroopToDeploy = 4
	If $iTroopToDeploy > 8 Then $iTroopToDeploy = 8

	$iHalf = INT( $iTroopToDeploy / 2 )
	$iRest = $iTroopToDeploy - ( $iHalf * 2 )
	$iHalf += $iRest

	$aBB_LineCenter[0] = INT( ( $aBB_DiamondTop[0] + $aBB_DiamondRight[0] ) / 2 )
	$aBB_LineCenter[1] = INT( ( $aBB_DiamondTop[1] + $aBB_DiamondRight[1] ) / 2 )
	$aDropCoord[0]     = INT( ( ( $aBB_LineCenter[0] - $aBB_DiamondTop[0] ) * 0.9 ) / $iHalf )
	$aDropCoord[1]     = INT( ( ( $aBB_LineCenter[1] - $aBB_DiamondTop[1] ) * 0.9 ) / $iHalf )

	KeepClicks()

	For $i = $iHalf To 1 Step -1
		$aDropPointX[0] = $aBB_LineCenter[0] + ( $i * $aDropCoord[0] )
		$aDropPointX[1] = $aBB_LineCenter[1] + ( $i * $aDropCoord[1] )
		$aDropPointY[0] = $aBB_LineCenter[0] - ( $i * $aDropCoord[0] )
		$aDropPointY[1] = $aBB_LineCenter[1] - ( $i * $aDropCoord[1] )
		If _Sleep($DELAYDROPTROOP1) Then Return
		AttackClick($aDropPointX[0], $aDropPointX[1], 1, SetSleep(0), 0, "#0000")
		If _Sleep($DELAYDROPTROOP1) Then Return
		AttackClick($aDropPointY[0], $aDropPointY[1], 1, SetSleep(0), 0, "#0000")
	Next

	ReleaseClicks()

	If _Sleep($DELAYRUNBOT1) Then Return

EndFunc   ;==>BB_Attack

Func BB_Mach_Deploy( $iSlot = -1 )

	Local $j = 0
    Local $iSide = Random(0, 1, 1) ; randomly choose top left or top right
	Local $iPoint = Random(0, 9, 1)
	Local $cPixColor  = ''
	Local $cPixCheck  = ''

	Local $bDegug     = True
	Local $iWait128   = 128

	Local $aBMachine[4]      = [ 395, 580 + $g_iBottomOffsetY, 0x486E83, 20 ]
	Local $aBMachineColor[5] = [ 0x487188, 0x486E83, 0x486B7E, 0x486F81, 0x466F84 ]
	Local $aBatleEndColor[2] = [ 0x020202, 0x020202 ]

	Local $aDropBM[4]        = [ 270, 480 + $g_iBottomOffsetY, 0x7D6559, 20 ]

	If _Sleep($DELAYRUNBOT3) Then Return

	; If BM Present
	If ( $iSlot + 1 ) > 0 Then
		; Slot Pos
		$aBMachine[0] += ( $iSlot * 72 )
		; Deploy Battle Machine
		If $bDegug Then SetLog("BB: Click BM, color: " & $cPixColor & " Slot:[ " & String( $iSlot + 5 ) & " ]", $COLOR_DEBUG)
        KeepClicks()
		If _Sleep($DELAYDROPTROOP1) Then Return
		ClickP($aBMachine, 1, 0, "#0000")
		If _Sleep($DELAYDROPTROOP1) Then Return
		AttackClick($aDropBM[0], $aDropBM[1], 1, SetSleep(0), 0, "#0000")
		If _Sleep($DELAYDROPTROOP1) Then Return
		ReleaseClicks()
		If _Sleep($DELAYRUNBOT3) Then Return
		$cPixColor = _GetPixelColor($aBMachine[0], $aBMachine[1], True)
		$cPixCheck = $cPixColor
		If _Sleep($DELAYRUNBOT3) Then Return
		While $j < $iWait128
			$j += 1
			If _ColorCheck( $cPixColor, $cPixCheck, 20) Then
				ClickP($aBMachine, 1, 0, "#0000")
				BB_StatusMsg("Activate BM Power, color: " & $cPixCheck & " [ " & String( $j+1 ) & " ]")
			Else
				If _ColorCheck( $cPixCheck, Hex($aBatleEndColor[0], 6), 20) Then
					If $bDegug Then SetLog("BB: Battle end detected, color: " & $cPixCheck & " Slot:[ " & String( $iSlot + 5 ) & " ]", $COLOR_DEBUG)
					$j = $iWait128
				Else
					If Mod($j, 8) = 0 Then
						ClickP($aBMachine, 1, 0, "#0000")
					EndIf
				EndIf
			EndIf
			If _Sleep($DELAYRUNBOT1) Then Return
			$cPixCheck = _GetPixelColor($aBMachine[0], $aBMachine[1], True)
		WEnd
	EndIf

EndFunc   ;==>BB_Mach_Deploy

; #FUNCTION# ====================================================================================================================
; Name ..........: BB_ColorCheck( $aInfo, $aColors )
; Description ...: Check an Array of Colors ( instead just one )
; Author ........: Chackal++
; Modified ......:
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2016
;                  MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
Func BB_ColorCheck( $aInfo, $aColors )
	Local $i
	Local $cPixel
	Local $bResult = False
	Local $iLoop = UBound( $aColors ) - 1
	$cPixel = _GetPixelColor($aInfo[0], $aInfo[1], True)
	For $i = 0 to $iLoop
		If _ColorCheck( $cPixel, Hex($aColors[$i], 6), 20) Then
			$bResult = True
			ExitLoop
		EndIf
	Next
	Return $bResult
EndFunc	;==>BB_ColorCheck

Func BB_StatusMsg( $cTxt )
	_GUICtrlStatusBar_SetTextEx($g_hStatusBar, "BB Status: " & $cTxt )
EndFunc	;==>BB_StatusMsg


 Func BB_Mach_Slot()

	Local $i = 0
	Local $iSlot = -1

	Local $cPixColor = ''
	Local $cPixCheck = ''
	Local $bDegug    = True

	Local $aBMachine[4]      = [ 392, 580 + $g_iBottomOffsetY, 0x486E83, 20 ]
	Local $aBMachineColor[5] = [ 0x487188, 0x486E83, 0x486B7E, 0x486F81, 0x466F84 ]

	If _Sleep($DELAYRUNBOT3) Then Return

	; Find Battle Machine
	For $i = 0 To 2
		; Pos Next Slot
		If ($i > 0) Then
			$aBMachine[0] += 72
		EndIf
		$cPixColor = _GetPixelColor($aBMachine[0], $aBMachine[1], True)
		If _Sleep($DELAYRUNBOT3) Then Return
		IF BB_ColorCheck( $aBMachine, $aBMachineColor ) Then
			If $bDegug Then SetLog("BB: BM Found, color: " & $cPixColor & " Slot:[ " & String( $i + 5 ) & " ]", $COLOR_DEBUG)
			$iSlot = $i
			$i = 2
		EndIf
	Next
	Return $iSlot
 EndFunc   ;==>BB_Mach_Slot

 

Edited by leex2912
  • Like 1
  • Upvote 2

Share this post


Link to post
Share on other sites
On 9/22/2019 at 5:56 PM, evilazzura said:

Don't work.

this only work on CHILL MOD BBAttacks. Edit AttackBB.au3 on CHILL MOD 

dont just copy the code and paste from here , use AutoIt Script Editor otherwise it will be code error

Edited by leex2912

Share this post


Link to post
Share on other sites
Il y a 3 heures, leex2912 a dit :

this only work on CHILL MOD BBAttacks. Edit AttackBB.au3 on CHILL MOD 

dont just copy the code and paste from here , use AutoIt Script Editor otherwise it will be code error

That's what i do, i ve already autoit installed, i do right click > Edit script, 

I've ChillMod 1.0.3

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...