Added debug mode + fighting agent class
BIN
assets/en/labels/combat/NoTarget.jpg
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 828 KiB After Width: | Height: | Size: 1.1 MiB |
BIN
assets/spells/hunter/ArcaneShot.jpg
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
assets/spells/hunter/AspectOfTheCheetah.jpg
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
assets/spells/hunter/AspectOfTheTurtlr.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
assets/spells/hunter/Exhilaration.jpg
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
assets/spells/hunter/ExplosiveShot.jpg
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
assets/spells/hunter/EyesOfTheBeast.jpg
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
assets/spells/hunter/Misdirection.jpg
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
assets/spells/hunter/PetUtility.jpg
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
31
bots/fighting/FightingAgent.py
Normal 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()
|
||||||
|
|
@ -12,7 +12,7 @@ class FishingAgent:
|
||||||
self.fishingBobberImg = cv.imread("assets/fishing/bobbers/Bobber2.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.fishingIconImg = cv.imread("assets/fishing/FishIcon.jpg", cv.IMREAD_GRAYSCALE)
|
||||||
self.fishingThread = None
|
self.fishingThread = None
|
||||||
self.logger = Logger("Fishing Agent")
|
self.logger = Logger("Fishing Agent", player.debug)
|
||||||
self.lureLoc = None
|
self.lureLoc = None
|
||||||
self.monitor = monitor
|
self.monitor = monitor
|
||||||
self.player = player
|
self.player = player
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ from core.Logger import Logger
|
||||||
from core.Player import PLAYER_STATE
|
from core.Player import PLAYER_STATE
|
||||||
|
|
||||||
class IdlingAgent:
|
class IdlingAgent:
|
||||||
def __init__(self, monitor, playerAgent) -> None:
|
def __init__(self, monitor, player) -> None:
|
||||||
self.logger = Logger("Idling Agent")
|
self.logger = Logger("Idling Agent", player.debug)
|
||||||
self.idleTime = time.time()
|
self.idleTime = time.time()
|
||||||
self.idleThread = None
|
self.idleThread = None
|
||||||
self.player = playerAgent
|
self.player = player
|
||||||
self.monitor = monitor
|
self.monitor = monitor
|
||||||
|
|
||||||
def checkIdleTime(self):
|
def checkIdleTime(self):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"antiAfk": true,
|
"antiAfk": true,
|
||||||
"class": "DRUID",
|
"class": "DRUID",
|
||||||
|
"spe": "MARKSMANSHIP",
|
||||||
|
"debug": false,
|
||||||
"lang": "en",
|
"lang": "en",
|
||||||
"name": "Droïde"
|
"name": "Droïde"
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
|
import json
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
## PASS JSON CONFIG HERE AND DECLARE IT TO THE MAIN AGENT
|
with open("config.json", encoding="utf-8") as jsonFile:
|
||||||
pass
|
self.file = json.load(jsonFile)
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
import datetime;
|
import datetime;
|
||||||
|
|
||||||
class Logger:
|
class Logger:
|
||||||
def __init__(self, name = "Logger") -> None:
|
def __init__(self, name = "Logger", debug = False) -> None:
|
||||||
|
self.isDebug = debug
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def log(self, message):
|
def log(self, message):
|
||||||
ct = datetime.datetime.now()
|
ct = datetime.datetime.now()
|
||||||
print(ct.strftime("%m/%d/%Y-%H:%M:%S:"), self.name, ">>", message)
|
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)
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
|
from core.Config import Config
|
||||||
from core.Monitor import Monitor
|
from core.Monitor import Monitor
|
||||||
from bots.battleground.battlegroundAgent import BattlegroundAgent
|
from bots.battleground.battlegroundAgent import BattlegroundAgent
|
||||||
from bots.fishing.FishingAgent import FishingAgent
|
from bots.fishing.FishingAgent import FishingAgent
|
||||||
|
from bots.fighting.FightingAgent import FightingAgent
|
||||||
from bots.idling.IdlingAgent import IdlingAgent
|
from bots.idling.IdlingAgent import IdlingAgent
|
||||||
from core.Player import Player, PLAYER_STATE
|
from core.Player import Player, PLAYER_STATE
|
||||||
|
|
||||||
class MainAgent:
|
class MainAgent:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.monitor = Monitor()
|
self.config = Config()
|
||||||
self.playerAgent = Player(self.monitor)
|
self.monitor = Monitor(self.config)
|
||||||
|
self.playerAgent = Player(self.monitor, self.config)
|
||||||
self.idlingBot = IdlingAgent(self.monitor, self.playerAgent)
|
self.idlingBot = IdlingAgent(self.monitor, self.playerAgent)
|
||||||
|
self.fightingAgent = FightingAgent(self.monitor, self.playerAgent)
|
||||||
self.fishingBot = FishingAgent(self.monitor, self.playerAgent)
|
self.fishingBot = FishingAgent(self.monitor, self.playerAgent)
|
||||||
self.bgFarming = BattlegroundAgent(self.monitor, self.playerAgent)
|
self.bgFarming = BattlegroundAgent(self.monitor, self.playerAgent)
|
||||||
self.monitor.startScreenCaptureThread()
|
self.monitor.startScreenCaptureThread()
|
||||||
|
|
@ -22,3 +26,11 @@ class MainAgent:
|
||||||
def startBgBot(self):
|
def startBgBot(self):
|
||||||
self.playerAgent.changeState(PLAYER_STATE.BG_FARMING)
|
self.playerAgent.changeState(PLAYER_STATE.BG_FARMING)
|
||||||
self.bgFarming.run()
|
self.bgFarming.run()
|
||||||
|
|
||||||
|
def toggleFightingAgent(self):
|
||||||
|
if (self.fightingAgent is True):
|
||||||
|
self.fightingAgent.stopFighting()
|
||||||
|
else:
|
||||||
|
self.fightingAgent.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import time
|
import time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from screeninfo import get_monitors
|
|
||||||
from inspect import isfunction
|
from inspect import isfunction
|
||||||
|
from screeninfo import get_monitors
|
||||||
import pyautogui
|
import pyautogui
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
|
|
@ -10,8 +10,10 @@ from core.Logger import Logger
|
||||||
FPS_REPORT_DELAY = 3
|
FPS_REPORT_DELAY = 3
|
||||||
|
|
||||||
class Monitor:
|
class Monitor:
|
||||||
def __init__(self):
|
def __init__(self, config):
|
||||||
self.logger = Logger("Monitor")
|
self.config = config
|
||||||
|
self.isDebug = self.config.file["debug"]
|
||||||
|
self.logger = Logger("Monitor", self.isDebug)
|
||||||
self.monitor = None
|
self.monitor = None
|
||||||
self.screenThread = None
|
self.screenThread = None
|
||||||
self.screenshot = None
|
self.screenshot = None
|
||||||
|
|
@ -34,7 +36,8 @@ class Monitor:
|
||||||
newScreenshot = cv.cvtColor(np.array(newScreenshot), cv.COLOR_RGB2BGR)
|
newScreenshot = cv.cvtColor(np.array(newScreenshot), cv.COLOR_RGB2BGR)
|
||||||
grayScreenshot = cv.cvtColor(newScreenshot, cv.COLOR_BGR2GRAY)
|
grayScreenshot = cv.cvtColor(newScreenshot, cv.COLOR_BGR2GRAY)
|
||||||
self.screenshot = grayScreenshot
|
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()
|
currTime = time.time()
|
||||||
if currTime - fpsPrintTime >= FPS_REPORT_DELAY:
|
if currTime - fpsPrintTime >= FPS_REPORT_DELAY:
|
||||||
self.fps = 1 / (currTime - loopTime)
|
self.fps = 1 / (currTime - loopTime)
|
||||||
|
|
@ -46,6 +49,7 @@ class Monitor:
|
||||||
self.screenThread.start()
|
self.screenThread.start()
|
||||||
self.logger.log("Main Agent: Thread started")
|
self.logger.log("Main Agent: Thread started")
|
||||||
|
|
||||||
|
# TODO: GET IMAGE BEST MATCH RATIO FOR A WHOLE DIRECTORY OF ASSETS
|
||||||
def findBestMatchFromDir(self, dirPath):
|
def findBestMatchFromDir(self, dirPath):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -56,9 +60,10 @@ class Monitor:
|
||||||
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
|
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
|
||||||
|
|
||||||
matchRatio = max_val * 100
|
matchRatio = max_val * 100
|
||||||
self.logger.log(matchRatio)
|
self.logger.debug(matchRatio)
|
||||||
|
# Consider a match if ratio is at least 50%
|
||||||
if (matchRatio < 50):
|
if (matchRatio < 50):
|
||||||
self.logger.log("Cannot find matching result...")
|
self.logger.debug("Cannot find matching result...")
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
# If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum
|
# If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum
|
||||||
|
|
@ -78,7 +83,7 @@ class Monitor:
|
||||||
pyautogui.moveTo(point[0], point[1])
|
pyautogui.moveTo(point[0], point[1])
|
||||||
time.sleep(0.15)
|
time.sleep(0.15)
|
||||||
|
|
||||||
def findMatchAndClickIfAvailable(self, template, onSuccess = None, onNotFound = None):
|
def findMatchAndClickIfAvailable(self, template, onFound = None, onNotFound = None):
|
||||||
res = self.findMatchAndMoveToPosition(template)
|
res = self.findMatchAndMoveToPosition(template)
|
||||||
|
|
||||||
if (res == -1):
|
if (res == -1):
|
||||||
|
|
@ -89,8 +94,8 @@ class Monitor:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
pyautogui.click()
|
pyautogui.click()
|
||||||
time.sleep(0.15)
|
time.sleep(0.15)
|
||||||
if (isfunction(onSuccess) is True):
|
if (isfunction(onFound) is True):
|
||||||
return onSuccess(res)
|
return onFound(res)
|
||||||
|
|
||||||
|
|
||||||
def stopScreenCaptureThread(self):
|
def stopScreenCaptureThread(self):
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import json
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import time
|
import time
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import pyautogui
|
|
||||||
from core.Logger import Logger
|
from core.Logger import Logger
|
||||||
|
|
||||||
CONNECT_STATUS = Enum('CONNECT_STATUS', ["CONNECTED", "CONNECTING", "DISCONNECTED"])
|
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'])
|
PLAYER_STATE = Enum('STATE', ['IDLE', 'FISHING', 'FARMING', 'BG_FARMING'])
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self, monitor) -> None:
|
def __init__(self, monitor, config) -> None:
|
||||||
with open("config.json", encoding="utf-8") as jsonFile:
|
self.config = config
|
||||||
self.config = json.load(jsonFile)
|
|
||||||
self.isConnected = None
|
self.isConnected = None
|
||||||
self.idleThread = 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.state = PLAYER_STATE.IDLE
|
||||||
self.monitor = monitor
|
self.monitor = monitor
|
||||||
self.playerClass = self.config["class"]
|
self.playerClass = self.config.file["class"]
|
||||||
self.playerName = self.config["name"]
|
self.playerName = self.config.file["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.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.reconnectButton = cv.imread("assets/" + self.lang + "/menus/Reconnect.jpg", cv.IMREAD_GRAYSCALE)
|
||||||
self.logger.log("Connected with " + self.playerName + " (" + self.playerClass + ")")
|
self.logger.log("Connected with " + self.playerName + " (" + self.playerClass + ")")
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class CLIAgent:
|
||||||
print("Enter a command:")
|
print("Enter a command:")
|
||||||
print("\tH\tHelp.")
|
print("\tH\tHelp.")
|
||||||
print("\tBG\tStart the bg farming agent.")
|
print("\tBG\tStart the bg farming agent.")
|
||||||
|
print("\tC\tToggle fight mode ON/OFF.")
|
||||||
print("\tF\tStart the fishing agent.")
|
print("\tF\tStart the fishing agent.")
|
||||||
print("\tQ\tQuit.")
|
print("\tQ\tQuit.")
|
||||||
print("$>> ", end='')
|
print("$>> ", end='')
|
||||||
|
|
@ -27,6 +28,8 @@ class CLIAgent:
|
||||||
|
|
||||||
if (userInput == "bg"):
|
if (userInput == "bg"):
|
||||||
self.mainAgent.startBgBot()
|
self.mainAgent.startBgBot()
|
||||||
|
elif (userInput == "c"):
|
||||||
|
self.mainAgent.toggleFightingAgent()
|
||||||
elif (userInput == "f"):
|
elif (userInput == "f"):
|
||||||
self.mainAgent.startFishBot()
|
self.mainAgent.startFishBot()
|
||||||
elif (userInput == "h"):
|
elif (userInput == "h"):
|
||||||
|
|
|
||||||