mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-22 08:37:42 +00:00
Opt: delay battle pass to next version if possible
This commit is contained in:
parent
ed4b4c78d8
commit
cfdb09f7c3
BIN
assets/share/battle_pass/OCR_REMAINING_TIME.png
Normal file
BIN
assets/share/battle_pass/OCR_REMAINING_TIME.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
@ -264,6 +264,7 @@ class AzurLaneConfig(ConfigUpdater, ManualConfig, GeneratedConfig, ConfigWatcher
|
|||||||
if isinstance(next_run, datetime) and next_run > limit:
|
if isinstance(next_run, datetime) and next_run > limit:
|
||||||
deep_set(self.data, keys=f"{task}.Scheduler.NextRun", value=now)
|
deep_set(self.data, keys=f"{task}.Scheduler.NextRun", value=now)
|
||||||
|
|
||||||
|
limit_next_run(['BattlePass'], limit=now + timedelta(days=31, seconds=-1))
|
||||||
limit_next_run(self.args.keys(), limit=now + timedelta(hours=24, seconds=-1))
|
limit_next_run(self.args.keys(), limit=now + timedelta(hours=24, seconds=-1))
|
||||||
|
|
||||||
def override(self, **kwargs):
|
def override(self, **kwargs):
|
||||||
|
@ -283,14 +283,14 @@ class Duration(Ocr):
|
|||||||
@cached_property
|
@cached_property
|
||||||
def timedelta_regex(self):
|
def timedelta_regex(self):
|
||||||
regex_str = {
|
regex_str = {
|
||||||
'ch': r'\D*((?P<hours>\d{1,2})小时)?((?P<minutes>\d{1,2})分钟)?((?P<seconds>\d{1,2})秒})?',
|
'ch': r'\D*((?P<days>\d{1,2})天)?((?P<hours>\d{1,2})小时)?((?P<minutes>\d{1,2})分钟)?((?P<seconds>\d{1,2})秒})?',
|
||||||
'en': r'\D*((?P<hours>\d{1,2})h\s*)?((?P<minutes>\d{1,2})m\s*)?((?P<seconds>\d{1,2})s)?'
|
'en': r'\D*((?P<days>\d{1,2})d\s*)?((?P<hours>\d{1,2})h\s*)?((?P<minutes>\d{1,2})m\s*)?((?P<seconds>\d{1,2})s)?'
|
||||||
}[self.lang]
|
}[self.lang]
|
||||||
return re.compile(regex_str)
|
return re.compile(regex_str)
|
||||||
|
|
||||||
def format_result(self, result: str) -> timedelta:
|
def format_result(self, result: str) -> timedelta:
|
||||||
"""
|
"""
|
||||||
Do OCR on a duration, such as `2h 13m 30s`, `2h`, `13m 30s`, `9s`
|
Do OCR on a duration, such as `18d 2h 13m 30s`, `2h`, `13m 30s`, `9s`
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
timedelta:
|
timedelta:
|
||||||
@ -298,10 +298,11 @@ class Duration(Ocr):
|
|||||||
matched = self.timedelta_regex.match(result)
|
matched = self.timedelta_regex.match(result)
|
||||||
if matched is None:
|
if matched is None:
|
||||||
return timedelta()
|
return timedelta()
|
||||||
|
days = self._sanitize_number(matched.group('days'))
|
||||||
hours = self._sanitize_number(matched.group('hours'))
|
hours = self._sanitize_number(matched.group('hours'))
|
||||||
minutes = self._sanitize_number(matched.group('minutes'))
|
minutes = self._sanitize_number(matched.group('minutes'))
|
||||||
seconds = self._sanitize_number(matched.group('seconds'))
|
seconds = self._sanitize_number(matched.group('seconds'))
|
||||||
return timedelta(hours=hours, minutes=minutes, seconds=seconds)
|
return timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _sanitize_number(number) -> int:
|
def _sanitize_number(number) -> int:
|
||||||
|
@ -63,6 +63,16 @@ OCR_LEVEL = ButtonWrapper(
|
|||||||
button=(183, 93, 240, 134),
|
button=(183, 93, 240, 134),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
OCR_REMAINING_TIME = ButtonWrapper(
|
||||||
|
name='OCR_REMAINING_TIME',
|
||||||
|
share=Button(
|
||||||
|
file='./assets/share/battle_pass/OCR_REMAINING_TIME.png',
|
||||||
|
area=(289, 89, 630, 132),
|
||||||
|
search=(269, 69, 650, 152),
|
||||||
|
color=(66, 63, 57),
|
||||||
|
button=(289, 89, 630, 132),
|
||||||
|
),
|
||||||
|
)
|
||||||
REWARDS_CHECK = ButtonWrapper(
|
REWARDS_CHECK = ButtonWrapper(
|
||||||
name='REWARDS_CHECK',
|
name='REWARDS_CHECK',
|
||||||
share=Button(
|
share=Button(
|
||||||
|
@ -3,7 +3,7 @@ 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.logger.logger import logger
|
from module.logger.logger import logger
|
||||||
from module.ocr.ocr import Digit
|
from module.ocr.ocr import Digit, Duration
|
||||||
from module.ui.switch import Switch
|
from module.ui.switch import Switch
|
||||||
from tasks.base.assets.assets_base_page import BATTLE_PASS_CHECK
|
from tasks.base.assets.assets_base_page import BATTLE_PASS_CHECK
|
||||||
from tasks.base.assets.assets_base_popup import GET_REWARD
|
from tasks.base.assets.assets_base_popup import GET_REWARD
|
||||||
@ -26,6 +26,8 @@ SWITCH_BATTLE_PASS_TAB.add_state(
|
|||||||
|
|
||||||
|
|
||||||
class BattlePassUI(UI):
|
class BattlePassUI(UI):
|
||||||
|
MAX_LEVEL = 50
|
||||||
|
|
||||||
def _battle_pass_wait_rewards_loaded(self, skip_first_screenshot=True):
|
def _battle_pass_wait_rewards_loaded(self, skip_first_screenshot=True):
|
||||||
timeout = Timer(2, count=4).start()
|
timeout = Timer(2, count=4).start()
|
||||||
while 1:
|
while 1:
|
||||||
@ -150,6 +152,9 @@ class BattlePassUI(UI):
|
|||||||
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):
|
||||||
|
return Duration(OCR_REMAINING_TIME).ocr_single_line(self.device.image)
|
||||||
|
|
||||||
def claim_battle_pass_rewards(self):
|
def claim_battle_pass_rewards(self):
|
||||||
"""
|
"""
|
||||||
Examples:
|
Examples:
|
||||||
@ -159,16 +164,19 @@ class BattlePassUI(UI):
|
|||||||
"""
|
"""
|
||||||
self.ui_ensure(page_battle_pass)
|
self.ui_ensure(page_battle_pass)
|
||||||
previous_level = self._get_battle_pass_level()
|
previous_level = self._get_battle_pass_level()
|
||||||
|
if previous_level == self.MAX_LEVEL:
|
||||||
|
return previous_level
|
||||||
claimed_exp = self._claim_exp()
|
claimed_exp = self._claim_exp()
|
||||||
if claimed_exp and previous_level != 50 and self._get_battle_pass_level() > previous_level:
|
current_level = self._get_battle_pass_level()
|
||||||
|
if claimed_exp and current_level > previous_level:
|
||||||
logger.info("Upgraded, go to claim rewards")
|
logger.info("Upgraded, go to claim rewards")
|
||||||
self._claim_rewards()
|
self._claim_rewards()
|
||||||
return True
|
return current_level
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
for _ in range(5):
|
current_level = self.claim_battle_pass_rewards()
|
||||||
claimed = self.claim_battle_pass_rewards()
|
if current_level == self.MAX_LEVEL:
|
||||||
if claimed:
|
remaining_time = self._get_remaining_time()
|
||||||
break
|
self.config.task_delay(minute=remaining_time.total_seconds() / 60)
|
||||||
|
else:
|
||||||
self.config.task_delay(server_update=True)
|
self.config.task_delay(server_update=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user