Added debug mode + fighting agent class

This commit is contained in:
srose 2024-09-22 16:00:48 -04:00
parent 29f9ce5140
commit 9b0fe2183b
20 changed files with 87 additions and 28 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 828 KiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -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()

View File

@ -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

View File

@ -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):

View File

@ -1,6 +1,8 @@
{
"antiAfk": true,
"class": "DRUID",
"spe": "MARKSMANSHIP",
"debug": false,
"lang": "en",
"name": "Droïde"
}

View File

@ -1,4 +1,5 @@
import json
class Config:
def __init__(self) -> None:
## PASS JSON CONFIG HERE AND DECLARE IT TO THE MAIN AGENT
pass
with open("config.json", encoding="utf-8") as jsonFile:
self.file = json.load(jsonFile)

View File

@ -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)
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)

View File

@ -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()

View File

@ -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):

View File

@ -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 + ")")

View File

@ -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"):