80 lines
2.0 KiB
Python
80 lines
2.0 KiB
Python
"""Module providing a fishing agent."""
|
|
|
|
import os
|
|
from threading import Thread
|
|
import time
|
|
import cv2 as cv
|
|
import numpy as np
|
|
import pyautogui
|
|
|
|
class FishingAgent:
|
|
def __init__(self, mainAgent) -> None:
|
|
self.mainAgent = mainAgent
|
|
|
|
# interpolate here_path to get the path to the fishing target image
|
|
assetPath = os.path.join(
|
|
os.path.dirname(os.path.realpath(__file__)),
|
|
"assets"
|
|
)
|
|
assetPath = os.path.dirname(os.path.realpath(__file__))
|
|
print(assetPath)
|
|
self.fishingBobber = cv.imread(
|
|
os.path.join(
|
|
assetPath,
|
|
"assets", "Bobber.png"
|
|
)
|
|
)
|
|
self.fishingThread = None
|
|
|
|
def agentLog(self, log: str):
|
|
print("Fishing Agent: " + log)
|
|
|
|
def castLure(self):
|
|
self.agentLog("Casting Lure.")
|
|
# pyautogui.press('1')
|
|
time.sleep(1)
|
|
self.findLure()
|
|
|
|
def findLure(self):
|
|
if self.mainAgent.currImg is not None:
|
|
self.agentLog("Searching for Bobber.")
|
|
cv.imshow("Bobber", self.fishingBobber)
|
|
|
|
lureLoc = cv.matchTemplate(self.mainAgent.currImg, self.fishingBobber, cv.TM_CCORR_NORMED)
|
|
lureLocArray = np.array(lureLoc)
|
|
|
|
minVal, maxVal, minLoc, maxLoc = cv.minMaxLoc(lureLocArray)
|
|
self.moveToLure(maxLoc)
|
|
else:
|
|
print("No curr img")
|
|
|
|
def moveToLure(self, maxLoc):
|
|
if maxLoc:
|
|
self.agentLog("Moving to Bobber.")
|
|
pyautogui.moveTo(maxLoc)
|
|
|
|
def watchLure(self):
|
|
self.agentLog("Waiting for fish...")
|
|
|
|
def pullLine(self):
|
|
self.agentLog("Pulling line!")
|
|
|
|
def run(self):
|
|
if self.mainAgent.currImg is None:
|
|
print("Image capture not found! Did you start the screen capture thread?")
|
|
return
|
|
print("Starting fishing thread in 10 seconds...")
|
|
time.sleep(3)
|
|
|
|
# print("Switching to fishing hotbar (hotbar 4)")
|
|
# pyautogui.keyDown('shift')
|
|
# pyautogui.press('4')
|
|
# pyautogui.keyUp('shift')
|
|
# time.sleep(1)
|
|
|
|
self.fishingThread = Thread(
|
|
target=self.castLure,
|
|
args=(),
|
|
name="fishing thread",
|
|
daemon=True)
|
|
self.fishingThread.start() |