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
|
2021-04-15 18:26:35 +00:00
|
|
|
import random
|
2020-04-15 11:27:26 +00:00
|
|
|
import time
|
|
|
|
|
2021-04-15 18:26:35 +00:00
|
|
|
import keyboard
|
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
|
2021-04-15 18:26:35 +00:00
|
|
|
from fishy.engine.semifisher import fishing_mode
|
2023-02-21 17:35:44 +00:00
|
|
|
from fishy.engine.semifisher.fishing_mode import State
|
2020-10-13 13:49:39 +00:00
|
|
|
from fishy.helper import helper
|
2020-10-17 19:06:07 +00:00
|
|
|
from fishy.helper.config import config
|
2023-02-21 17:35:44 +00:00
|
|
|
from fishy.osservices.os_services import os_services
|
2021-05-02 18:05:06 +00:00
|
|
|
|
2020-12-27 12:56:43 +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
|
2020-12-07 21:02:32 +00:00
|
|
|
jitter = False
|
2020-10-17 16:04:44 +00:00
|
|
|
previousState = State.IDLE
|
2020-10-15 02:23:15 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
# initialize these
|
|
|
|
action_key = 'e'
|
2021-05-09 09:09:26 +00:00
|
|
|
collect_key = 'r'
|
2020-10-17 16:04:44 +00:00
|
|
|
sound = False
|
2020-10-15 02:23:15 +00:00
|
|
|
|
2020-12-16 20:03:50 +00:00
|
|
|
|
2022-02-20 19:05:41 +00:00
|
|
|
def _fishing_sleep(waittime, lower_limit_ms=16, upper_limit_ms=1375):
|
2020-12-07 21:02:32 +00:00
|
|
|
reaction = 0.0
|
2020-12-13 20:07:06 +00:00
|
|
|
if FishEvent.jitter and upper_limit_ms > lower_limit_ms:
|
2021-05-09 09:09:26 +00:00
|
|
|
reaction = float(random.randrange(lower_limit_ms, upper_limit_ms)) / 1000.0
|
|
|
|
max_wait_t = waittime + reaction if waittime + reaction <= 2.5 else 2.5
|
2020-12-13 19:13:15 +00:00
|
|
|
time.sleep(max_wait_t)
|
2020-12-07 21:02:32 +00:00
|
|
|
|
2020-10-15 02:23:15 +00:00
|
|
|
|
2020-12-27 12:56:43 +00:00
|
|
|
def if_eso_is_focused(func):
|
|
|
|
def wrapper():
|
2023-02-21 17:35:44 +00:00
|
|
|
if not os_services.is_eso_active():
|
2020-12-27 12:56:43 +00:00
|
|
|
logging.warning("ESO window is not focused")
|
|
|
|
return
|
|
|
|
func()
|
|
|
|
return wrapper
|
2020-12-16 20:03:50 +00:00
|
|
|
|
|
|
|
|
2021-04-21 16:20:28 +00:00
|
|
|
def _sound_and_send_fishy_data():
|
|
|
|
if FishEvent.fishCaught > 0:
|
2021-05-07 07:59:18 +00:00
|
|
|
web.send_fish_caught(FishEvent.fishCaught, time.time() - FishEvent.hole_start_time, FishEvent.fish_times)
|
2021-04-21 16:20:28 +00:00
|
|
|
FishEvent.fishCaught = 0
|
|
|
|
|
|
|
|
if FishEvent.sound:
|
|
|
|
playsound(helper.manifest_file("sound.mp3"), False)
|
|
|
|
|
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def init():
|
2020-10-17 19:45:57 +00:00
|
|
|
subscribe()
|
2020-12-07 21:02:32 +00:00
|
|
|
FishEvent.jitter = config.get("jitter", False)
|
2020-10-17 19:06:07 +00:00
|
|
|
FishEvent.action_key = config.get("action_key", 'e')
|
2020-12-07 15:36:15 +00:00
|
|
|
FishEvent.collect_key = config.get("collect_key", 'r')
|
2020-10-17 19:06:07 +00:00
|
|
|
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
|
|
|
|
2020-04-15 11:27:26 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def fisher_callback(event: State):
|
2021-03-14 21:16:49 +00:00
|
|
|
callbacks_map = {
|
|
|
|
State.IDLE: on_idle,
|
2021-04-15 18:24:01 +00:00
|
|
|
State.LOOKAWAY: on_idle,
|
2021-03-14 21:16:49 +00:00
|
|
|
State.LOOKING: on_looking,
|
|
|
|
State.DEPLETED: on_depleted,
|
2021-05-07 08:22:09 +00:00
|
|
|
State.NOBAIT: lambda: on_user_interact("You need to equip bait!"),
|
2021-03-14 21:16:49 +00:00
|
|
|
State.FISHING: on_fishing,
|
|
|
|
State.REELIN: on_reelin,
|
|
|
|
State.LOOT: on_loot,
|
2021-05-07 08:22:09 +00:00
|
|
|
State.INVFULL: lambda: on_user_interact("Inventory is full!"),
|
|
|
|
State.FIGHT: lambda: on_user_interact("Character is FIGHTING!"),
|
|
|
|
State.DEAD: lambda: on_user_interact("Character died!")
|
2021-03-14 21:16:49 +00:00
|
|
|
}
|
2021-04-09 18:50:53 +00:00
|
|
|
|
2021-03-14 21:16:49 +00:00
|
|
|
try:
|
|
|
|
callbacks_map[event]()
|
|
|
|
FishEvent.previousState = event
|
2021-05-09 09:48:35 +00:00
|
|
|
except KeyError:
|
2021-04-09 17:30:34 +00:00
|
|
|
logging.error("KeyError: State " + str(event) + " is not known.")
|
2021-05-09 09:48:35 +00:00
|
|
|
except TypeError:
|
2021-04-09 17:30:34 +00:00
|
|
|
logging.error("TypeError when reading state: " + str(event))
|
2020-10-15 02:23:15 +00:00
|
|
|
|
2020-04-18 11:32:14 +00:00
|
|
|
|
2021-03-14 21:16:49 +00:00
|
|
|
def on_idle():
|
2021-11-21 07:12:14 +00:00
|
|
|
if FishEvent.previousState == State.REELIN:
|
|
|
|
logging.info("HOLE DEPLETED")
|
|
|
|
_sound_and_send_fishy_data()
|
|
|
|
elif FishEvent.previousState == State.FISHING:
|
2021-03-14 21:16:49 +00:00
|
|
|
logging.info("FISHING INTERRUPTED")
|
2021-04-21 16:20:28 +00:00
|
|
|
_sound_and_send_fishy_data()
|
2020-12-16 20:03:50 +00:00
|
|
|
|
2021-04-21 16:20:28 +00:00
|
|
|
|
|
|
|
def on_depleted():
|
|
|
|
logging.info("HOLE DEPLETED")
|
|
|
|
_sound_and_send_fishy_data()
|
2020-12-13 19:13:15 +00:00
|
|
|
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-12-27 12:56:43 +00:00
|
|
|
@if_eso_is_focused
|
2021-03-14 21:16:49 +00:00
|
|
|
def on_looking():
|
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
|
|
|
"""
|
2021-03-14 21:16:49 +00:00
|
|
|
_fishing_sleep(0.0)
|
2020-10-17 16:04:44 +00:00
|
|
|
keyboard.press_and_release(FishEvent.action_key)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
|
2021-05-07 08:22:09 +00:00
|
|
|
def on_user_interact(msg):
|
2021-03-28 15:33:09 +00:00
|
|
|
logging.info(msg)
|
|
|
|
web.send_notification(msg)
|
|
|
|
|
2021-04-15 15:03:08 +00:00
|
|
|
if FishEvent.sound:
|
|
|
|
playsound(helper.manifest_file("sound.mp3"), False)
|
|
|
|
|
2021-03-28 15:33:09 +00:00
|
|
|
|
2021-03-14 21:16:49 +00:00
|
|
|
def on_fishing():
|
2020-10-17 16:04:44 +00:00
|
|
|
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 = []
|
2021-03-14 21:16:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
@if_eso_is_focused
|
|
|
|
def on_reelin():
|
|
|
|
"""
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
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))
|
|
|
|
|
|
|
|
_fishing_sleep(0.0)
|
|
|
|
keyboard.press_and_release(FishEvent.action_key)
|
|
|
|
_fishing_sleep(0.5)
|
|
|
|
|
|
|
|
|
|
|
|
def on_loot():
|
2021-04-15 10:49:17 +00:00
|
|
|
_fishing_sleep(0)
|
|
|
|
keyboard.press_and_release(FishEvent.collect_key)
|
|
|
|
_fishing_sleep(0)
|