Opt: Delay battle pass to exact 04:00

This commit is contained in:
LmeSzinc 2023-07-09 18:09:30 +08:00
parent 59eccac256
commit 866612345f

View File

@ -1,7 +1,10 @@
import datetime
import numpy as np import numpy as np
from module.base.timer import Timer from module.base.timer import Timer
from module.base.utils import get_color from module.base.utils import get_color
from module.config.utils import get_server_next_update
from module.logger.logger import logger from module.logger.logger import logger
from module.ocr.ocr import Digit, Duration from module.ocr.ocr import Digit, Duration
from module.ui.switch import Switch from module.ui.switch import Switch
@ -148,15 +151,21 @@ class BattlePassUI(UI):
if self.handle_reward(): if self.handle_reward():
continue continue
def _get_battle_pass_level(self): def _get_battle_pass_level(self) -> int:
digit = Digit(OCR_LEVEL) digit = Digit(OCR_LEVEL)
return digit.ocr_single_line(self.device.image) return digit.ocr_single_line(self.device.image)
def _get_remaining_time(self): def _get_battle_pass_end(self) -> datetime.datetime:
return Duration(OCR_REMAINING_TIME).ocr_single_line(self.device.image) remain = Duration(OCR_REMAINING_TIME).ocr_single_line(self.device.image)
future = get_server_next_update(self.config.Scheduler_ServerUpdate)
future += datetime.timedelta(days=remain.days)
return future
def claim_battle_pass_rewards(self): def claim_battle_pass_rewards(self):
""" """
Returns:
int: Current battle pass level
Examples: Examples:
self = BattlePassUI('alas') self = BattlePassUI('alas')
self.device.screenshot() self.device.screenshot()
@ -176,7 +185,6 @@ class BattlePassUI(UI):
def run(self): def run(self):
current_level = self.claim_battle_pass_rewards() current_level = self.claim_battle_pass_rewards()
if current_level == self.MAX_LEVEL: if current_level == self.MAX_LEVEL:
remaining_time = self._get_remaining_time() self.config.task_delay(target=self._get_battle_pass_end())
self.config.task_delay(minute=remaining_time.total_seconds() / 60)
else: else:
self.config.task_delay(server_update=True) self.config.task_delay(server_update=True)