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
|
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
from fishy.engine.semifisher import fishing_mode
|
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-17 22:04:25 +00:00
|
|
|
from fishy.engine.semifisher.fishing_mode import State, FishingMode
|
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
|
|
|
|
2020-10-17 19:06:07 +00:00
|
|
|
from fishy.helper.config import config
|
|
|
|
|
2020-04-15 11:27:26 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
class FishEvent:
|
|
|
|
fishCaught = 0
|
|
|
|
totalFishCaught = 0
|
|
|
|
stickInitTime = 0
|
|
|
|
fish_times = []
|
|
|
|
hole_start_time = 0
|
|
|
|
FishingStarted = False
|
|
|
|
previousState = State.IDLE
|
2020-10-15 02:23:15 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
# initialize these
|
|
|
|
action_key = 'e'
|
|
|
|
collect_r = False
|
|
|
|
uid = None
|
|
|
|
sound = False
|
2020-10-15 02:23:15 +00:00
|
|
|
|
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def init():
|
2020-10-17 19:45:57 +00:00
|
|
|
subscribe()
|
2020-10-17 19:06:07 +00:00
|
|
|
FishEvent.action_key = config.get("action_key", 'e')
|
|
|
|
FishEvent.uid = config.get("uid")
|
|
|
|
FishEvent.sound = config.get("sound_notification", False)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
|
2020-10-17 19:45:57 +00:00
|
|
|
def unsubscribe():
|
|
|
|
if fisher_callback in fishing_mode.subscribers:
|
|
|
|
fishing_mode.subscribers.remove(fisher_callback)
|
|
|
|
|
|
|
|
|
|
|
|
def subscribe():
|
|
|
|
if fisher_callback not in fishing_mode.subscribers:
|
|
|
|
fishing_mode.subscribers.append(fisher_callback)
|
2020-10-18 07:47:24 +00:00
|
|
|
|
|
|
|
if FishingMode.CurrentMode == State.LOOK:
|
|
|
|
fisher_callback(FishingMode.CurrentMode)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-04-15 11:27:26 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def fisher_callback(event: State):
|
|
|
|
callbacks_map = {State.HOOK: on_hook, State.LOOK: on_look, State.IDLE: on_idle, State.STICK: on_stick}
|
|
|
|
callbacks_map[event]()
|
|
|
|
FishEvent.previousState = event
|
2020-10-15 02:23:15 +00:00
|
|
|
|
2020-04-18 11:32:14 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def on_hook():
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
2020-10-17 16:04:44 +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
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
2020-10-17 16:04:44 +00:00
|
|
|
FishEvent.fishCaught += 1
|
|
|
|
FishEvent.totalFishCaught += 1
|
|
|
|
time_to_hook = time.time() - FishEvent.stickInitTime
|
|
|
|
FishEvent.fish_times.append(time_to_hook)
|
|
|
|
logging.info("HOOOOOOOOOOOOOOOOOOOOOOOK....... " + str(FishEvent.fishCaught) + " caught " + "in " + str(
|
|
|
|
round(time_to_hook, 2)) + " secs. " + "Total: " + str(FishEvent.totalFishCaught))
|
2020-05-05 12:55:06 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
keyboard.press_and_release(FishEvent.action_key)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
if FishEvent.collect_r:
|
|
|
|
time.sleep(0.1)
|
|
|
|
keyboard.press_and_release('r')
|
|
|
|
time.sleep(0.1)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def on_look():
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
2020-10-17 16:04:44 +00:00
|
|
|
presses e to throw the fishing rod
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
2020-10-17 16:04:44 +00:00
|
|
|
keyboard.press_and_release(FishEvent.action_key)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def on_idle():
|
|
|
|
if FishEvent.fishCaught > 0:
|
|
|
|
web.send_hole_deplete(FishEvent.uid, FishEvent.fishCaught, time.time() - FishEvent.hole_start_time,
|
|
|
|
FishEvent.fish_times)
|
|
|
|
FishEvent.fishCaught = 0
|
2020-05-14 02:03:13 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
if FishEvent.previousState == State.HOOK:
|
|
|
|
logging.info("HOLE DEPLETED")
|
|
|
|
else:
|
|
|
|
logging.info("FISHING INTERRUPTED")
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-10-18 07:47:24 +00:00
|
|
|
if FishEvent.sound:
|
|
|
|
playsound(helper.manifest_file("sound.mp3"), False)
|
|
|
|
|
2020-05-05 12:55:06 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def on_stick():
|
|
|
|
FishEvent.stickInitTime = time.time()
|
|
|
|
FishEvent.FishingStarted = True
|
2020-10-15 02:23:15 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
if FishEvent.fishCaught == 0:
|
|
|
|
FishEvent.hole_start_time = time.time()
|
|
|
|
FishEvent.fish_times = []
|