diff --git a/assets/en/labels/combat/NoTarget.jpg b/assets/en/labels/combat/NoTarget.jpg new file mode 100644 index 0000000..77786a7 Binary files /dev/null and b/assets/en/labels/combat/NoTarget.jpg differ diff --git a/assets/screenshot.jpg b/assets/screenshot.jpg index ff2d69e..9b57a03 100644 Binary files a/assets/screenshot.jpg and b/assets/screenshot.jpg differ diff --git a/assets/spells/hunter/ArcaneShot.jpg b/assets/spells/hunter/ArcaneShot.jpg new file mode 100644 index 0000000..9302b52 Binary files /dev/null and b/assets/spells/hunter/ArcaneShot.jpg differ diff --git a/assets/spells/hunter/AspectOfTheCheetah.jpg b/assets/spells/hunter/AspectOfTheCheetah.jpg new file mode 100644 index 0000000..9316f0f Binary files /dev/null and b/assets/spells/hunter/AspectOfTheCheetah.jpg differ diff --git a/assets/spells/hunter/AspectOfTheTurtlr.jpg b/assets/spells/hunter/AspectOfTheTurtlr.jpg new file mode 100644 index 0000000..4975be2 Binary files /dev/null and b/assets/spells/hunter/AspectOfTheTurtlr.jpg differ diff --git a/assets/spells/hunter/Exhilaration.jpg b/assets/spells/hunter/Exhilaration.jpg new file mode 100644 index 0000000..29594f7 Binary files /dev/null and b/assets/spells/hunter/Exhilaration.jpg differ diff --git a/assets/spells/hunter/ExplosiveShot.jpg b/assets/spells/hunter/ExplosiveShot.jpg new file mode 100644 index 0000000..4959a1b Binary files /dev/null and b/assets/spells/hunter/ExplosiveShot.jpg differ diff --git a/assets/spells/hunter/EyesOfTheBeast.jpg b/assets/spells/hunter/EyesOfTheBeast.jpg new file mode 100644 index 0000000..002f66f Binary files /dev/null and b/assets/spells/hunter/EyesOfTheBeast.jpg differ diff --git a/assets/spells/hunter/Misdirection.jpg b/assets/spells/hunter/Misdirection.jpg new file mode 100644 index 0000000..cda3667 Binary files /dev/null and b/assets/spells/hunter/Misdirection.jpg differ diff --git a/assets/spells/hunter/PetUtility.jpg b/assets/spells/hunter/PetUtility.jpg new file mode 100644 index 0000000..6363b50 Binary files /dev/null and b/assets/spells/hunter/PetUtility.jpg differ diff --git a/bots/fighting/FightingAgent.py b/bots/fighting/FightingAgent.py new file mode 100644 index 0000000..a26be22 --- /dev/null +++ b/bots/fighting/FightingAgent.py @@ -0,0 +1,31 @@ +import time +from threading import Thread +from core.Logger import Logger + +class FightingAgent: + def __init__(self, monitor, player) -> None: + self.isCombatModeEnabled = False + self.monitor = monitor + self.player = player + self.logger = Logger("Combat Agent", player.debug) + self.hasTarget = False + + def startFighting(self): + self.player.checkConnection() + self.isCombatModeEnabled = True + while self.isCombatModeEnabled is True: + time.sleep(0.1) + self.logger.log("Combat mode is now disabled...") + + def stopFighting(self): + self.isCombatModeEnabled = False + + def run(self): + self.logger.log("Combat mode is now enabled...") + + fightingThread = Thread( + target=self.startFighting, + args=(), + name="fighting thread", + daemon=True) + fightingThread.start() \ No newline at end of file diff --git a/bots/fishing/FishingAgent.py b/bots/fishing/FishingAgent.py index f373c5a..8c8307c 100644 --- a/bots/fishing/FishingAgent.py +++ b/bots/fishing/FishingAgent.py @@ -12,7 +12,7 @@ class FishingAgent: 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.logger = Logger("Fishing Agent", player.debug) self.lureLoc = None self.monitor = monitor self.player = player diff --git a/bots/idling/IdlingAgent.py b/bots/idling/IdlingAgent.py index 5fc6cdf..8db6ec7 100644 --- a/bots/idling/IdlingAgent.py +++ b/bots/idling/IdlingAgent.py @@ -5,11 +5,11 @@ from core.Logger import Logger from core.Player import PLAYER_STATE class IdlingAgent: - def __init__(self, monitor, playerAgent) -> None: - self.logger = Logger("Idling Agent") + def __init__(self, monitor, player) -> None: + self.logger = Logger("Idling Agent", player.debug) self.idleTime = time.time() self.idleThread = None - self.player = playerAgent + self.player = player self.monitor = monitor def checkIdleTime(self): diff --git a/config.json b/config.json index 72408b2..db2d766 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,8 @@ { "antiAfk": true, "class": "DRUID", + "spe": "MARKSMANSHIP", + "debug": false, "lang": "en", "name": "Droïde" } \ No newline at end of file diff --git a/core/Config.py b/core/Config.py index 6221eab..98fb793 100644 --- a/core/Config.py +++ b/core/Config.py @@ -1,4 +1,5 @@ +import json class Config: def __init__(self) -> None: - ## PASS JSON CONFIG HERE AND DECLARE IT TO THE MAIN AGENT - pass \ No newline at end of file + with open("config.json", encoding="utf-8") as jsonFile: + self.file = json.load(jsonFile) \ No newline at end of file diff --git a/core/Logger.py b/core/Logger.py index 4838daf..8fb8a4d 100644 --- a/core/Logger.py +++ b/core/Logger.py @@ -1,9 +1,15 @@ import datetime; class Logger: - def __init__(self, name = "Logger") -> None: + def __init__(self, name = "Logger", debug = False) -> None: + self.isDebug = debug self.name = name def log(self, message): ct = datetime.datetime.now() - print(ct.strftime("%m/%d/%Y-%H:%M:%S:"), self.name, ">>", message) \ No newline at end of file + print(ct.strftime("%m/%d/%Y-%H:%M:%S:"), self.name, ">>", message) + + def debug(self, message): + if (self.isDebug is True): + ct = datetime.datetime.now() + print(ct.strftime("%m/%d/%Y-%H:%M:%S:"), self.name, ">>", message) \ No newline at end of file diff --git a/core/MainAgent.py b/core/MainAgent.py index 90ce1c6..84181d8 100644 --- a/core/MainAgent.py +++ b/core/MainAgent.py @@ -1,14 +1,18 @@ +from core.Config import Config from core.Monitor import Monitor from bots.battleground.battlegroundAgent import BattlegroundAgent from bots.fishing.FishingAgent import FishingAgent +from bots.fighting.FightingAgent import FightingAgent from bots.idling.IdlingAgent import IdlingAgent from core.Player import Player, PLAYER_STATE class MainAgent: def __init__(self) -> None: - self.monitor = Monitor() - self.playerAgent = Player(self.monitor) + self.config = Config() + self.monitor = Monitor(self.config) + self.playerAgent = Player(self.monitor, self.config) self.idlingBot = IdlingAgent(self.monitor, self.playerAgent) + self.fightingAgent = FightingAgent(self.monitor, self.playerAgent) self.fishingBot = FishingAgent(self.monitor, self.playerAgent) self.bgFarming = BattlegroundAgent(self.monitor, self.playerAgent) self.monitor.startScreenCaptureThread() @@ -22,3 +26,11 @@ class MainAgent: def startBgBot(self): self.playerAgent.changeState(PLAYER_STATE.BG_FARMING) self.bgFarming.run() + + def toggleFightingAgent(self): + if (self.fightingAgent is True): + self.fightingAgent.stopFighting() + else: + self.fightingAgent.run() + + diff --git a/core/Monitor.py b/core/Monitor.py index b02d97a..e8db162 100644 --- a/core/Monitor.py +++ b/core/Monitor.py @@ -1,7 +1,7 @@ import time from threading import Thread -from screeninfo import get_monitors from inspect import isfunction +from screeninfo import get_monitors import pyautogui import numpy as np import cv2 as cv @@ -10,8 +10,10 @@ from core.Logger import Logger FPS_REPORT_DELAY = 3 class Monitor: - def __init__(self): - self.logger = Logger("Monitor") + def __init__(self, config): + self.config = config + self.isDebug = self.config.file["debug"] + self.logger = Logger("Monitor", self.isDebug) self.monitor = None self.screenThread = None self.screenshot = None @@ -34,7 +36,8 @@ class Monitor: newScreenshot = cv.cvtColor(np.array(newScreenshot), cv.COLOR_RGB2BGR) grayScreenshot = cv.cvtColor(newScreenshot, cv.COLOR_BGR2GRAY) self.screenshot = grayScreenshot - cv.imwrite("assets/screenshot.jpg", self.screenshot) + if (self.isDebug is True): + cv.imwrite("assets/screenshot.jpg", self.screenshot) currTime = time.time() if currTime - fpsPrintTime >= FPS_REPORT_DELAY: self.fps = 1 / (currTime - loopTime) @@ -46,6 +49,7 @@ class Monitor: self.screenThread.start() self.logger.log("Main Agent: Thread started") + # TODO: GET IMAGE BEST MATCH RATIO FOR A WHOLE DIRECTORY OF ASSETS def findBestMatchFromDir(self, dirPath): pass @@ -56,9 +60,10 @@ class Monitor: min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res) matchRatio = max_val * 100 - self.logger.log(matchRatio) + self.logger.debug(matchRatio) + # Consider a match if ratio is at least 50% if (matchRatio < 50): - self.logger.log("Cannot find matching result...") + self.logger.debug("Cannot find matching result...") return -1 # If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum @@ -78,7 +83,7 @@ class Monitor: pyautogui.moveTo(point[0], point[1]) time.sleep(0.15) - def findMatchAndClickIfAvailable(self, template, onSuccess = None, onNotFound = None): + def findMatchAndClickIfAvailable(self, template, onFound = None, onNotFound = None): res = self.findMatchAndMoveToPosition(template) if (res == -1): @@ -89,8 +94,8 @@ class Monitor: time.sleep(0.1) pyautogui.click() time.sleep(0.15) - if (isfunction(onSuccess) is True): - return onSuccess(res) + if (isfunction(onFound) is True): + return onFound(res) def stopScreenCaptureThread(self): diff --git a/core/Player.py b/core/Player.py index fc26dff..b434c41 100644 --- a/core/Player.py +++ b/core/Player.py @@ -2,7 +2,6 @@ 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"]) @@ -10,18 +9,18 @@ CLASSES = Enum('CLASSES', ['DRUID', 'MAGE', 'HUNTER', 'PRIEST']) PLAYER_STATE = Enum('STATE', ['IDLE', 'FISHING', 'FARMING', 'BG_FARMING']) class Player: - def __init__(self, monitor) -> None: - with open("config.json", encoding="utf-8") as jsonFile: - self.config = json.load(jsonFile) + def __init__(self, monitor, config) -> None: + self.config = config self.isConnected = None self.idleThread = None - self.logger = Logger("Player Agent") + self.antiAfk = self.config.file["antiAfk"] + self.debug = self.config.file["debug"] + self.lang = self.config.file["lang"] + self.logger = Logger("Player Agent", self.debug) 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.playerClass = self.config.file["class"] + self.playerName = self.config.file["name"] 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 + ")") diff --git a/core/cli/CliAgent.py b/core/cli/CliAgent.py index a241cd3..30a04a3 100644 --- a/core/cli/CliAgent.py +++ b/core/cli/CliAgent.py @@ -13,6 +13,7 @@ class CLIAgent: print("Enter a command:") print("\tH\tHelp.") print("\tBG\tStart the bg farming agent.") + print("\tC\tToggle fight mode ON/OFF.") print("\tF\tStart the fishing agent.") print("\tQ\tQuit.") print("$>> ", end='') @@ -27,6 +28,8 @@ class CLIAgent: if (userInput == "bg"): self.mainAgent.startBgBot() + elif (userInput == "c"): + self.mainAgent.toggleFightingAgent() elif (userInput == "f"): self.mainAgent.startFishBot() elif (userInput == "h"):