diff --git a/fishy/engine/fullautofisher/calibrate.py b/fishy/engine/fullautofisher/calibrator.py similarity index 75% rename from fishy/engine/fullautofisher/calibrate.py rename to fishy/engine/fullautofisher/calibrator.py index de01b3b..237751a 100644 --- a/fishy/engine/fullautofisher/calibrate.py +++ b/fishy/engine/fullautofisher/calibrator.py @@ -47,7 +47,7 @@ def _get_factor(key): return config.get("full_auto_factors", {}).get(key) -class Calibrate: +class Calibrator: def __init__(self, engine: FullAuto): self._callibrate_state = -1 self.engine = engine @@ -60,10 +60,6 @@ class Calibrate: def rot_factor(self): return _get_factor("rot_factor") - @property - def time_to_reach_bottom(self): - return _get_factor("time_to_reach_bottom") - # endregion def all_callibrated(self): @@ -72,7 +68,7 @@ class Calibrate: def toggle_show(self): self.engine.show_crop = not self.engine.show_crop - def walk_calibrate(self): + def _walk_calibrate(self): walking_time = 3 coods = self.engine.get_coods() @@ -95,7 +91,7 @@ class Calibrate: _update_factor("move_factor", move_factor) logging.info("done") - def rotate_calibrate(self): + def _rotate_calibrate(self): rotate_times = 50 coods = self.engine.get_coods() @@ -119,25 +115,7 @@ class Calibrate: _update_factor("rot_factor", rot_factor) logging.info("done") - def time_to_reach_bottom_callibrate(self): - self._callibrate_state = 0 + def calibrate(self): + self._walk_calibrate() + self._rotate_calibrate() - def _f8_pressed(): - self._callibrate_state += 1 - - logging.info("look straight up and press f8") - hotkey.set_hotkey(Key.F8, _f8_pressed) - - wait_until(lambda: self._callibrate_state == 1) - - logging.info("as soon as you look on the floor, press f8 again") - - y_cal_start_time = time.time() - while self._callibrate_state == 1: - mse.move(0, FullAuto.rotate_by) - time.sleep(0.05) - hotkey.free_key(Key.F8) - - time_to_reach_bottom = time.time() - y_cal_start_time - _update_factor("time_to_reach_bottom", time_to_reach_bottom) - logging.info("done") diff --git a/fishy/engine/fullautofisher/controls.py b/fishy/engine/fullautofisher/controls.py index 1ee275d..979ddc7 100644 --- a/fishy/engine/fullautofisher/controls.py +++ b/fishy/engine/fullautofisher/controls.py @@ -11,16 +11,10 @@ def get_controls(engine: FullAuto): from fishy.engine.fullautofisher.player import Player controls = [ ("MODE_SELECT", { - Key.RIGHT: (lambda: engine.controls.select_mode("CALIBRATE"), "calibrate mode"), - Key.UP: (lambda: engine.controls.select_mode("TEST1"), "test mode"), + Key.RIGHT: (Recorder(engine).toggle_recording, "start/stop record"), + Key.UP: (engine.calibrator.calibrate, "calibrate mode"), Key.LEFT: (Player(engine).toggle_move, "start/stop play"), - Key.DOWN: (Recorder(engine).toggle_recording, "start/stop record"), - }), - ("CALIBRATE", { - Key.RIGHT: (None, ""), - Key.UP: (engine.calibrate.walk_calibrate, "walking"), - Key.LEFT: (engine.calibrate.rotate_calibrate, "rotation"), - Key.DOWN: (engine.calibrate.time_to_reach_bottom_callibrate, "look up down") + Key.DOWN: (lambda: engine.controls.select_mode("TEST1"), "test mode"), }), ("TEST1", { Key.RIGHT: (engine.test.print_coods, "print coordinates"), diff --git a/fishy/engine/fullautofisher/engine.py b/fishy/engine/fullautofisher/engine.py index a775266..c929bbc 100644 --- a/fishy/engine/fullautofisher/engine.py +++ b/fishy/engine/fullautofisher/engine.py @@ -14,6 +14,7 @@ import time import numpy as np import pytesseract +from fishy.constants import libgps, fishyqr, lam2 from fishy.engine.fullautofisher.qr_detection import get_values_from_image, get_qr_location from fishy.engine.semifisher.fishing_mode import FishingMode @@ -24,9 +25,9 @@ from fishy.engine.semifisher import fishing_mode, fishing_event from fishy.engine.common.IEngine import IEngine from pynput import keyboard, mouse -from fishy.helper import hotkey, helper +from fishy.helper import hotkey, helper, hotkey_process from fishy.helper.config import config -from fishy.helper.helper import sign +from fishy.helper.helper import sign, addon_exists from fishy.helper.hotkey import Key mse = mouse.Controller() @@ -56,7 +57,7 @@ class FullAuto(IEngine): def __init__(self, gui_ref): from fishy.engine.fullautofisher.controls import Controls from fishy.engine.fullautofisher import controls - from fishy.engine.fullautofisher.calibrate import Calibrate + from fishy.engine.fullautofisher.calibrator import Calibrator from fishy.engine.fullautofisher.test import Test super().__init__(gui_ref) @@ -64,7 +65,7 @@ class FullAuto(IEngine): self._curr_rotate_y = 0 self.fisher = SemiFisherEngine(None) - self.calibrate = Calibrate(self) + self.calibrator = Calibrator(self) self.test = Test(self) self.controls = Controls(controls.get_controls(self)) self.show_crop = False @@ -73,19 +74,20 @@ class FullAuto(IEngine): FullAuto.state = State.NONE self.gui.bot_started(True) - fishing_event.unsubscribe() - self.fisher.toggle_start() - self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug") try: self.window.crop = get_qr_location(self.window.get_capture()) if self.window.crop is None: - print("FishyQR not found") + logging.warning("FishyQR not found") self.start = False + raise Exception("FishyQR not found") - if not self.calibrate.all_callibrated(): - logging.error("you need to callibrate first") + if not self.calibrator.all_callibrated(): + logging.error("you need to calibrate first") + + self.fisher.toggle_start() + fishing_event.unsubscribe() self.controls.initialize() while self.start and WindowClient.running(): @@ -115,7 +117,7 @@ class FullAuto(IEngine): logging.error("set target first") return - if not self.calibrate.all_callibrated(): + if not self.calibrator.all_callibrated(): logging.error("you need to callibrate first") return @@ -134,7 +136,7 @@ class FullAuto(IEngine): self.rotate_to(target_angle, from_angle) - walking_time = dist / self.calibrate.move_factor + walking_time = dist / self.calibrator.move_factor print(f"walking for {walking_time}") kb.press('w') time.sleep(walking_time) @@ -156,7 +158,7 @@ class FullAuto(IEngine): if abs(angle_diff) > 180: angle_diff = (360 - abs(angle_diff)) * sign(angle_diff) * -1 - rotate_times = int(angle_diff / self.calibrate.rot_factor) * -1 + rotate_times = int(angle_diff / self.calibrator.rot_factor) * -1 print(f"rotate_times: {rotate_times}") @@ -177,7 +179,7 @@ class FullAuto(IEngine): fishing_mode.subscribers.append(found_hole) t = 0 - while not self._hole_found_flag and t <= self.calibrate.time_to_reach_bottom / 3: + while not self._hole_found_flag and t <= 4.47: mse.move(0, FullAuto.rotate_by) time.sleep(0.05) t += 0.05