Make fishing agent capable of detecting bobber
This commit is contained in:
@@ -1,73 +1,67 @@
|
||||
"""Module providing a fishing agent."""
|
||||
|
||||
import os
|
||||
from threading import Thread
|
||||
import time
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
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
|
||||
assetPath = os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)),
|
||||
"..\\..\\assets"
|
||||
)
|
||||
self.fishingBobberImg = cv.imread(os.path.join(assetPath,"fishing","Bobber.png"), cv.IMREAD_GRAYSCALE)
|
||||
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.agentLog("Casting Lure.")
|
||||
# pyautogui.press('1')
|
||||
time.sleep(1)
|
||||
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):
|
||||
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)
|
||||
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.agentLog("Waiting for fish...")
|
||||
self.logger.log("Waiting for fish...")
|
||||
while True:
|
||||
time.sleep(0.1)
|
||||
res = self.monitor.findMatch(self.fishingBobberImg)
|
||||
print(res)
|
||||
|
||||
|
||||
def pullLine(self):
|
||||
self.agentLog("Pulling line!")
|
||||
|
||||
def test(self):
|
||||
while True:
|
||||
time.sleep(1)
|
||||
self.logger.log("###")
|
||||
point = self.monitor.findMatch(self.fishingBobberImg)
|
||||
pyautogui.moveTo(point[0], point[1])
|
||||
self.logger.log("Pulling line!")
|
||||
|
||||
def run(self):
|
||||
if self.monitor.screenshot is None:
|
||||
self.logger.log("Screenshot capture not found...")
|
||||
return
|
||||
self.logger.log("Starting fishing thread in 3 seconds...")
|
||||
time.sleep(3)
|
||||
|
||||
# print("Switching to fishing hotbar (hotbar 4)")
|
||||
# pyautogui.keyDown('shift')
|
||||
# pyautogui.press('4')
|
||||
# pyautogui.keyUp('shift')
|
||||
# time.sleep(1)
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user