2020-10-15 01:26:31 +00:00
|
|
|
import logging
|
2020-10-15 03:19:08 +00:00
|
|
|
import pickle
|
2020-10-17 19:45:57 +00:00
|
|
|
from pprint import pprint
|
2020-10-15 01:26:31 +00:00
|
|
|
|
2020-10-17 22:04:25 +00:00
|
|
|
from fishy.engine.semifisher import fishing_event, fishing_mode
|
2020-10-17 19:45:57 +00:00
|
|
|
|
2020-10-15 01:26:31 +00:00
|
|
|
from fishy.engine.fullautofisher.engine import FullAuto
|
|
|
|
|
2020-10-15 02:23:15 +00:00
|
|
|
from fishy.helper import hotkey, helper
|
2020-10-18 13:53:46 +00:00
|
|
|
from fishy.helper.config import config
|
2020-10-15 01:26:31 +00:00
|
|
|
from fishy.helper.hotkey import Key
|
|
|
|
|
|
|
|
|
|
|
|
class Player:
|
2020-10-15 03:19:08 +00:00
|
|
|
def __init__(self, engine: 'FullAuto'):
|
2020-10-15 01:26:31 +00:00
|
|
|
self.recording = False
|
|
|
|
self.engine = engine
|
|
|
|
self.timeline = []
|
2020-10-15 02:23:15 +00:00
|
|
|
self.hole_complete_flag = False
|
2020-10-15 03:19:08 +00:00
|
|
|
self.start_moving_flag = False
|
2020-10-15 01:26:31 +00:00
|
|
|
|
|
|
|
def _mark_hole(self):
|
|
|
|
coods = self.engine.get_coods()
|
|
|
|
self.timeline.append(("check_fish", coods))
|
|
|
|
|
2020-10-15 03:19:08 +00:00
|
|
|
def _start_moving(self):
|
2020-10-17 22:04:25 +00:00
|
|
|
self.start_moving_flag = not self.start_moving_flag
|
2020-10-15 03:19:08 +00:00
|
|
|
|
2020-10-15 01:26:31 +00:00
|
|
|
def _stop_recording(self):
|
|
|
|
self.recording = False
|
|
|
|
|
2020-10-15 02:23:15 +00:00
|
|
|
def _hole_complete_callback(self, e):
|
2020-10-17 22:04:25 +00:00
|
|
|
if e == fishing_event.State.IDLE:
|
2020-10-15 02:23:15 +00:00
|
|
|
self.hole_complete_flag = True
|
|
|
|
|
|
|
|
def start_route(self):
|
2020-10-18 13:53:46 +00:00
|
|
|
file = config.get("full_auto_rec_file")
|
2020-10-17 19:45:57 +00:00
|
|
|
|
2020-10-18 13:53:46 +00:00
|
|
|
if not file:
|
|
|
|
logging.error("Please select a fishy file first from config")
|
|
|
|
return
|
|
|
|
|
|
|
|
file = open(file, 'rb')
|
2020-10-15 03:19:08 +00:00
|
|
|
data = pickle.load(file)
|
|
|
|
file.close()
|
2020-10-17 19:45:57 +00:00
|
|
|
pprint(data)
|
2020-10-15 01:26:31 +00:00
|
|
|
if "full_auto_path" not in data:
|
2020-10-18 13:53:46 +00:00
|
|
|
logging.error("invalid file")
|
2020-10-15 01:26:31 +00:00
|
|
|
return
|
|
|
|
self.timeline = data["full_auto_path"]
|
|
|
|
|
2020-10-15 03:19:08 +00:00
|
|
|
# wait until f8 is pressed
|
|
|
|
logging.info("press f8 to start")
|
2020-10-17 19:45:57 +00:00
|
|
|
|
2020-10-15 03:19:08 +00:00
|
|
|
self.start_moving_flag = False
|
|
|
|
hotkey.set_hotkey(Key.F8, self._start_moving)
|
|
|
|
helper.wait_until(lambda: self.start_moving_flag)
|
|
|
|
|
2020-10-17 22:04:25 +00:00
|
|
|
logging.info("starting, press f8 to stop")
|
|
|
|
forward = True
|
|
|
|
i = 0
|
|
|
|
while self.start_moving_flag:
|
|
|
|
action = self.timeline[i]
|
|
|
|
|
2020-10-15 03:19:08 +00:00
|
|
|
if action[0] == "move_to":
|
2020-10-15 01:26:31 +00:00
|
|
|
self.engine.move_to(action[1])
|
2020-10-15 03:19:08 +00:00
|
|
|
elif action[0] == "check_fish":
|
2020-10-15 01:26:31 +00:00
|
|
|
self.engine.move_to(action[1])
|
|
|
|
self.engine.rotate_to(action[1][2])
|
2020-10-17 19:45:57 +00:00
|
|
|
fishing_event.subscribe()
|
2020-10-17 22:04:25 +00:00
|
|
|
fishing_mode.subscribers.append(self._hole_complete_callback)
|
2020-10-15 01:26:31 +00:00
|
|
|
# scan for fish hole
|
2020-10-15 03:19:08 +00:00
|
|
|
logging.info("scanning")
|
2020-10-15 02:23:15 +00:00
|
|
|
if self.engine.look_for_hole():
|
2020-10-17 22:04:25 +00:00
|
|
|
logging.info("starting fishing")
|
2020-10-15 02:23:15 +00:00
|
|
|
self.hole_complete_flag = False
|
2020-10-17 22:04:25 +00:00
|
|
|
helper.wait_until(lambda: self.hole_complete_flag or not self.start_moving_flag)
|
|
|
|
else:
|
|
|
|
logging.info("no hole found")
|
2020-10-15 01:26:31 +00:00
|
|
|
# if found start fishing and wait for hole to complete
|
|
|
|
# contine when hole completes
|
2020-10-17 22:04:25 +00:00
|
|
|
fishing_event.unsubscribe()
|
|
|
|
fishing_mode.subscribers.remove(self._hole_complete_callback)
|
|
|
|
|
|
|
|
i += 1 if forward else -1
|
|
|
|
if i >= len(self.timeline):
|
|
|
|
forward = False
|
|
|
|
i = len(self.timeline) - 1
|
|
|
|
elif i < 0:
|
|
|
|
forward = True
|
|
|
|
i = 0
|
2020-10-15 01:26:31 +00:00
|
|
|
|
2020-10-17 22:04:25 +00:00
|
|
|
logging.info("stopped")
|