2023-07-09 10:09:30 +00:00
|
|
|
import datetime
|
2023-08-02 11:07:46 +00:00
|
|
|
import re
|
2024-01-01 16:43:34 +00:00
|
|
|
from dataclasses import dataclass
|
2023-07-09 10:09:30 +00:00
|
|
|
|
2023-06-19 13:57:19 +00:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
from module.base.timer import Timer
|
|
|
|
from module.base.utils import get_color
|
2024-01-01 16:43:34 +00:00
|
|
|
from module.config.stored.classes import StoredCounter
|
2023-07-09 10:09:30 +00:00
|
|
|
from module.config.utils import get_server_next_update
|
2023-06-19 13:57:19 +00:00
|
|
|
from module.logger.logger import logger
|
2024-01-01 16:43:34 +00:00
|
|
|
from module.ocr.keyword import KeywordDigitCounter
|
|
|
|
from module.ocr.ocr import Digit, DigitCounter, Duration, Ocr, OcrResultButton
|
|
|
|
from module.ocr.utils import pair_buttons
|
2023-08-02 11:07:46 +00:00
|
|
|
from module.ui.scroll import Scroll
|
2023-06-19 13:57:19 +00:00
|
|
|
from module.ui.switch import Switch
|
2023-07-19 05:36:48 +00:00
|
|
|
from tasks.base.assets.assets_base_page import BATTLE_PASS_CHECK, MAIN_GOTO_BATTLE_PASS
|
2023-07-17 05:40:58 +00:00
|
|
|
from tasks.base.page import page_battle_pass, page_main
|
2023-06-19 13:57:19 +00:00
|
|
|
from tasks.base.ui import UI
|
|
|
|
from tasks.battle_pass.assets.assets_battle_pass import *
|
2023-08-02 11:07:46 +00:00
|
|
|
from tasks.battle_pass.keywords import *
|
2023-06-19 13:57:19 +00:00
|
|
|
|
2024-01-18 05:00:34 +00:00
|
|
|
|
|
|
|
class BattlePassTab(Switch):
|
|
|
|
def handle_additional(self, main: UI):
|
|
|
|
if main.handle_reward():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
SWITCH_BATTLE_PASS_TAB = BattlePassTab('BattlePassTab', is_selector=True)
|
2023-06-19 13:57:19 +00:00
|
|
|
SWITCH_BATTLE_PASS_TAB.add_state(
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_TAB.Rewards,
|
2023-06-19 13:57:19 +00:00
|
|
|
check_button=REWARDS_CHECK,
|
|
|
|
click_button=REWARDS_CLICK
|
|
|
|
)
|
|
|
|
SWITCH_BATTLE_PASS_TAB.add_state(
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_TAB.Missions,
|
2023-06-19 13:57:19 +00:00
|
|
|
check_button=MISSIONS_CHECK,
|
|
|
|
click_button=MISSIONS_CLICK
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-08-02 11:07:46 +00:00
|
|
|
class BattlePassMissionTab(Switch):
|
|
|
|
def get(self, main):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
main (ModuleBase):
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: state name or 'unknown'.
|
|
|
|
"""
|
|
|
|
for data in self.state_list:
|
|
|
|
if main.image_color_count(data['check_button'], color=(250, 233, 153)):
|
|
|
|
return data['state']
|
|
|
|
|
|
|
|
return 'unknown'
|
|
|
|
|
|
|
|
|
|
|
|
SWITCH_BATTLE_PASS_MISSION_TAB = BattlePassMissionTab('BattlePassMissionTab', is_selector=True)
|
|
|
|
SWITCH_BATTLE_PASS_MISSION_TAB.add_state(
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_MISSION_TAB.This_Week_Missions,
|
2023-08-02 11:07:46 +00:00
|
|
|
check_button=WEEK_MISSION_CLICK,
|
|
|
|
click_button=WEEK_MISSION_CLICK
|
|
|
|
)
|
|
|
|
SWITCH_BATTLE_PASS_MISSION_TAB.add_state(
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_MISSION_TAB.This_Period_Missions,
|
2023-08-02 11:07:46 +00:00
|
|
|
check_button=PERIOD_MISSION_CLICK,
|
|
|
|
click_button=PERIOD_MISSION_CLICK
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class BattlePassQuestOcr(Ocr):
|
|
|
|
def after_process(self, result):
|
|
|
|
result = super().after_process(result)
|
2023-09-08 14:23:57 +00:00
|
|
|
if self.lang == 'cn':
|
2023-08-02 11:07:46 +00:00
|
|
|
result = re.sub("[jJ]", "」", result)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2024-01-01 16:43:34 +00:00
|
|
|
@dataclass
|
|
|
|
class DataBattlePassQuest:
|
|
|
|
quest: BattlePassQuest
|
|
|
|
state: BattlePassQuestState = None
|
|
|
|
digit: KeywordDigitCounter = ''
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
return self.quest == other.quest
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_incomplete(self) -> bool:
|
2024-02-06 21:13:54 +00:00
|
|
|
return self.state == KEYWORDS_BATTLE_PASS_QUEST_STATE.Navigate
|
2024-01-01 16:43:34 +00:00
|
|
|
|
|
|
|
|
2023-06-19 13:57:19 +00:00
|
|
|
class BattlePassUI(UI):
|
2023-11-17 04:37:16 +00:00
|
|
|
MAX_LEVEL = 70
|
2023-07-08 04:09:23 +00:00
|
|
|
|
2023-06-19 13:57:19 +00:00
|
|
|
def _battle_pass_wait_rewards_loaded(self, skip_first_screenshot=True):
|
2024-05-13 11:24:17 +00:00
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
bool: If load success
|
|
|
|
"""
|
2023-06-19 13:57:19 +00:00
|
|
|
timeout = Timer(2, count=4).start()
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if timeout.reached():
|
|
|
|
logger.warning('Wait rewards tab loaded timeout')
|
2024-05-13 11:24:17 +00:00
|
|
|
return False
|
2023-06-19 13:57:19 +00:00
|
|
|
if self.appear(REWARDS_LOADED):
|
|
|
|
logger.info('Rewards tab loaded')
|
2024-05-13 11:24:17 +00:00
|
|
|
return True
|
2023-06-19 13:57:19 +00:00
|
|
|
|
2024-01-01 19:58:31 +00:00
|
|
|
def _battle_pass_wait_missions_loaded(self, skip_first_screenshot=True):
|
2024-05-13 11:24:17 +00:00
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
bool: If load success
|
|
|
|
"""
|
2023-06-19 13:57:19 +00:00
|
|
|
timeout = Timer(2, count=4).start()
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if timeout.reached():
|
|
|
|
logger.warning('Wait missions tab loaded timeout')
|
2024-05-13 11:24:17 +00:00
|
|
|
return False
|
2024-01-01 19:58:31 +00:00
|
|
|
|
|
|
|
# Has scroll and last mission loaded
|
|
|
|
if self.appear(MISSION_PAGE_SCROLL):
|
2023-08-02 11:07:46 +00:00
|
|
|
color = get_color(self.device.image, MISSIONS_LOADED.area)
|
|
|
|
if np.mean(color) > 128:
|
|
|
|
logger.info('Missions tab loaded')
|
2024-05-13 11:24:17 +00:00
|
|
|
return True
|
2023-06-19 13:57:19 +00:00
|
|
|
|
2024-02-06 21:13:54 +00:00
|
|
|
def battle_pass_goto(self, state: KEYWORDS_BATTLE_PASS_TAB):
|
2023-06-19 13:57:19 +00:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
state:
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
self = BattlePassUI('alas')
|
|
|
|
self.device.screenshot()
|
|
|
|
self.battle_pass_goto(KEYWORDS_DUNGEON_TAB.Missions)
|
|
|
|
self.battle_pass_goto(KEYWORDS_DUNGEON_TAB.Rewards)
|
|
|
|
"""
|
|
|
|
self.ui_ensure(page_battle_pass)
|
|
|
|
if SWITCH_BATTLE_PASS_TAB.set(state, main=self):
|
|
|
|
logger.info(f'Tab goto {state}, wait until loaded')
|
2024-02-06 21:13:54 +00:00
|
|
|
if state == KEYWORDS_BATTLE_PASS_TAB.Missions:
|
2023-12-27 18:03:26 +00:00
|
|
|
self._battle_pass_wait_missions_loaded()
|
2024-02-06 21:13:54 +00:00
|
|
|
if state == KEYWORDS_BATTLE_PASS_TAB.Rewards:
|
2023-06-19 13:57:19 +00:00
|
|
|
self._battle_pass_wait_rewards_loaded()
|
|
|
|
|
2024-02-06 21:13:54 +00:00
|
|
|
def battle_pass_mission_tab_goto(self, state: KEYWORDS_BATTLE_PASS_MISSION_TAB):
|
|
|
|
self.battle_pass_goto(KEYWORDS_BATTLE_PASS_TAB.Missions)
|
2023-08-02 11:07:46 +00:00
|
|
|
if SWITCH_BATTLE_PASS_MISSION_TAB.set(state, main=self):
|
|
|
|
logger.info(f'Tab goto {state}, wait until loaded')
|
2024-02-06 21:13:54 +00:00
|
|
|
if state == KEYWORDS_BATTLE_PASS_MISSION_TAB.This_Week_Missions:
|
2023-08-02 11:07:46 +00:00
|
|
|
self._battle_pass_wait_missions_loaded()
|
2024-02-06 21:13:54 +00:00
|
|
|
if state == KEYWORDS_BATTLE_PASS_MISSION_TAB.This_Period_Missions:
|
2023-08-02 11:07:46 +00:00
|
|
|
self._battle_pass_wait_missions_loaded()
|
|
|
|
|
2023-06-19 13:57:19 +00:00
|
|
|
def handle_choose_gifts(self, interval=5):
|
|
|
|
"""
|
|
|
|
Popup when you have purchase Nameless Glory
|
|
|
|
|
|
|
|
Args:
|
|
|
|
interval:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
If handled
|
|
|
|
"""
|
|
|
|
if self.appear_then_click(CLOSE_CHOOSE_GIFT, interval=interval):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _claim_exp(self, skip_first_screenshot=True):
|
2023-06-26 11:16:19 +00:00
|
|
|
logger.hr('Claim EXP', level=1)
|
2024-02-06 21:13:54 +00:00
|
|
|
self.battle_pass_goto(KEYWORDS_BATTLE_PASS_TAB.Missions)
|
2023-06-23 01:40:42 +00:00
|
|
|
claimed = False
|
2023-06-19 13:57:19 +00:00
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if not self.appear(EXP_CLAIM_ALL):
|
2023-06-26 11:16:19 +00:00
|
|
|
logger.info('No more EXP to claim')
|
2023-06-19 13:57:19 +00:00
|
|
|
break
|
|
|
|
if self.appear_then_click(EXP_CLAIM_ALL):
|
2023-06-23 01:40:42 +00:00
|
|
|
claimed = True
|
2023-06-19 13:57:19 +00:00
|
|
|
logger.info("All EXP claimed")
|
|
|
|
continue
|
2023-06-26 11:16:19 +00:00
|
|
|
|
|
|
|
logger.attr('EXP claimed', claimed)
|
2023-06-23 01:40:42 +00:00
|
|
|
return claimed
|
2023-06-19 13:57:19 +00:00
|
|
|
|
|
|
|
def _claim_rewards(self, skip_first_screenshot=True):
|
2023-06-26 11:16:19 +00:00
|
|
|
logger.hr('Claim rewards', level=1)
|
2024-02-06 21:13:54 +00:00
|
|
|
self.battle_pass_goto(KEYWORDS_BATTLE_PASS_TAB.Rewards)
|
2023-11-17 13:54:35 +00:00
|
|
|
timeout = Timer(5, count=15).start()
|
2023-06-19 13:57:19 +00:00
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
2023-11-06 14:30:43 +00:00
|
|
|
if self.reward_appear():
|
2023-06-26 11:16:19 +00:00
|
|
|
logger.info('Get reward')
|
|
|
|
break
|
|
|
|
if self.appear(CLOSE_CHOOSE_GIFT):
|
|
|
|
logger.info('Got reward but have gift to choose')
|
2023-06-19 13:57:19 +00:00
|
|
|
break
|
2023-11-17 13:54:35 +00:00
|
|
|
if timeout.reached():
|
|
|
|
logger.warning('Claim reward timeout, no rewards to claim')
|
|
|
|
break
|
2023-09-15 16:05:32 +00:00
|
|
|
if self.appear_then_click(REWARDS_CLAIM_ALL, interval=2):
|
2023-11-17 13:54:35 +00:00
|
|
|
timeout.reset()
|
2023-06-19 13:57:19 +00:00
|
|
|
continue
|
|
|
|
|
2023-11-17 13:54:35 +00:00
|
|
|
logger.info('Close reward popup')
|
2023-06-19 13:57:19 +00:00
|
|
|
skip_first_screenshot = True
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if self.appear(BATTLE_PASS_CHECK):
|
|
|
|
logger.info("Claiming rewards complete")
|
|
|
|
break
|
|
|
|
if self.handle_choose_gifts():
|
|
|
|
logger.info("You have unclaimed gift to choose")
|
|
|
|
continue
|
|
|
|
if self.handle_reward():
|
|
|
|
continue
|
|
|
|
|
2023-07-09 10:09:30 +00:00
|
|
|
def _get_battle_pass_level(self) -> int:
|
2023-06-23 01:40:42 +00:00
|
|
|
digit = Digit(OCR_LEVEL)
|
|
|
|
return digit.ocr_single_line(self.device.image)
|
|
|
|
|
2023-07-09 10:09:30 +00:00
|
|
|
def _get_battle_pass_end(self) -> datetime.datetime:
|
|
|
|
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
|
2023-07-08 04:09:23 +00:00
|
|
|
|
2023-06-19 13:57:19 +00:00
|
|
|
def claim_battle_pass_rewards(self):
|
|
|
|
"""
|
2023-07-09 10:09:30 +00:00
|
|
|
Returns:
|
|
|
|
int: Current battle pass level
|
|
|
|
|
2023-06-19 13:57:19 +00:00
|
|
|
Examples:
|
|
|
|
self = BattlePassUI('alas')
|
|
|
|
self.device.screenshot()
|
2023-06-23 01:40:42 +00:00
|
|
|
self.claim_battle_pass_rewards()
|
2023-06-19 13:57:19 +00:00
|
|
|
"""
|
2024-01-01 19:58:31 +00:00
|
|
|
# Update level
|
2023-08-30 17:06:24 +00:00
|
|
|
with self.config.multi_set():
|
|
|
|
previous_level = self._get_battle_pass_level()
|
|
|
|
self.config.stored.BattlePassLevel.set(previous_level)
|
2024-01-01 19:58:31 +00:00
|
|
|
if previous_level == self.MAX_LEVEL:
|
|
|
|
self.config.stored.BattlePassWeeklyQuest.write_quests([])
|
|
|
|
return previous_level
|
2023-08-30 17:06:24 +00:00
|
|
|
|
2023-12-27 18:03:26 +00:00
|
|
|
# Claim rewards
|
2023-06-23 01:40:42 +00:00
|
|
|
claimed_exp = self._claim_exp()
|
2023-07-08 04:09:23 +00:00
|
|
|
current_level = self._get_battle_pass_level()
|
2023-08-30 17:06:24 +00:00
|
|
|
self.config.stored.BattlePassLevel.set(current_level)
|
2023-07-08 04:09:23 +00:00
|
|
|
if claimed_exp and current_level > previous_level:
|
2023-06-23 01:40:42 +00:00
|
|
|
logger.info("Upgraded, go to claim rewards")
|
|
|
|
self._claim_rewards()
|
2024-01-01 19:58:31 +00:00
|
|
|
else:
|
|
|
|
# Missions refreshed
|
|
|
|
self._battle_pass_wait_missions_loaded()
|
|
|
|
|
|
|
|
# Update quests
|
|
|
|
self.battle_pass_quests_recognition()
|
|
|
|
|
2023-07-08 04:09:23 +00:00
|
|
|
return current_level
|
2023-06-19 13:57:19 +00:00
|
|
|
|
2024-01-01 16:43:34 +00:00
|
|
|
def ocr_single_page(self) -> list[DataBattlePassQuest]:
|
2023-08-02 11:07:46 +00:00
|
|
|
"""
|
|
|
|
Returns incomplete quests only
|
|
|
|
"""
|
2024-01-01 16:43:34 +00:00
|
|
|
logger.hr('Battle pass ocr single page')
|
2023-08-02 11:07:46 +00:00
|
|
|
ocr = BattlePassQuestOcr(OCR_BATTLE_PASS_QUEST)
|
2024-01-01 16:43:34 +00:00
|
|
|
results = ocr.matched_ocr(
|
|
|
|
self.device.image, keyword_classes=[BattlePassQuest, BattlePassQuestState, KeywordDigitCounter])
|
|
|
|
|
|
|
|
# Product DataBattlePassQuest objects
|
|
|
|
data_quest: dict[OcrResultButton, DataBattlePassQuest] = {
|
|
|
|
result: DataBattlePassQuest(result.matched_keyword)
|
|
|
|
for result in results if isinstance(result.matched_keyword, BattlePassQuest)
|
|
|
|
}
|
|
|
|
# Update quest state
|
|
|
|
list_attr = [result for result in results if isinstance(result.matched_keyword, BattlePassQuestState)]
|
|
|
|
for quest, state in pair_buttons(data_quest, list_attr, relative_area=(0, 0, 800, 100)):
|
|
|
|
data_quest[quest].state = state.matched_keyword
|
|
|
|
# Update quest progress
|
|
|
|
list_attr = [result for result in results if isinstance(result.matched_keyword, str)]
|
|
|
|
for quest, digit in pair_buttons(data_quest, list_attr, relative_area=(-50, 0, 200, 70)):
|
|
|
|
data_quest[quest].digit = digit.matched_keyword
|
|
|
|
|
|
|
|
return list(data_quest.values())
|
|
|
|
|
|
|
|
def battle_pass_quests_recognition(self):
|
2023-08-02 11:07:46 +00:00
|
|
|
"""
|
2023-12-27 18:03:26 +00:00
|
|
|
Pages:
|
2024-02-06 21:13:54 +00:00
|
|
|
in: page_battle_pass, KEYWORDS_BATTLE_PASS_TAB.Missions, weekly or period
|
2023-08-02 11:07:46 +00:00
|
|
|
"""
|
2024-01-01 19:58:31 +00:00
|
|
|
logger.hr('Quest recognise', level=1)
|
|
|
|
self.battle_pass_mission_tab_goto(
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_MISSION_TAB.This_Week_Missions)
|
2023-12-27 18:03:26 +00:00
|
|
|
|
2024-01-01 19:58:31 +00:00
|
|
|
scroll = Scroll(MISSION_PAGE_SCROLL, color=(198, 198, 198))
|
2023-12-27 18:03:26 +00:00
|
|
|
scroll.set_top(main=self)
|
2024-01-01 19:58:31 +00:00
|
|
|
|
2024-01-01 16:43:34 +00:00
|
|
|
results: list[DataBattlePassQuest] = []
|
2023-12-27 18:03:26 +00:00
|
|
|
while 1:
|
|
|
|
results += [result for result in self.ocr_single_page() if result not in results]
|
|
|
|
if scroll.at_bottom(main=self):
|
|
|
|
logger.info('Quest list reached bottom')
|
|
|
|
break
|
2024-01-01 19:58:31 +00:00
|
|
|
if scroll.next_page(main=self):
|
|
|
|
continue
|
2023-12-27 18:03:26 +00:00
|
|
|
else:
|
2024-01-01 19:58:31 +00:00
|
|
|
self.device.screenshot()
|
2023-12-27 18:03:26 +00:00
|
|
|
|
2024-01-01 16:43:34 +00:00
|
|
|
# Convert quest keyword to stored object
|
|
|
|
dic_quest_to_stored = {
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_QUEST.Complete_Simulated_Universe_1_times:
|
2024-01-01 16:43:34 +00:00
|
|
|
self.config.stored.BattlePassSimulatedUniverse,
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_QUEST.Clear_Calyx_1_times:
|
2024-01-01 16:43:34 +00:00
|
|
|
self.config.stored.BattlePassQuestCalyx,
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_QUEST.Complete_Echo_of_War_1_times:
|
2024-01-01 16:43:34 +00:00
|
|
|
self.config.stored.BattlePassQuestEchoOfWar,
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_QUEST.Use_300000_credits:
|
2024-01-01 16:43:34 +00:00
|
|
|
self.config.stored.BattlePassQuestCredits,
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_QUEST.Synthesize_Consumables_1_times:
|
2024-01-01 16:43:34 +00:00
|
|
|
self.config.stored.BattlePassQuestSynthesizeConsumables,
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_QUEST.Clear_Cavern_of_Corrosion_1_times:
|
2024-01-01 16:43:34 +00:00
|
|
|
self.config.stored.BattlePassQuestCavernOfCorrosion,
|
2024-02-06 21:13:54 +00:00
|
|
|
KEYWORDS_BATTLE_PASS_QUEST.Consume_a_total_of_1_Trailblaze_Power_1400_Trailblazer_Power_max:
|
2024-01-01 16:43:34 +00:00
|
|
|
self.config.stored.BattlePassQuestTrailblazePower,
|
|
|
|
}
|
|
|
|
with self.config.multi_set():
|
|
|
|
# Write incomplete quests
|
|
|
|
quests = [result.quest for result in results if result.is_incomplete]
|
|
|
|
self.config.stored.BattlePassWeeklyQuest.write_quests(quests)
|
|
|
|
# Create an OCR object just for calling format_result()
|
|
|
|
ocr = DigitCounter(OCR_BATTLE_PASS_QUEST)
|
|
|
|
# Write quest progresses
|
|
|
|
for result in results:
|
|
|
|
ocr.name = result.quest.name
|
|
|
|
current, _, total = ocr.format_result(result.digit)
|
|
|
|
if total == 0:
|
|
|
|
logger.error(f'Battle pass quests {result.quest} progress invalid: {result.digit}')
|
|
|
|
continue
|
|
|
|
stored: StoredCounter = dic_quest_to_stored.get(result.quest, None)
|
|
|
|
# Check if exist
|
|
|
|
if stored is None:
|
|
|
|
logger.error(f'Battle pass quest {result.quest} has not corresponding stored object')
|
|
|
|
continue
|
|
|
|
# Check total
|
|
|
|
if stored.FIXED_TOTAL and total != stored.FIXED_TOTAL:
|
|
|
|
logger.error(f'Battle pass quest progress {current}/{total} does not match its stored object')
|
|
|
|
continue
|
|
|
|
if hasattr(stored, 'LIST_TOTAL') and total not in stored.LIST_TOTAL:
|
|
|
|
logger.error(f'Battle pass quest progress {current}/{total} is not in LIST_TOTAL')
|
|
|
|
continue
|
|
|
|
# Set
|
|
|
|
stored.set(current, total=total)
|
2023-08-02 11:07:46 +00:00
|
|
|
|
2023-07-29 08:42:34 +00:00
|
|
|
def has_battle_pass_entrance(self, skip_first_screenshot=True):
|
|
|
|
"""
|
|
|
|
Pages:
|
|
|
|
in: page_main
|
|
|
|
"""
|
|
|
|
timeout = Timer(0.5, count=2).start()
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if timeout.reached():
|
|
|
|
break
|
|
|
|
|
|
|
|
if self.appear(MAIN_GOTO_BATTLE_PASS, similarity=0.75):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
|
2023-10-09 04:16:03 +00:00
|
|
|
logger.info('No battle pass entrance, probably a gap between two periods')
|
2023-07-29 08:42:34 +00:00
|
|
|
return False
|
|
|
|
|
2023-06-19 13:57:19 +00:00
|
|
|
def run(self):
|
2023-07-17 05:40:58 +00:00
|
|
|
self.ui_ensure(page_main)
|
2023-07-29 08:42:34 +00:00
|
|
|
if not self.has_battle_pass_entrance():
|
2023-12-27 18:03:26 +00:00
|
|
|
self.config.stored.BattlePassWeeklyQuest.set(0)
|
2023-07-17 05:40:58 +00:00
|
|
|
self.config.task_delay(server_update=True)
|
|
|
|
self.config.task_stop()
|
|
|
|
|
|
|
|
self.ui_goto(page_battle_pass)
|
2023-07-08 04:09:23 +00:00
|
|
|
current_level = self.claim_battle_pass_rewards()
|
|
|
|
if current_level == self.MAX_LEVEL:
|
2023-07-09 10:09:30 +00:00
|
|
|
self.config.task_delay(target=self._get_battle_pass_end())
|
2023-07-08 04:09:23 +00:00
|
|
|
else:
|
|
|
|
self.config.task_delay(server_update=True)
|