Compare commits

..

No commits in common. "b8cd6a09eddb566eeff12b100c4a66664ce3f0ed" and "db5b3a521c964967f0430eb5eb981d6fca1e0b3f" have entirely different histories.

10 changed files with 15 additions and 52 deletions

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
assets/fishing/Bobber.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

View File

@ -9,31 +9,23 @@ from core.Player import PLAYER_STATE
class FishingAgent: class FishingAgent:
def __init__(self, monitor, player) -> None: def __init__(self, monitor, player) -> None:
self.fishingBobberImg = cv.imread("assets/fishing/bobbers/Bobber2.jpg", cv.IMREAD_GRAYSCALE) self.fishingBobberImg = cv.imread("assets/fishing/Bobber.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")
self.monitor = monitor self.monitor = monitor
self.lureLoc = None self.lureLoc = None
self.player = player self.player = player
self.fail = 0
self.retry = 0 self.retry = 0
def startFishing(self): def startFishing(self):
self.player.checkConnection()
self.player.changeState(PLAYER_STATE.FISHING) self.player.changeState(PLAYER_STATE.FISHING)
while self.player.state is 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() self.castLure()
def castLure(self): def castLure(self):
self.retry = 0 self.retry = 0
self.lureLoc = None pyautogui.moveTo(2,3)
pyautogui.moveTo(50,50)
self.logger.log("Casting Lure.") self.logger.log("Casting Lure.")
res = self.monitor.findMatchAndMoveToPosition(self.fishingIconImg) res = self.monitor.findMatchAndMoveToPosition(self.fishingIconImg)
if (res == -1): if (res == -1):
@ -47,20 +39,18 @@ class FishingAgent:
self.logger.log("Moving cursor to Lure.") self.logger.log("Moving cursor to Lure.")
time.sleep(2) time.sleep(2)
res = self.monitor.findMatch(self.fishingBobberImg) res = self.monitor.findMatch(self.fishingBobberImg)
if (res == -1): if (res == -1):
if (self.retry > 4): if (self.retry > 4):
self.fail += 1 self.logger.log("Took too to find lure long, retrying fishing from the beginning")
self.logger.log("Took too long to find lure, retrying fishing from the beginning")
return return
else: else:
self.logger.log("Trying again in 1 second...") self.logger.log("Trying again in 1 second...")
self.retry += 1 self.retry += 1
time.sleep(1) time.sleep(1)
self.findLure() self.findLure()
time.sleep(0.5)
self.lureLoc = res self.lureLoc = res
pyautogui.moveTo(self.lureLoc[0], self.lureLoc[1]) time.sleep(0.2)
pyautogui.moveTo(res[0], res[1])
self.watchLure() self.watchLure()
def watchLure(self): def watchLure(self):
@ -70,16 +60,12 @@ class FishingAgent:
self.retry += 1 self.retry += 1
time.sleep(0.1) time.sleep(0.1)
res = self.monitor.findMatch(self.fishingBobberImg) res = self.monitor.findMatch(self.fishingBobberImg)
print(self.lureLoc)
print(res) print(res)
if (res != -1 and abs(res[1] - self.lureLoc[1]) > 10): if (res != -1 and abs(res[1] - self.lureLoc[1]) > 20):
time.sleep(0.2)
pyautogui.click() pyautogui.click()
time.sleep(0.5) time.sleep(0.5)
return return
elif (self.retry > 200): elif (self.retry > 200):
self.retry = 0
self.fail += 1
return return
def run(self): def run(self):

View File

@ -1,16 +1,15 @@
import time import time
from threading import Thread
import pyautogui import pyautogui
from threading import Thread
from core.Logger import Logger 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, playerAgent) -> None:
self.logger = Logger("Idling Agent") self.logger = Logger("Idling Agent")
self.idleTime = time.time() self.idleTime = time.time()
self.idleThread = None self.idleThread = None
self.player = playerAgent self.player = playerAgent
self.monitor = monitor
def checkIdleTime(self): def checkIdleTime(self):
while self.player.state is PLAYER_STATE.IDLE: while self.player.state is PLAYER_STATE.IDLE:

View File

@ -6,13 +6,14 @@ from core.Player import Player, PLAYER_STATE
class MainAgent: class MainAgent:
def __init__(self) -> None: def __init__(self) -> None:
self.monitor = Monitor() self.monitor = Monitor()
self.playerAgent = Player(self.monitor) self.playerAgent = Player()
self.idlingBot = IdlingAgent(self.monitor, self.playerAgent) self.idlingBot = IdlingAgent(self.playerAgent)
self.fishingBot = FishingAgent(self.monitor, self.playerAgent) self.fishingBot = FishingAgent(self.monitor, self.playerAgent)
self.monitor.startScreenCaptureThread() self.monitor.startScreenCaptureThread()
# Start idling agent at the construction of the mainAgent for now # Start idling agent at the construction of the mainAgent for now
self.idlingBot.run() self.idlingBot.run()
def startFishBot(self): def startFishBot(self):
self.playerAgent.changeState(PLAYER_STATE.FISHING) self.playerAgent.changeState(PLAYER_STATE.FISHING)
self.fishingBot.run() self.fishingBot.run()

View File

@ -45,9 +45,6 @@ class Monitor:
self.screenThread.start() self.screenThread.start()
self.logger.log("Main Agent: Thread started") self.logger.log("Main Agent: Thread started")
def findBestMatchFromDir(self, dirPath):
pass
def findMatch(self, template, method = "TM_CCOEFF_NORMED"): def findMatch(self, template, method = "TM_CCOEFF_NORMED"):
methodInt = getattr(cv, method) methodInt = getattr(cv, method)
res = cv.matchTemplate(self.screenshot, template, methodInt) res = cv.matchTemplate(self.screenshot, template, methodInt)
@ -56,7 +53,7 @@ class Monitor:
matchRatio = max_val * 100 matchRatio = max_val * 100
self.logger.log(matchRatio) self.logger.log(matchRatio)
if (matchRatio < 60): if (matchRatio < 55):
self.logger.log("Cannot find matching result...") self.logger.log("Cannot find matching result...")
return -1 return -1

View File

@ -1,8 +1,5 @@
import json import json
from enum import Enum from enum import Enum
import time
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,33 +7,16 @@ CLASSES = Enum('CLASSES', ['DRUID', 'MAGE', 'HUNTER', 'PRIEST'])
PLAYER_STATE = Enum('STATE', ['IDLE', 'FISHING', 'FARMING']) PLAYER_STATE = Enum('STATE', ['IDLE', 'FISHING', 'FARMING'])
class Player: class Player:
def __init__(self, monitor) -> None: def __init__(self) -> None:
with open("config.json", encoding="utf-8") as jsonFile: with open("config.json", encoding="utf-8") as jsonFile:
self.config = json.load(jsonFile) self.config = json.load(jsonFile)
self.isConnected = None self.isConnected = CONNECT_STATUS.DISCONNECTED
self.idleThread = None self.idleThread = None
self.enterWorldButton = cv.imread("assets/menus/EnterWorldButton.jpg", cv.IMREAD_GRAYSCALE)
self.logger = Logger("Player Agent") self.logger = Logger("Player Agent")
self.state = PLAYER_STATE.IDLE self.state = PLAYER_STATE.IDLE
self.monitor = monitor
self.playerClass = self.config["class"] self.playerClass = self.config["class"]
self.playerName = self.config["name"] self.playerName = self.config["name"]
self.logger.log("Connected with " + self.playerName + " (" + self.playerClass + ")") 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): def changeState(self, newState):
self.state = newState self.state = newState

View File

@ -33,7 +33,7 @@ class CLIAgent:
cv.destroyAllWindows() cv.destroyAllWindows()
self.logger.log("Exiting application...") self.logger.log("Exiting application...")
self.isRunning = False self.isRunning = False
else: else:
self.logger.log("Unknown Command.") self.logger.log("Unknown Command.")
self.printMenu() self.printMenu()