2020-06-24 23:16:23 +00:00
|
|
|
import math
|
2020-10-18 00:43:24 +00:00
|
|
|
import os
|
|
|
|
import tempfile
|
2020-11-19 13:19:27 +00:00
|
|
|
import traceback
|
2020-10-17 22:04:25 +00:00
|
|
|
import uuid
|
2020-11-19 13:19:27 +00:00
|
|
|
from enum import Enum
|
2020-10-18 00:43:24 +00:00
|
|
|
from zipfile import ZipFile
|
2020-10-17 08:06:49 +00:00
|
|
|
|
2020-06-03 01:41:54 +00:00
|
|
|
import cv2
|
2020-06-01 12:58:18 +00:00
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
|
2020-06-03 01:41:54 +00:00
|
|
|
import numpy as np
|
2020-06-24 23:16:23 +00:00
|
|
|
import pytesseract
|
2020-11-07 16:40:57 +00:00
|
|
|
|
|
|
|
from fishy.engine.fullautofisher.tesseract import is_tesseract_installed, downlaoad_and_extract_tesseract, \
|
|
|
|
get_values_from_image
|
2020-10-17 19:45:57 +00:00
|
|
|
from fishy.engine.semifisher.fishing_mode import FishingMode
|
2020-06-03 01:41:54 +00:00
|
|
|
|
2020-10-17 08:06:49 +00:00
|
|
|
from fishy.engine import SemiFisherEngine
|
2020-10-17 10:52:04 +00:00
|
|
|
from fishy.engine.common.window import WindowClient
|
2020-10-17 19:45:57 +00:00
|
|
|
from fishy.engine.semifisher import fishing_mode, fishing_event
|
2020-10-15 02:23:15 +00:00
|
|
|
|
2020-10-17 10:52:04 +00:00
|
|
|
from fishy.engine.common.IEngine import IEngine
|
2020-06-24 23:16:23 +00:00
|
|
|
from pynput import keyboard, mouse
|
|
|
|
|
2020-10-17 22:04:25 +00:00
|
|
|
from fishy.helper import hotkey, helper
|
2020-10-17 19:06:07 +00:00
|
|
|
from fishy.helper.config import config
|
2020-10-18 00:43:24 +00:00
|
|
|
from fishy.helper.downloader import download_file_from_google_drive
|
2020-11-07 16:40:57 +00:00
|
|
|
from fishy.helper.helper import sign
|
2020-10-15 01:26:31 +00:00
|
|
|
from fishy.helper.hotkey import Key
|
2020-06-25 13:40:05 +00:00
|
|
|
|
2020-06-24 23:16:23 +00:00
|
|
|
mse = mouse.Controller()
|
|
|
|
kb = keyboard.Controller()
|
|
|
|
|
|
|
|
|
|
|
|
def image_pre_process(img):
|
|
|
|
scale_percent = 200 # percent of original size
|
|
|
|
width = int(img.shape[1] * scale_percent / 100)
|
|
|
|
height = int(img.shape[0] * scale_percent / 100)
|
|
|
|
dim = (width, height)
|
|
|
|
img = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
|
|
|
|
img = cv2.bitwise_not(img)
|
|
|
|
return img
|
|
|
|
|
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
class State(Enum):
|
|
|
|
NONE = 0
|
|
|
|
PLAYING = 1
|
|
|
|
RECORDING = 2
|
|
|
|
OTHER = 3
|
|
|
|
|
|
|
|
|
2020-06-01 12:58:18 +00:00
|
|
|
class FullAuto(IEngine):
|
2020-10-15 01:26:31 +00:00
|
|
|
rotate_by = 30
|
2020-11-19 13:19:27 +00:00
|
|
|
state = State.NONE
|
2020-10-15 01:26:31 +00:00
|
|
|
|
2020-10-17 19:06:07 +00:00
|
|
|
def __init__(self, gui_ref):
|
2020-11-07 16:40:57 +00:00
|
|
|
from fishy.engine.fullautofisher.controls import Controls
|
|
|
|
from fishy.engine.fullautofisher import controls
|
|
|
|
from fishy.engine.fullautofisher.calibrate import Calibrate
|
|
|
|
from fishy.engine.fullautofisher.test import Test
|
2020-06-24 23:16:23 +00:00
|
|
|
|
2020-11-07 16:40:57 +00:00
|
|
|
super().__init__(gui_ref)
|
2020-10-15 02:23:15 +00:00
|
|
|
self._hole_found_flag = False
|
|
|
|
self._curr_rotate_y = 0
|
|
|
|
|
2020-10-17 22:35:20 +00:00
|
|
|
self.fisher = SemiFisherEngine(None)
|
2020-11-07 16:40:57 +00:00
|
|
|
self.calibrate = Calibrate(self)
|
|
|
|
self.test = Test(self)
|
2020-11-19 13:19:27 +00:00
|
|
|
self.controls = Controls(controls.get_controls(self))
|
2020-10-17 22:35:20 +00:00
|
|
|
|
2020-10-17 23:12:48 +00:00
|
|
|
@property
|
2020-11-07 16:40:57 +00:00
|
|
|
def show_crop(self):
|
2020-10-17 23:12:48 +00:00
|
|
|
return config.get("show_window_full_auto", False)
|
|
|
|
|
2020-11-07 16:40:57 +00:00
|
|
|
@show_crop.setter
|
|
|
|
def show_crop(self, x):
|
2020-10-17 23:12:48 +00:00
|
|
|
config.set("show_window_full_auto", x)
|
|
|
|
|
2020-06-01 12:58:18 +00:00
|
|
|
def run(self):
|
2020-06-25 18:43:53 +00:00
|
|
|
logging.info("Loading please wait...")
|
2020-10-18 00:43:24 +00:00
|
|
|
self.gui.bot_started(True)
|
2020-10-17 22:35:20 +00:00
|
|
|
fishing_event.unsubscribe()
|
|
|
|
self.fisher.toggle_start()
|
2020-06-03 01:41:54 +00:00
|
|
|
|
2020-10-17 10:52:04 +00:00
|
|
|
self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug")
|
2020-06-24 23:16:23 +00:00
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
try:
|
|
|
|
if self.calibrate.crop is None:
|
|
|
|
self.calibrate.update_crop(enable_crop=False)
|
|
|
|
self.window.crop = self.calibrate.crop
|
|
|
|
|
|
|
|
if not is_tesseract_installed():
|
|
|
|
logging.info("tesseract not found")
|
|
|
|
downlaoad_and_extract_tesseract()
|
|
|
|
|
|
|
|
self.controls.initialize()
|
|
|
|
while self.start and WindowClient.running():
|
|
|
|
self.window.show(self.show_crop, func=image_pre_process)
|
|
|
|
if not self.show_crop:
|
|
|
|
time.sleep(0.1)
|
|
|
|
except:
|
|
|
|
traceback.print_exc()
|
2020-06-03 01:41:54 +00:00
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
if not self.window.get_capture():
|
|
|
|
logging.error("Game window not found")
|
2020-10-17 19:45:57 +00:00
|
|
|
|
2020-06-01 12:58:18 +00:00
|
|
|
self.gui.bot_started(False)
|
2020-10-17 22:35:20 +00:00
|
|
|
self.controls.unassign_keys()
|
2020-10-17 23:12:48 +00:00
|
|
|
self.window.show(False)
|
2020-11-19 13:19:27 +00:00
|
|
|
logging.info("Quitting")
|
2020-10-17 23:12:48 +00:00
|
|
|
self.window.destory()
|
|
|
|
self.fisher.toggle_start()
|
2020-06-03 01:41:54 +00:00
|
|
|
|
2020-06-24 23:16:23 +00:00
|
|
|
def get_coods(self):
|
2020-11-07 16:40:57 +00:00
|
|
|
img = self.window.processed_image(func=image_pre_process)
|
|
|
|
return get_values_from_image(img)
|
2020-06-24 23:16:23 +00:00
|
|
|
|
2020-06-25 13:40:05 +00:00
|
|
|
def move_to(self, target):
|
|
|
|
if target is None:
|
|
|
|
logging.error("set target first")
|
|
|
|
return
|
|
|
|
|
2020-11-07 16:40:57 +00:00
|
|
|
if not self.calibrate.all_callibrated():
|
2020-06-25 13:40:05 +00:00
|
|
|
logging.error("you need to callibrate first")
|
|
|
|
return
|
|
|
|
|
|
|
|
current = self.get_coods()
|
2020-10-17 22:04:25 +00:00
|
|
|
print(f"Moving from {(current[0], current[1])} to {target}")
|
2020-06-25 13:40:05 +00:00
|
|
|
move_vec = target[0] - current[0], target[1] - current[1]
|
2020-10-17 22:04:25 +00:00
|
|
|
|
|
|
|
dist = math.sqrt(move_vec[0] ** 2 + move_vec[1] ** 2)
|
|
|
|
print(f"distance: {dist}")
|
|
|
|
if dist < 5e-05:
|
|
|
|
print("distance very small skipping")
|
|
|
|
return
|
|
|
|
|
|
|
|
target_angle = math.degrees(math.atan2(-move_vec[1], move_vec[0])) + 90
|
2020-10-15 01:26:31 +00:00
|
|
|
from_angle = current[2]
|
|
|
|
|
|
|
|
self.rotate_to(target_angle, from_angle)
|
|
|
|
|
2020-11-07 16:40:57 +00:00
|
|
|
walking_time = dist / self.calibrate.move_factor
|
2020-10-15 01:26:31 +00:00
|
|
|
print(f"walking for {walking_time}")
|
|
|
|
kb.press('w')
|
|
|
|
time.sleep(walking_time)
|
|
|
|
kb.release('w')
|
|
|
|
print("done")
|
|
|
|
|
|
|
|
def rotate_to(self, target_angle, from_angle=None):
|
2020-10-17 19:45:57 +00:00
|
|
|
if from_angle is None:
|
2020-10-15 01:26:31 +00:00
|
|
|
_, _, from_angle = self.get_coods()
|
|
|
|
|
2020-06-25 13:40:05 +00:00
|
|
|
if target_angle < 0:
|
|
|
|
target_angle = 360 + target_angle
|
|
|
|
while target_angle > 360:
|
|
|
|
target_angle -= 360
|
2020-10-15 01:26:31 +00:00
|
|
|
print(f"Rotating from {from_angle} to {target_angle}")
|
2020-06-25 13:40:05 +00:00
|
|
|
|
2020-10-15 01:26:31 +00:00
|
|
|
angle_diff = target_angle - from_angle
|
2020-06-25 13:40:05 +00:00
|
|
|
|
|
|
|
if abs(angle_diff) > 180:
|
2020-06-25 16:39:05 +00:00
|
|
|
angle_diff = (360 - abs(angle_diff)) * sign(angle_diff) * -1
|
2020-06-25 13:40:05 +00:00
|
|
|
|
2020-11-07 16:40:57 +00:00
|
|
|
rotate_times = int(angle_diff / self.calibrate.rot_factor) * -1
|
2020-06-25 13:40:05 +00:00
|
|
|
|
2020-10-15 01:26:31 +00:00
|
|
|
print(f"rotate_times: {rotate_times}")
|
2020-06-25 13:40:05 +00:00
|
|
|
|
|
|
|
for _ in range(abs(rotate_times)):
|
2020-10-15 01:26:31 +00:00
|
|
|
mse.move(sign(rotate_times) * FullAuto.rotate_by * -1, 0)
|
2020-06-25 13:40:05 +00:00
|
|
|
time.sleep(0.05)
|
|
|
|
|
2020-10-15 02:23:15 +00:00
|
|
|
def look_for_hole(self):
|
|
|
|
self._hole_found_flag = False
|
|
|
|
|
2020-10-17 19:45:57 +00:00
|
|
|
if FishingMode.CurrentMode == fishing_mode.State.LOOK:
|
|
|
|
return True
|
|
|
|
|
2020-10-15 02:23:15 +00:00
|
|
|
def found_hole(e):
|
2020-10-17 19:45:57 +00:00
|
|
|
if e == fishing_mode.State.LOOK:
|
2020-10-15 02:23:15 +00:00
|
|
|
self._hole_found_flag = True
|
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
fishing_mode.subscribers.append(found_hole)
|
2020-10-15 02:23:15 +00:00
|
|
|
|
|
|
|
t = 0
|
2020-11-07 16:40:57 +00:00
|
|
|
while not self._hole_found_flag and t <= self.calibrate.time_to_reach_bottom / 3:
|
2020-10-15 02:23:15 +00:00
|
|
|
mse.move(0, FullAuto.rotate_by)
|
|
|
|
time.sleep(0.05)
|
|
|
|
t += 0.05
|
2020-10-17 08:06:49 +00:00
|
|
|
while not self._hole_found_flag and t > 0:
|
2020-10-15 02:23:15 +00:00
|
|
|
mse.move(0, -FullAuto.rotate_by)
|
|
|
|
time.sleep(0.05)
|
|
|
|
t -= 0.05
|
|
|
|
|
|
|
|
self._curr_rotate_y = t
|
2020-10-17 16:04:44 +00:00
|
|
|
fishing_mode.subscribers.remove(found_hole)
|
2020-10-15 02:23:15 +00:00
|
|
|
return self._hole_found_flag
|
|
|
|
|
2020-10-17 19:45:57 +00:00
|
|
|
def rotate_back(self):
|
|
|
|
while self._curr_rotate_y > 0.01:
|
|
|
|
mse.move(0, -FullAuto.rotate_by)
|
|
|
|
time.sleep(0.05)
|
|
|
|
self._curr_rotate_y -= 0.05
|
|
|
|
|
2020-06-03 01:41:54 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-06-24 23:16:23 +00:00
|
|
|
logging.getLogger("").setLevel(logging.DEBUG)
|
2020-10-17 22:35:20 +00:00
|
|
|
hotkey.initalize()
|
2020-06-25 01:22:39 +00:00
|
|
|
# noinspection PyTypeChecker
|
2020-10-17 19:06:07 +00:00
|
|
|
bot = FullAuto(None)
|
2020-06-03 01:41:54 +00:00
|
|
|
bot.toggle_start()
|