Added lang + findAndClick Function

This commit is contained in:
srose 2024-09-22 13:41:23 -04:00
parent cdcc70d7de
commit 29f9ce5140
15 changed files with 50 additions and 43 deletions

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 828 KiB

View File

@ -11,23 +11,22 @@ BG_STATUS = Enum('BG_STATUS', ['IDLE', 'IN_QUEUE', 'IN_BG', 'LOADING'])
class BattlegroundAgent:
def __init__(self, monitor, player) -> None:
self.battlegroundThread = None
self.player = player
self.logger = Logger("Battleground Agent")
self.groupFinderIcon = cv.imread("assets/icons/GroupFinder.jpg", cv.IMREAD_GRAYSCALE)
self.pvpTab = cv.imread("assets/menus/PlayerVsPlayerTab.jpg", cv.IMREAD_GRAYSCALE)
self.randomEpicBgButton = cv.imread("assets/menus/RandomEpicBGButton.jpg", cv.IMREAD_GRAYSCALE)
self.joinBattleButton = cv.imread("assets/menus/JoinBattleButton.jpg", cv.IMREAD_GRAYSCALE)
self.pvpTab = cv.imread("assets/" + player.lang + "/menus/PlayerVsPlayerTab.jpg", cv.IMREAD_GRAYSCALE)
self.randomEpicBgButton = cv.imread("assets/" + player.lang + "/menus/RandomEpicBGButton.jpg", cv.IMREAD_GRAYSCALE)
self.joinBattleButton = cv.imread("assets/" + player.lang + "/menus/JoinBattleButton.jpg", cv.IMREAD_GRAYSCALE)
self.deserterIcon = cv.imread("assets/icons/Deserter.jpg", cv.IMREAD_GRAYSCALE)
self.joinBgWindow = cv.imread("assets/menus/JoinBGWindow.jpg", cv.IMREAD_GRAYSCALE)
self.enterBgButton = cv.imread("assets/menus/EnterBgButton.jpg", cv.IMREAD_GRAYSCALE)
self.leaveBgButton = cv.imread("assets/menus/LeaveMatchButton.jpg", cv.IMREAD_GRAYSCALE)
self.joinBgWindow = cv.imread("assets/" + player.lang + "/menus/JoinBGWindow.jpg", cv.IMREAD_GRAYSCALE)
self.enterBgButton = cv.imread("assets/" + player.lang + "/menus/EnterBgButton.jpg", cv.IMREAD_GRAYSCALE)
self.leaveBgButton = cv.imread("assets/" + player.lang + "/menus/LeaveMatchButton.jpg", cv.IMREAD_GRAYSCALE)
self.status = BG_STATUS.IDLE
self.monitor = monitor
self.player = player
def startBGFarming(self):
pyautogui.press("esc")
self.player.checkConnection()
while self.player.state is PLAYER_STATE.BG_FARMING:
self.player.checkConnection()
self.status = BG_STATUS.IDLE
if (self.isDeserter() is False):
self.tagInBg()
@ -46,17 +45,10 @@ class BattlegroundAgent:
pyautogui.moveTo(50,50)
self.logger.log("Tagging in random epic bg...")
time.sleep(0.2)
self.monitor.findMatchAndMoveToPosition(self.groupFinderIcon)
pyautogui.click()
time.sleep(0.2)
self.monitor.findMatchAndMoveToPosition(self.pvpTab)
pyautogui.click()
time.sleep(0.2)
self.monitor.findMatchAndMoveToPosition(self.randomEpicBgButton)
pyautogui.click()
time.sleep(0.2)
self.monitor.findMatchAndMoveToPosition(self.joinBattleButton)
pyautogui.click()
self.monitor.findMatchAndClickIfAvailable(self.groupFinderIcon)
self.monitor.findMatchAndClickIfAvailable(self.pvpTab)
self.monitor.findMatchAndClickIfAvailable(self.randomEpicBgButton)
self.monitor.findMatchAndClickIfAvailable(self.joinBattleButton)
self.status = BG_STATUS.IN_QUEUE
self.waitForBg()
@ -66,24 +58,19 @@ class BattlegroundAgent:
res = self.monitor.findMatch(self.joinBgWindow)
if (res != -1):
self.logger.log("Bg started joining the game...")
time.sleep(0.2)
self.monitor.findMatchAndMoveToPosition(self.enterBgButton)
pyautogui.click()
self.monitor.findMatchAndClickIfAvailable(self.enterBgButton)
self.status = BG_STATUS.LOADING
time.sleep(1)
self.inBgRoutine()
def foundEndOfBg(self ):
self.logger.log("End of bg detected, leaving...")
self.status = BG_STATUS.IDLE
time.sleep(10)
def checkEndOfBg(self):
res = self.monitor.findMatch(self.leaveBgButton)
if (res != -1):
self.logger.log("End of bg detected, leaving...")
time.sleep(0.2)
pyautogui.move(res[0], res[1])
time.sleep(0.3)
self.status = BG_STATUS.IDLE
pyautogui.click()
time.sleep(10)
self.monitor.findMatchAndClickIfAvailable(self.leaveBgButton, self.foundEndOfBg)
def inBgRoutine(self):
self.logger.log("BG in progress...")

View File

@ -1,5 +1,6 @@
{
"antiAfk": true,
"class": "DRUID",
"lang": "en",
"name": "Droïde"
}

View File

@ -1,6 +1,7 @@
import time
from threading import Thread
from screeninfo import get_monitors
from inspect import isfunction
import pyautogui
import numpy as np
import cv2 as cv
@ -77,6 +78,21 @@ class Monitor:
pyautogui.moveTo(point[0], point[1])
time.sleep(0.15)
def findMatchAndClickIfAvailable(self, template, onSuccess = None, onNotFound = None):
res = self.findMatchAndMoveToPosition(template)
if (res == -1):
time.sleep(0.3)
if isfunction(onNotFound) is True:
return onNotFound(res)
else:
time.sleep(0.1)
pyautogui.click()
time.sleep(0.15)
if (isfunction(onSuccess) is True):
return onSuccess(res)
def stopScreenCaptureThread(self):
if (self.screenThread):
self.screenThread.terminate()

View File

@ -15,25 +15,28 @@ class Player:
self.config = json.load(jsonFile)
self.isConnected = None
self.idleThread = None
self.enterWorldButton = cv.imread("assets/menus/EnterWorldButton.jpg", cv.IMREAD_GRAYSCALE)
self.logger = Logger("Player Agent")
self.state = PLAYER_STATE.IDLE
self.monitor = monitor
self.playerClass = self.config["class"]
self.playerName = self.config["name"]
self.antiAfk = self.config["antiAfk"]
self.lang = self.config["lang"]
self.enterWorldButton = cv.imread("assets/" + self.lang + "/menus/EnterWorldButton.jpg", cv.IMREAD_GRAYSCALE)
self.reconnectButton = cv.imread("assets/" + self.lang + "/menus/Reconnect.jpg", cv.IMREAD_GRAYSCALE)
self.logger.log("Connected with " + self.playerName + " (" + self.playerClass + ")")
def connectButtonFound(self):
self.isConnected = CONNECT_STATUS.DISCONNECTED
self.logger.log("Player not connected attempting to connect...")
time.sleep(30)
def connectButtonNotFound(self):
self.isConnected = CONNECT_STATUS.CONNECTED
def checkConnection(self):
res = self.monitor.findMatch(self.enterWorldButton)
if (res == -1):
self.isConnected = CONNECT_STATUS.CONNECTED
else:
self.isConnected = CONNECT_STATUS.DISCONNECTED
self.logger.log("Player not connected attempting to connect...")
pyautogui.move(res[0], res[1])
time.sleep(0.4)
pyautogui.click()
time.sleep(5)
self.monitor.findMatchAndClickIfAvailable(self.enterWorldButton, self.connectButtonFound, self.connectButtonNotFound)
self.monitor.findMatchAndClickIfAvailable(self.reconnectButton, self.connectButtonFound, self.connectButtonNotFound)
def changeState(self, newState):
self.state = newState