71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
"""Module providing a fishing agent."""
|
|
|
|
from threading import Thread
|
|
import time
|
|
import cv2 as cv
|
|
import pyautogui
|
|
from core.Logger import Logger
|
|
|
|
class FishingAgent:
|
|
def __init__(self, monitor) -> None:
|
|
self.logger = Logger("Fishing Agent")
|
|
self.retry = 0
|
|
self.monitor = monitor
|
|
self.lureLoc = None
|
|
self.fishingBobberImg = cv.imread("assets/fishing/Bobber.jpg", cv.IMREAD_GRAYSCALE)
|
|
self.fishingIconImg = cv.imread("assets/fishing/FishIcon.jpg", cv.IMREAD_GRAYSCALE)
|
|
self.fishingThread = None
|
|
|
|
def castLure(self):
|
|
self.retry = 0
|
|
pyautogui.moveTo(2,3)
|
|
self.logger.log("Casting Lure.")
|
|
res = self.monitor.findMatchAndMoveToPosition(self.fishingIconImg)
|
|
if (res == -1):
|
|
self.logger.log("Trying again in 1 second...")
|
|
time.sleep(1)
|
|
self.castLure()
|
|
pyautogui.click()
|
|
self.findLure()
|
|
|
|
def findLure(self):
|
|
self.logger.log("Moving cursor to Lure.")
|
|
time.sleep(2)
|
|
res = self.monitor.findMatch(self.fishingBobberImg)
|
|
if (res == -1):
|
|
if (self.retry > 4):
|
|
self.logger.log("Took too to find lure long, retrying fishing from the beginning")
|
|
self.castLure()
|
|
else:
|
|
self.logger.log("Trying again in 1 second...")
|
|
self.retry += 1
|
|
time.sleep(1)
|
|
self.findLure()
|
|
self.lureLoc = res
|
|
self.watchLure()
|
|
|
|
def watchLure(self):
|
|
self.logger.log("Waiting for fish...")
|
|
while True:
|
|
time.sleep(0.1)
|
|
res = self.monitor.findMatch(self.fishingBobberImg)
|
|
print(res)
|
|
|
|
|
|
def pullLine(self):
|
|
self.logger.log("Pulling line!")
|
|
|
|
def run(self):
|
|
self.logger.log("Starting fishing thread in 3 seconds...")
|
|
time.sleep(1)
|
|
self.logger.log("Starting fishing thread in 2 seconds...")
|
|
time.sleep(1)
|
|
self.logger.log("Starting fishing thread in 1 seconds...")
|
|
time.sleep(1)
|
|
|
|
self.fishingThread = Thread(
|
|
target=self.castLure,
|
|
args=(),
|
|
name="fishing thread",
|
|
daemon=True)
|
|
self.fishingThread.start() |