fishyboteso/fishy/engine/fullautofisher/player.py

76 lines
2.3 KiB
Python
Raw Normal View History

import logging
import pickle
from pprint import pprint
2020-10-17 19:06:07 +00:00
from tkinter.filedialog import askopenfile
from fishy.engine.semifisher import fishing_event
from fishy.engine.fullautofisher.engine import FullAuto
2020-10-15 02:23:15 +00:00
from fishy.helper import hotkey, helper
from fishy.helper.hotkey import Key
class Player:
def __init__(self, engine: 'FullAuto'):
self.recording = False
self.engine = engine
self.timeline = []
2020-10-15 02:23:15 +00:00
self.hole_complete_flag = False
self.start_moving_flag = False
def _mark_hole(self):
coods = self.engine.get_coods()
self.timeline.append(("check_fish", coods))
def _start_moving(self):
self.start_moving_flag = True
def _stop_recording(self):
self.recording = False
2020-10-15 02:23:15 +00:00
def _hole_complete_callback(self, e):
if e == "idle":
self.hole_complete_flag = True
def start_route(self):
# file = askopenfile(mode='rb', filetypes=[('Python Files', '*.fishy')])
# if not file:
# logging.error("file not selected")
# return
file = open(r"C:\Users\adam_\Desktop\test3.fishy", 'rb')
data = pickle.load(file)
file.close()
pprint(data)
if "full_auto_path" not in data:
logging.error("incorrect file")
return
self.timeline = data["full_auto_path"]
# wait until f8 is pressed
logging.info("press f8 to start")
self.start_moving_flag = False
hotkey.set_hotkey(Key.F8, self._start_moving)
helper.wait_until(lambda: self.start_moving_flag)
logging.info("starting")
for action in self.timeline:
fishing_event.unsubscribe()
if action[0] == "move_to":
self.engine.move_to(action[1])
logging.info("moved")
elif action[0] == "check_fish":
self.engine.move_to(action[1])
self.engine.rotate_to(action[1][2])
fishing_event.subscribe()
# scan for fish hole
logging.info("scanning")
2020-10-15 02:23:15 +00:00
if self.engine.look_for_hole():
self.hole_complete_flag = False
helper.wait_until(lambda: self.hole_complete_flag)
# if found start fishing and wait for hole to complete
# contine when hole completes