From c6205d683a214830147af4861597ba9dc8e8935e Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 29 Jan 2024 23:41:11 +0800 Subject: [PATCH] Opt: Do double events in today as possible when stamina exhausted --- tasks/dungeon/state.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tasks/dungeon/state.py b/tasks/dungeon/state.py index 6cd691d3b..3f1865690 100644 --- a/tasks/dungeon/state.py +++ b/tasks/dungeon/state.py @@ -4,7 +4,7 @@ from module.base.base import ModuleBase from module.base.timer import Timer from module.base.utils import crop from module.config.stored.classes import now -from module.config.utils import DEFAULT_TIME +from module.config.utils import DEFAULT_TIME, get_server_next_monday_update, get_server_next_update from module.logger import logger from module.ocr.ocr import DigitCounter from tasks.base.ui import UI @@ -139,12 +139,37 @@ class DungeonState(UI): limit = 30 else: limit = 60 + + # Double event is not yet finished, do it today as possible + diff = get_server_next_update('04:00') - now() + if self.config.stored.DungeonDouble.relic > 0: + if diff < timedelta(hours=4): + # 4h recover 40 stamina, run double relic at today + logger.info(f'Just less than 4h til the next day, ' + f'double relic event is not yet finished, wait until 40') + limit = 40 + if self.config.stored.DungeonDouble.calyx > 0: + if diff < timedelta(hours=3): + logger.info(f'Just less than 3h til the next day, ' + f'double calyx event is not yet finished, wait until 10') + limit = 10 + elif diff < timedelta(hours=6): + logger.info(f'Just less than 6h til the next day, ' + f'double calyx event is not yet finished, wait until 30') + limit = 30 + # Recover 1 trailbaze power each 6 minutes current = self.config.stored.TrailblazePower.value cover = max(limit - current, 0) * 6 future = now() + timedelta(minutes=cover) logger.info(f'Currently has {current} need {cover} minutes to reach {limit}') + # Save stamina for the next week + next_monday = get_server_next_monday_update('04:00') + if next_monday - future < timedelta(hours=4): + logger.info(f'Approaching next monday, delay to {next_monday} instead') + future = next_monday + tasks = ['Dungeon', 'Weekly'] with self.config.multi_set(): for task in tasks: