mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
move to target created
This commit is contained in:
parent
1418271583
commit
066ec93742
Binary file not shown.
@ -1,2 +1,2 @@
|
||||
from fishy.__main__ import main
|
||||
__version__ = "0.3.7"
|
||||
__version__ = "0.3.8"
|
||||
|
@ -12,9 +12,15 @@ from fishy.engine.window import Window
|
||||
from pynput import keyboard, mouse
|
||||
from pynput.keyboard import Key
|
||||
|
||||
from fishy.helper import Config
|
||||
|
||||
mse = mouse.Controller()
|
||||
kb = keyboard.Controller()
|
||||
|
||||
rotate_by = 30
|
||||
|
||||
def sign(x):
|
||||
return -1 if x < 0 else 1
|
||||
|
||||
def get_crop_coods(window):
|
||||
Window.loop()
|
||||
@ -49,7 +55,7 @@ def image_pre_process(img):
|
||||
# noinspection PyBroadException
|
||||
def get_values_from_image(img, tesseract_dir):
|
||||
try:
|
||||
pytesseract.pytesseract.tesseract_cmd = tesseract_dir+'/tesseract.exe'
|
||||
pytesseract.pytesseract.tesseract_cmd = tesseract_dir + '/tesseract.exe'
|
||||
tessdata_dir_config = f'--tessdata-dir "{tesseract_dir}" -c tessedit_char_whitelist=0123456789.'
|
||||
|
||||
text = pytesseract.image_to_string(img, lang="eng", config=tessdata_dir_config)
|
||||
@ -63,8 +69,14 @@ def get_values_from_image(img, tesseract_dir):
|
||||
class FullAuto(IEngine):
|
||||
def __init__(self, config, gui_ref):
|
||||
super().__init__(config, gui_ref)
|
||||
self.factors = None
|
||||
self.factors = self.config.get("full_auto_factors", None)
|
||||
self.tesseract_dir = None
|
||||
self.target = None
|
||||
|
||||
if self.factors is None:
|
||||
logging.warning("Please callibrate first")
|
||||
else:
|
||||
print(self.factors)
|
||||
|
||||
def run(self):
|
||||
|
||||
@ -88,14 +100,14 @@ class FullAuto(IEngine):
|
||||
if self.get_gui is not None:
|
||||
self.gui.bot_started(True)
|
||||
|
||||
logging.info("Controlls:\nUP: Callibrate\nLEFT: Pring Coordinates\nDOWN: Quit")
|
||||
logging.info("Controlls:\nUP: Callibrate\nLEFT: Print Coordinates\nDOWN: Set target\nRIGHT: Move to target")
|
||||
with keyboard.Listener(
|
||||
on_press=self.on_press,
|
||||
):
|
||||
while self.start:
|
||||
Window.loop()
|
||||
|
||||
self.window.show("test", func=image_pre_process)
|
||||
# self.window.show("test", func=image_pre_process)
|
||||
Window.loop_end()
|
||||
self.gui.bot_started(False)
|
||||
|
||||
@ -105,7 +117,7 @@ class FullAuto(IEngine):
|
||||
def callibrate(self):
|
||||
logging.debug("Callibrating...")
|
||||
walking_time = 3
|
||||
rotate_by = 100
|
||||
rotate_times = 50
|
||||
|
||||
coods = self.get_coods()
|
||||
if coods is None:
|
||||
@ -123,8 +135,9 @@ class FullAuto(IEngine):
|
||||
return
|
||||
x2, y2, rot2 = coods
|
||||
|
||||
mse.move(rotate_by, 0)
|
||||
time.sleep(0.5)
|
||||
for _ in range(rotate_times):
|
||||
mse.move(rotate_by, 0)
|
||||
time.sleep(0.05)
|
||||
|
||||
coods = self.get_coods()
|
||||
if coods is None:
|
||||
@ -134,29 +147,71 @@ class FullAuto(IEngine):
|
||||
if rot3 > rot2:
|
||||
rot3 -= 360
|
||||
|
||||
rot_factor = (rot3 - rot2) / rotate_by
|
||||
rot_factor = (rot3 - rot2) / rotate_times
|
||||
move_factor = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) / walking_time
|
||||
self.config.set("full_auto_factors", (move_factor, rot_factor))
|
||||
self.factors = move_factor, rot_factor
|
||||
logging.info(self.factors)
|
||||
|
||||
def move_to(self, target):
|
||||
if target is None:
|
||||
logging.error("set target first")
|
||||
return
|
||||
|
||||
if self.factors is None:
|
||||
logging.error("you need to callibrate first")
|
||||
return
|
||||
|
||||
current = self.get_coods()
|
||||
print(f"Moving from {(current[0], current[1])} to {self.target}")
|
||||
move_vec = target[0] - current[0], target[1] - current[1]
|
||||
target_angle = math.degrees(math.atan2(-move_vec[1], move_vec[0]))
|
||||
if target_angle < 0:
|
||||
target_angle = 360 + target_angle
|
||||
target_angle += 90
|
||||
while target_angle > 360:
|
||||
target_angle -= 360
|
||||
print(f"Rotating from {current[2]} to {target_angle}")
|
||||
|
||||
angle_diff = target_angle - current[2]
|
||||
|
||||
if abs(angle_diff) > 180:
|
||||
angle_diff = (360 - abs(angle_diff))*sign(angle_diff)*-1
|
||||
|
||||
rotate_times = int(angle_diff / self.factors[1]) * -1
|
||||
walking_time = math.sqrt(move_vec[0]**2 + move_vec[1]**2) / self.factors[0]
|
||||
|
||||
print(f"Rotating by {angle_diff}\nrotate_times {rotate_times}\nwalking_time {walking_time}")
|
||||
|
||||
for _ in range(abs(rotate_times)):
|
||||
mse.move(sign(rotate_times)*rotate_by*-1, 0)
|
||||
time.sleep(0.05)
|
||||
|
||||
kb.press('w')
|
||||
time.sleep(walking_time)
|
||||
kb.release('w')
|
||||
print("done")
|
||||
|
||||
def on_press(self, key):
|
||||
if key == Key.down:
|
||||
bot.start = False
|
||||
self.toggle_start()
|
||||
if self.get_gui is not None:
|
||||
quit()
|
||||
elif key == Key.left:
|
||||
if key == Key.left:
|
||||
logging.info(self.get_coods())
|
||||
elif key == Key.up:
|
||||
self.callibrate()
|
||||
elif key == Key.right:
|
||||
self.move_to(self.config.get("target", None))
|
||||
elif key == Key.down:
|
||||
t = self.get_coods()[:-1]
|
||||
self.config.set("target", t)
|
||||
print(f"target_coods are {t}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.getLogger("").setLevel(logging.DEBUG)
|
||||
# noinspection PyTypeChecker
|
||||
bot = FullAuto(None, None)
|
||||
bot = FullAuto(Config(), None)
|
||||
bot.toggle_start()
|
||||
with keyboard.Listener(
|
||||
on_press=bot.on_press,
|
||||
on_release=bot.on_press,
|
||||
) as listener:
|
||||
listener.join()
|
||||
|
||||
|
@ -118,7 +118,7 @@ def _create(gui: 'GUI'):
|
||||
gui.call_in_thread(lambda: start_engine(engine_var.get()))
|
||||
|
||||
kb_listener = keyboard.Listener(
|
||||
on_press=keyboard_listener,
|
||||
on_release=keyboard_listener,
|
||||
)
|
||||
kb_listener.start()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user