2021-05-09 07:05:51 +00:00
|
|
|
import logging
|
2020-05-14 02:03:13 +00:00
|
|
|
import time
|
2020-05-19 03:11:58 +00:00
|
|
|
import typing
|
2020-05-14 02:03:13 +00:00
|
|
|
from threading import Thread
|
2021-05-09 07:05:51 +00:00
|
|
|
from typing import Callable, Optional
|
2020-05-14 02:03:13 +00:00
|
|
|
|
2021-05-09 07:05:51 +00:00
|
|
|
from playsound import playsound
|
2020-05-14 02:03:13 +00:00
|
|
|
|
2020-10-17 10:52:04 +00:00
|
|
|
from fishy.engine.common.IEngine import IEngine
|
2021-05-09 07:05:51 +00:00
|
|
|
from fishy.engine.common.window import WindowClient
|
|
|
|
from fishy.engine.semifisher import fishing_event, fishing_mode
|
2021-04-15 18:26:35 +00:00
|
|
|
from fishy.engine.semifisher.fishing_event import FishEvent
|
2021-05-09 07:05:51 +00:00
|
|
|
from fishy.engine.semifisher.fishing_mode import Colors, FishingMode
|
2020-10-17 16:04:44 +00:00
|
|
|
from fishy.engine.semifisher.pixel_loc import PixelLoc
|
2021-04-15 18:27:08 +00:00
|
|
|
from fishy.helper import helper
|
2021-04-09 18:50:53 +00:00
|
|
|
from fishy.helper.luaparser import sv_color_extract
|
|
|
|
|
2020-05-19 03:11:58 +00:00
|
|
|
if typing.TYPE_CHECKING:
|
|
|
|
from fishy.gui import GUI
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
|
2020-06-01 12:58:18 +00:00
|
|
|
class SemiFisherEngine(IEngine):
|
2020-10-17 19:45:57 +00:00
|
|
|
def __init__(self, gui_ref: Optional['Callable[[], GUI]']):
|
2020-10-17 19:06:07 +00:00
|
|
|
super().__init__(gui_ref)
|
2020-06-25 01:22:39 +00:00
|
|
|
self.fishPixWindow = None
|
2020-05-19 03:11:58 +00:00
|
|
|
|
2020-06-01 12:58:18 +00:00
|
|
|
def run(self):
|
2020-05-14 02:03:13 +00:00
|
|
|
"""
|
|
|
|
Starts the fishing
|
|
|
|
code explained in comments in detail
|
|
|
|
"""
|
2020-12-13 06:56:43 +00:00
|
|
|
fishing_event.init()
|
2021-04-09 17:30:34 +00:00
|
|
|
self.fishPixWindow = WindowClient()
|
2020-05-14 02:03:13 +00:00
|
|
|
|
|
|
|
# check for game window and stuff
|
2020-05-19 03:11:58 +00:00
|
|
|
self.gui.bot_started(True)
|
2020-11-30 21:04:33 +00:00
|
|
|
|
2021-05-07 12:07:09 +00:00
|
|
|
sv_color_extract(Colors)
|
2021-04-09 18:50:53 +00:00
|
|
|
|
2020-11-30 21:04:33 +00:00
|
|
|
if self.get_gui:
|
|
|
|
logging.info("Starting the bot engine, look at the fishing hole to start fishing")
|
2021-04-17 16:34:10 +00:00
|
|
|
Thread(target=self._wait_and_check).start()
|
|
|
|
|
2020-10-17 23:12:48 +00:00
|
|
|
while self.start and WindowClient.running():
|
2020-10-17 10:52:04 +00:00
|
|
|
capture = self.fishPixWindow.get_capture()
|
2020-06-25 01:22:39 +00:00
|
|
|
|
2020-10-17 10:52:04 +00:00
|
|
|
if capture is None:
|
|
|
|
# if window server crashed
|
2020-06-25 01:22:39 +00:00
|
|
|
self.gui.bot_started(False)
|
|
|
|
self.toggle_start()
|
|
|
|
continue
|
2020-05-14 02:03:13 +00:00
|
|
|
|
|
|
|
self.fishPixWindow.crop = PixelLoc.val
|
2021-03-14 21:16:49 +00:00
|
|
|
fishing_mode.loop(capture[0][0])
|
2021-05-07 01:35:06 +00:00
|
|
|
time.sleep(0.1)
|
2020-10-17 16:04:44 +00:00
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
logging.info("Fishing engine stopped")
|
2020-05-19 03:11:58 +00:00
|
|
|
self.gui.bot_started(False)
|
2020-10-17 19:45:57 +00:00
|
|
|
fishing_event.unsubscribe()
|
2020-10-17 23:12:48 +00:00
|
|
|
self.fishPixWindow.destory()
|
2020-05-14 02:03:13 +00:00
|
|
|
|
2020-06-25 01:22:39 +00:00
|
|
|
def _wait_and_check(self):
|
|
|
|
time.sleep(10)
|
2020-10-17 16:04:44 +00:00
|
|
|
if not FishEvent.FishingStarted and self.start:
|
2021-05-09 09:44:19 +00:00
|
|
|
logging.warning("Doesn't look like fishing has started \n"
|
|
|
|
"Check out #read-me-first on our discord channel to troubleshoot the issue")
|
2020-06-25 01:22:39 +00:00
|
|
|
|
2020-06-01 12:58:18 +00:00
|
|
|
def show_pixel_vals(self):
|
2020-05-14 02:03:13 +00:00
|
|
|
def show():
|
|
|
|
freq = 0.5
|
|
|
|
t = 0
|
|
|
|
while t < 10.0:
|
|
|
|
t += freq
|
2021-04-15 10:31:37 +00:00
|
|
|
logging.debug(str(FishingMode.CurrentMode) + ":" + str(self.fishPixWindow.get_capture()[0][0]))
|
2020-05-14 02:03:13 +00:00
|
|
|
time.sleep(freq)
|
|
|
|
|
|
|
|
logging.debug("Will display pixel values for 10 seconds")
|
|
|
|
time.sleep(5)
|
|
|
|
Thread(target=show, args=()).start()
|
2020-05-19 03:11:58 +00:00
|
|
|
|
2020-11-30 21:04:33 +00:00
|
|
|
def toggle_start(self):
|
|
|
|
self.start = not self.start
|
|
|
|
if self.start:
|
|
|
|
self.thread = Thread(target=self.run)
|
|
|
|
self.thread.start()
|
2021-04-15 18:27:08 +00:00
|
|
|
playsound(helper.manifest_file("beep.wav"), False)
|
|
|
|
else:
|
|
|
|
helper.playsound_multiple(helper.manifest_file("beep.wav"))
|
2020-11-30 21:04:33 +00:00
|
|
|
|
2020-05-19 03:11:58 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
logging.getLogger("").setLevel(logging.DEBUG)
|
|
|
|
# noinspection PyTypeChecker
|
2020-10-17 19:06:07 +00:00
|
|
|
fisher = SemiFisherEngine(None)
|
2020-10-17 16:04:44 +00:00
|
|
|
fisher.toggle_start()
|