2021-05-07 12:13:55 +00:00
|
|
|
from enum import Enum
|
2022-02-20 19:00:30 +00:00
|
|
|
from time import time, sleep
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
subscribers = []
|
2022-02-20 19:00:30 +00:00
|
|
|
checkpoint = 0
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2021-05-07 12:13:55 +00:00
|
|
|
class State(Enum):
|
|
|
|
IDLE = 0
|
|
|
|
LOOKAWAY = 1
|
|
|
|
LOOKING = 2
|
|
|
|
DEPLETED = 3
|
|
|
|
NOBAIT = 5
|
|
|
|
FISHING = 6
|
|
|
|
REELIN = 7
|
|
|
|
LOOT = 8
|
|
|
|
INVFULL = 9
|
|
|
|
FIGHT = 14
|
|
|
|
DEAD = 15
|
|
|
|
|
2021-05-09 09:09:26 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def _notify(event):
|
|
|
|
for subscriber in subscribers:
|
|
|
|
subscriber(event)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2019-06-29 20:35:53 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
class FishingMode:
|
2021-05-07 12:13:55 +00:00
|
|
|
CurrentMode = State.IDLE
|
|
|
|
PrevMode = State.IDLE
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
|
2021-11-21 07:12:14 +00:00
|
|
|
def loop(state_num: int):
|
2020-10-17 16:04:44 +00:00
|
|
|
"""
|
|
|
|
Executed in the start of the main loop in fishy.py
|
|
|
|
Changes modes, calls mode events (callbacks) when mode is changed
|
|
|
|
"""
|
2022-02-20 19:00:30 +00:00
|
|
|
global checkpoint
|
2021-11-21 07:12:14 +00:00
|
|
|
FishingMode.CurrentMode = State(state_num)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2021-04-15 09:50:03 +00:00
|
|
|
if FishingMode.CurrentMode != FishingMode.PrevMode:
|
2022-02-20 19:00:30 +00:00
|
|
|
checkpoint = time()
|
2020-10-17 16:04:44 +00:00
|
|
|
_notify(FishingMode.CurrentMode)
|
2022-02-20 19:00:30 +00:00
|
|
|
elif FishingMode.CurrentMode == State.LOOKING:
|
|
|
|
if time() - checkpoint > 5:
|
|
|
|
_notify(FishingMode.CurrentMode)
|
|
|
|
checkpoint = time()
|
|
|
|
else:
|
|
|
|
sleep(0.5)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
FishingMode.PrevMode = FishingMode.CurrentMode
|