2019-06-29 20:35:53 +00:00
|
|
|
"""
|
2020-05-12 06:13:42 +00:00
|
|
|
fishing_event.py
|
2019-06-29 20:35:53 +00:00
|
|
|
Defines different fishing modes (states) which acts as state for state machine
|
|
|
|
also implements callbacks which is called when states are changed
|
|
|
|
"""
|
2020-04-17 13:08:26 +00:00
|
|
|
import logging
|
2020-04-15 11:27:26 +00:00
|
|
|
import time
|
|
|
|
from abc import abstractmethod, ABC
|
|
|
|
|
2020-10-13 13:49:39 +00:00
|
|
|
from playsound import playsound
|
2020-04-15 11:27:26 +00:00
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
from fishy import web
|
2020-10-13 13:49:39 +00:00
|
|
|
from fishy.helper import helper
|
2020-10-13 14:36:19 +00:00
|
|
|
import keyboard
|
2020-05-14 02:03:13 +00:00
|
|
|
|
|
|
|
_fishCaught = 0
|
|
|
|
_totalFishCaught = 0
|
|
|
|
_stickInitTime = 0
|
|
|
|
_fish_times = []
|
|
|
|
_hole_start_time = 0
|
|
|
|
_FishingStarted = False
|
2020-04-15 11:27:26 +00:00
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
class FishEvent(ABC):
|
|
|
|
@abstractmethod
|
2020-05-14 02:03:13 +00:00
|
|
|
def on_enter_callback(self, previous_mode):
|
2019-02-07 22:03:28 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2020-05-14 02:03:13 +00:00
|
|
|
def on_exit_callback(self, current_mode):
|
2019-02-07 22:03:28 +00:00
|
|
|
pass
|
|
|
|
|
2020-04-15 11:27:26 +00:00
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
class HookEvent(FishEvent):
|
2020-04-19 11:52:42 +00:00
|
|
|
def __init__(self, action_key: str, collect_r: bool):
|
|
|
|
self.action_key = action_key
|
2020-04-18 11:32:14 +00:00
|
|
|
self.collect_r = collect_r
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
def on_enter_callback(self, previous_mode):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
called when the fish hook is detected
|
|
|
|
increases the `fishCaught` and `totalFishCaught`, calculates the time it took to catch
|
|
|
|
presses e to catch the fish
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
:param previous_mode: previous mode in the state machine
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
2020-05-14 02:03:13 +00:00
|
|
|
global _fishCaught, _totalFishCaught
|
|
|
|
|
|
|
|
_fishCaught += 1
|
|
|
|
_totalFishCaught += 1
|
|
|
|
time_to_hook = time.time() - _stickInitTime
|
|
|
|
_fish_times.append(time_to_hook)
|
|
|
|
logging.info("HOOOOOOOOOOOOOOOOOOOOOOOK....... " + str(_fishCaught) + " caught " + "in " + str(
|
|
|
|
round(time_to_hook, 2)) + " secs. " + "Total: " + str(_totalFishCaught))
|
2020-10-13 14:36:19 +00:00
|
|
|
# pyautogui.press(self.action_key)
|
|
|
|
keyboard.press_and_release(self.action_key)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-04-18 11:32:14 +00:00
|
|
|
if self.collect_r:
|
2019-06-19 09:28:18 +00:00
|
|
|
time.sleep(0.1)
|
2020-10-13 14:36:19 +00:00
|
|
|
keyboard.press_and_release('r')
|
2019-06-19 09:28:18 +00:00
|
|
|
time.sleep(0.1)
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
def on_exit_callback(self, current_mode):
|
2019-02-07 22:03:28 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class LookEvent(FishEvent):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
state when looking on a fishing hole
|
|
|
|
"""
|
2020-05-05 12:55:06 +00:00
|
|
|
|
2020-05-12 06:16:36 +00:00
|
|
|
def __init__(self, action_key: str):
|
|
|
|
self.action_key = action_key
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
def on_enter_callback(self, previous_mode):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
presses e to throw the fishing rod
|
2020-05-14 02:03:13 +00:00
|
|
|
:param previous_mode: previous mode in the state machine
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
2020-10-13 14:36:19 +00:00
|
|
|
keyboard.press_and_release(self.action_key)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
def on_exit_callback(self, current_mode):
|
2019-02-07 22:03:28 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class IdleEvent(FishEvent):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
State when the fishing hole is depleted or the bot is doing nothing
|
|
|
|
"""
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-10-13 13:49:39 +00:00
|
|
|
def __init__(self, uid, sound: bool):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
sets the flag to send notification on phone
|
|
|
|
"""
|
2020-04-27 21:19:30 +00:00
|
|
|
self.uid = uid
|
2020-10-13 13:49:39 +00:00
|
|
|
self.sound = sound
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
def on_enter_callback(self, previous_mode):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
Resets the fishCaught counter and logs a message depending on the previous state
|
2020-05-14 02:03:13 +00:00
|
|
|
:param previous_mode: previous mode in the state machine
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
2020-05-14 02:03:13 +00:00
|
|
|
global _fishCaught
|
2019-06-29 20:35:53 +00:00
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
if _fishCaught > 0:
|
|
|
|
web.send_hole_deplete(self.uid, _fishCaught, time.time() - _hole_start_time, _fish_times)
|
|
|
|
_fishCaught = 0
|
2020-10-13 13:49:39 +00:00
|
|
|
if self.sound:
|
|
|
|
playsound(helper.manifest_file("sound.mp3"), False)
|
2020-05-07 06:03:30 +00:00
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
if previous_mode.name == "hook":
|
2020-05-07 06:03:30 +00:00
|
|
|
logging.info("HOLE DEPLETED")
|
|
|
|
else:
|
2020-04-17 13:08:26 +00:00
|
|
|
logging.info("FISHING INTERRUPTED")
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
def on_exit_callback(self, current_mode):
|
2019-02-07 22:03:28 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class StickEvent(FishEvent):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
State when fishing is going on
|
|
|
|
"""
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
def on_enter_callback(self, previous_mode):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
resets the fishing timer
|
2020-05-14 02:03:13 +00:00
|
|
|
:param previous_mode: previous mode in the state machine
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
2020-05-14 02:03:13 +00:00
|
|
|
global _stickInitTime, _hole_start_time, _fish_times, _FishingStarted
|
|
|
|
|
|
|
|
_stickInitTime = time.time()
|
|
|
|
_FishingStarted = True
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
if _fishCaught == 0:
|
|
|
|
_hole_start_time = time.time()
|
|
|
|
_fish_times = []
|
2020-05-05 12:55:06 +00:00
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
def on_exit_callback(self, current_mode):
|
2019-02-07 22:03:28 +00:00
|
|
|
pass
|