diff --git a/assets/fishing/Bobber.png b/assets/fishing/Bobber.png deleted file mode 100644 index c4d194a..0000000 Binary files a/assets/fishing/Bobber.png and /dev/null differ diff --git a/assets/fishing/Bobber.jpg b/assets/fishing/bobbers/Bobber.jpg similarity index 100% rename from assets/fishing/Bobber.jpg rename to assets/fishing/bobbers/Bobber.jpg diff --git a/assets/fishing/bobbers/Bobber2.jpg b/assets/fishing/bobbers/Bobber2.jpg new file mode 100644 index 0000000..9bc9534 Binary files /dev/null and b/assets/fishing/bobbers/Bobber2.jpg differ diff --git a/assets/menus/EnterWorldButton.jpg b/assets/menus/EnterWorldButton.jpg new file mode 100644 index 0000000..b6b8477 Binary files /dev/null and b/assets/menus/EnterWorldButton.jpg differ diff --git a/bots/fishing/FishingAgent.py b/bots/fishing/FishingAgent.py index 9cb48b6..b5ebdc3 100644 --- a/bots/fishing/FishingAgent.py +++ b/bots/fishing/FishingAgent.py @@ -9,18 +9,25 @@ from core.Player import PLAYER_STATE class FishingAgent: def __init__(self, monitor, player) -> None: - self.fishingBobberImg = cv.imread("assets/fishing/Bobber.jpg", cv.IMREAD_GRAYSCALE) + self.fishingBobberImg = cv.imread("assets/fishing/bobbers/Bobber2.jpg", cv.IMREAD_GRAYSCALE) self.fishingIconImg = cv.imread("assets/fishing/FishIcon.jpg", cv.IMREAD_GRAYSCALE) self.fishingThread = None self.logger = Logger("Fishing Agent") self.monitor = monitor self.lureLoc = None self.player = player + self.fail = 0 self.retry = 0 def startFishing(self): + self.player.checkConnection() self.player.changeState(PLAYER_STATE.FISHING) while self.player.state is PLAYER_STATE.FISHING: + if (self.fail > 5): + self.fail = 0 + self.logger.log("Fishing failed too many times. Stopping fishing thread...") + self.player.changeState(PLAYER_STATE.IDLE) + return self.castLure() def castLure(self): @@ -43,7 +50,8 @@ class FishingAgent: if (res == -1): if (self.retry > 4): - self.logger.log("Took too to find lure long, retrying fishing from the beginning") + self.fail += 1 + self.logger.log("Took too long to find lure, retrying fishing from the beginning") return else: self.logger.log("Trying again in 1 second...") @@ -64,13 +72,14 @@ class FishingAgent: res = self.monitor.findMatch(self.fishingBobberImg) print(self.lureLoc) print(res) - if (res != -1 and abs(res[1] - self.lureLoc[1]) > 20): + if (res != -1 and abs(res[1] - self.lureLoc[1]) > 10): time.sleep(0.2) pyautogui.click() time.sleep(0.5) return elif (self.retry > 200): self.retry = 0 + self.fail += 1 return def run(self): diff --git a/bots/idling/IdlingAgent.py b/bots/idling/IdlingAgent.py index 6df80b2..882e610 100644 --- a/bots/idling/IdlingAgent.py +++ b/bots/idling/IdlingAgent.py @@ -1,15 +1,16 @@ import time -import pyautogui from threading import Thread +import pyautogui from core.Logger import Logger from core.Player import PLAYER_STATE class IdlingAgent: - def __init__(self, playerAgent) -> None: + def __init__(self, monitor, playerAgent) -> None: self.logger = Logger("Idling Agent") self.idleTime = time.time() self.idleThread = None self.player = playerAgent + self.monitor = monitor def checkIdleTime(self): while self.player.state is PLAYER_STATE.IDLE: diff --git a/core/MainAgent.py b/core/MainAgent.py index ecabe94..d396805 100644 --- a/core/MainAgent.py +++ b/core/MainAgent.py @@ -6,14 +6,13 @@ from core.Player import Player, PLAYER_STATE class MainAgent: def __init__(self) -> None: self.monitor = Monitor() - self.playerAgent = Player() - self.idlingBot = IdlingAgent(self.playerAgent) + self.playerAgent = Player(self.monitor) + self.idlingBot = IdlingAgent(self.monitor, self.playerAgent) self.fishingBot = FishingAgent(self.monitor, self.playerAgent) self.monitor.startScreenCaptureThread() # Start idling agent at the construction of the mainAgent for now self.idlingBot.run() - def startFishBot(self): self.playerAgent.changeState(PLAYER_STATE.FISHING) self.fishingBot.run() diff --git a/core/Monitor.py b/core/Monitor.py index 94b12a2..20b5810 100644 --- a/core/Monitor.py +++ b/core/Monitor.py @@ -45,6 +45,9 @@ class Monitor: self.screenThread.start() self.logger.log("Main Agent: Thread started") + def findBestMatchFromDir(self, dirPath): + pass + def findMatch(self, template, method = "TM_CCOEFF_NORMED"): methodInt = getattr(cv, method) res = cv.matchTemplate(self.screenshot, template, methodInt) @@ -53,7 +56,7 @@ class Monitor: matchRatio = max_val * 100 self.logger.log(matchRatio) - if (matchRatio < 55): + if (matchRatio < 60): self.logger.log("Cannot find matching result...") return -1 diff --git a/core/Player.py b/core/Player.py index 1e68ad6..4babfbf 100644 --- a/core/Player.py +++ b/core/Player.py @@ -1,5 +1,8 @@ import json from enum import Enum +import time +import cv2 as cv +import pyautogui from core.Logger import Logger CONNECT_STATUS = Enum('CONNECT_STATUS', ["CONNECTED", "CONNECTING", "DISCONNECTED"]) @@ -7,16 +10,33 @@ CLASSES = Enum('CLASSES', ['DRUID', 'MAGE', 'HUNTER', 'PRIEST']) PLAYER_STATE = Enum('STATE', ['IDLE', 'FISHING', 'FARMING']) class Player: - def __init__(self) -> None: + def __init__(self, monitor) -> None: with open("config.json", encoding="utf-8") as jsonFile: self.config = json.load(jsonFile) - self.isConnected = CONNECT_STATUS.DISCONNECTED + 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.logger.log("Connected with " + self.playerName + " (" + self.playerClass + ")") + 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) + + + + def changeState(self, newState): self.state = newState \ No newline at end of file diff --git a/core/cli/CliAgent.py b/core/cli/CliAgent.py index 763a492..6af3307 100644 --- a/core/cli/CliAgent.py +++ b/core/cli/CliAgent.py @@ -33,7 +33,7 @@ class CLIAgent: cv.destroyAllWindows() self.logger.log("Exiting application...") self.isRunning = False - else: + else: self.logger.log("Unknown Command.") self.printMenu()