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-11-19 13:19:27 +00:00
|
|
|
from fishy.engine.fullautofisher.engine import FullAuto, State
|
2020-10-15 01:26:31 +00:00
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
from fishy.helper import helper
|
2020-10-18 13:53:46 +00:00
|
|
|
from fishy.helper.config import config
|
2020-11-19 13:19:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _get_rec_file():
|
|
|
|
file = config.get("full_auto_rec_file")
|
|
|
|
|
|
|
|
if not file:
|
|
|
|
logging.error("Please select a fishy file first from config")
|
|
|
|
return None
|
|
|
|
|
|
|
|
file = open(file, 'rb')
|
|
|
|
data = pickle.load(file)
|
|
|
|
file.close()
|
|
|
|
pprint(data)
|
|
|
|
if "full_auto_path" not in data:
|
|
|
|
logging.error("invalid file")
|
|
|
|
return None
|
|
|
|
return data["full_auto_path"]
|
2020-10-15 01:26:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
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
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
def toggle_move(self):
|
|
|
|
if FullAuto.state != State.PLAYING and FullAuto.state != State.NONE:
|
|
|
|
return
|
2020-10-15 01:26:31 +00:00
|
|
|
|
2020-10-17 22:04:25 +00:00
|
|
|
self.start_moving_flag = not self.start_moving_flag
|
2020-11-19 13:19:27 +00:00
|
|
|
if self.start_moving_flag:
|
|
|
|
self._start_route()
|
2020-11-30 21:04:33 +00:00
|
|
|
else:
|
|
|
|
logging.info("Waiting for the last action to finish...")
|
2020-10-15 01:26:31 +00:00
|
|
|
|
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
|
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
def _start_route(self):
|
|
|
|
FullAuto.state = State.PLAYING
|
|
|
|
timeline = _get_rec_file()
|
|
|
|
if not timeline:
|
2020-10-15 01:26:31 +00:00
|
|
|
return
|
2020-10-15 03:19:08 +00:00
|
|
|
|
2020-10-17 22:04:25 +00:00
|
|
|
forward = True
|
|
|
|
i = 0
|
|
|
|
while self.start_moving_flag:
|
2020-11-19 13:19:27 +00:00
|
|
|
action = timeline[i]
|
2020-10-17 22:04:25 +00:00
|
|
|
|
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)
|
2020-11-07 16:40:57 +00:00
|
|
|
self.engine.rotate_back()
|
2020-10-17 22:04:25 +00:00
|
|
|
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
|
2020-11-19 13:19:27 +00:00
|
|
|
if i >= len(timeline):
|
2020-10-17 22:04:25 +00:00
|
|
|
forward = False
|
2020-11-19 13:19:27 +00:00
|
|
|
i = len(timeline) - 1
|
2020-10-17 22:04:25 +00:00
|
|
|
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")
|
2020-11-19 13:19:27 +00:00
|
|
|
FullAuto.state = State.NONE
|