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
|
|
|
|
|
|
|
|
import pyautogui
|
|
|
|
|
2020-04-27 21:19:30 +00:00
|
|
|
from fishy.systems import web
|
2020-04-15 11:27:26 +00:00
|
|
|
from fishy.systems.globals import G
|
|
|
|
from fishy.systems.helper import round_float
|
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
class FishEvent(ABC):
|
|
|
|
@abstractmethod
|
|
|
|
def onEnterCallback(self, previousMode):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def onExitCallback(self, currentMode):
|
|
|
|
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
|
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
def onEnterCallback(self, previousMode):
|
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
|
|
|
|
|
|
|
|
:param previousMode: previous mode in the state machine
|
|
|
|
"""
|
2019-02-07 22:03:28 +00:00
|
|
|
G.fishCaught += 1
|
2019-06-19 09:28:18 +00:00
|
|
|
G.totalFishCaught += 1
|
2019-02-07 22:03:28 +00:00
|
|
|
timeToHook = time.time() - G.stickInitTime
|
2020-05-05 12:55:06 +00:00
|
|
|
G.fish_times.append(timeToHook)
|
2020-04-17 13:08:26 +00:00
|
|
|
logging.info("HOOOOOOOOOOOOOOOOOOOOOOOK....... " + str(G.fishCaught) + " caught " + "in " + str(
|
2019-06-19 09:28:18 +00:00
|
|
|
round_float(timeToHook)) + " secs. " + "Total: " + str(G.totalFishCaught))
|
2020-04-19 11:52:42 +00:00
|
|
|
pyautogui.press(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)
|
|
|
|
pyautogui.press('r')
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
def onExitCallback(self, currentMode):
|
|
|
|
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
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
def onEnterCallback(self, previousMode):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
presses e to throw the fishing rod
|
|
|
|
:param previousMode: previous mode in the state machine
|
|
|
|
"""
|
2019-02-07 22:03:28 +00:00
|
|
|
pyautogui.press('e')
|
|
|
|
|
|
|
|
def onExitCallback(self, currentMode):
|
|
|
|
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-04-27 21:19:30 +00:00
|
|
|
def __init__(self, uid):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
sets the flag to send notification on phone
|
|
|
|
:param use_net: true if user wants to send notification on phone
|
|
|
|
"""
|
2020-04-27 21:19:30 +00:00
|
|
|
self.uid = uid
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
def onEnterCallback(self, previousMode):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
Resets the fishCaught counter and logs a message depending on the previous state
|
|
|
|
:param previousMode: previous mode in the state machine
|
|
|
|
"""
|
|
|
|
|
2020-05-07 06:03:30 +00:00
|
|
|
if G.fishCaught > 0:
|
2020-05-05 12:55:06 +00:00
|
|
|
web.send_hole_deplete(self.uid, G.fishCaught, time.time() - G.hole_start_time, G.fish_times)
|
|
|
|
G.fishCaught = 0
|
2020-05-07 06:03:30 +00:00
|
|
|
|
|
|
|
if previousMode.name == "hook":
|
|
|
|
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
|
|
|
|
|
|
|
def onExitCallback(self, currentMode):
|
|
|
|
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
|
|
|
|
|
|
|
def onEnterCallback(self, previousMode):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
resets the fishing timer
|
|
|
|
:param previousMode: previous mode in the state machine
|
|
|
|
"""
|
2019-02-07 22:03:28 +00:00
|
|
|
G.stickInitTime = time.time()
|
2020-04-20 13:03:44 +00:00
|
|
|
G.FishingStarted = True
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-05-05 12:55:06 +00:00
|
|
|
if G.fishCaught == 0:
|
|
|
|
G.hole_start_time = time.time()
|
|
|
|
G.fish_times = []
|
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
def onExitCallback(self, currentMode):
|
|
|
|
pass
|