Fix: Battle pass quest callbacks as dailies are removed (#254)

This commit is contained in:
LmeSzinc 2024-01-02 04:07:35 +08:00
parent 7e543c2215
commit d783aa23d9
5 changed files with 125 additions and 47 deletions

View File

@ -155,6 +155,9 @@ class StoredCounter(StoredBase):
def get_remain(self) -> int: def get_remain(self) -> int:
return self.total - self.value return self.total - self.value
def add(self, value=1):
self.value += value
@cached_property @cached_property
def _attrs(self) -> dict: def _attrs(self) -> dict:
attrs = super()._attrs attrs = super()._attrs

View File

@ -15,7 +15,7 @@ from tasks.daily.keywords import (
KEYWORDS_DAILY_QUEST, KEYWORDS_DAILY_QUEST,
KEYWORDS_DAILY_QUEST_STATE, KEYWORDS_DAILY_QUEST_STATE,
) )
from tasks.daily.synthesize import SynthesizeConsumablesUI, SynthesizeMaterialUI from tasks.daily.synthesize import SynthesizeMaterialUI
from tasks.daily.use_technique import UseTechniqueUI from tasks.daily.use_technique import UseTechniqueUI
from tasks.dungeon.assets.assets_dungeon_ui import DAILY_TRAINING_CHECK from tasks.dungeon.assets.assets_dungeon_ui import DAILY_TRAINING_CHECK
from tasks.dungeon.keywords import KEYWORDS_DUNGEON_TAB from tasks.dungeon.keywords import KEYWORDS_DUNGEON_TAB
@ -64,6 +64,9 @@ class DailyQuestOcr(Ocr):
class DailyQuestUI(DungeonUI, RouteLoader): class DailyQuestUI(DungeonUI, RouteLoader):
claimed_point_reward = False
synthesized_material = False
def _ensure_position(self, direction: str, skip_first_screenshot=True): def _ensure_position(self, direction: str, skip_first_screenshot=True):
interval = Timer(5) interval = Timer(5)
if direction == 'left': if direction == 'left':
@ -160,6 +163,9 @@ class DailyQuestUI(DungeonUI, RouteLoader):
return self.appear(ACTIVE_POINTS_5_CHECKED) return self.appear(ACTIVE_POINTS_5_CHECKED)
def _get_active_point_reward(self, skip_first_screenshot=True): def _get_active_point_reward(self, skip_first_screenshot=True):
"""
self.claimed_point_reward will be set if claimed any point reward
"""
def get_active(): def get_active():
for b in [ for b in [
ACTIVE_POINTS_1_UNLOCK, ACTIVE_POINTS_1_UNLOCK,
@ -188,6 +194,7 @@ class DailyQuestUI(DungeonUI, RouteLoader):
if interval.reached(): if interval.reached():
if active := get_active(): if active := get_active():
self.device.click(active) self.device.click(active)
self.claimed_point_reward = True
interval.reset() interval.reset()
# Write stored # Write stored
@ -252,6 +259,7 @@ class DailyQuestUI(DungeonUI, RouteLoader):
""" """
if KEYWORDS_DAILY_QUEST.Use_the_Omni_Synthesizer_1_times in quests: if KEYWORDS_DAILY_QUEST.Use_the_Omni_Synthesizer_1_times in quests:
if SynthesizeMaterialUI(self.config, self.device).synthesize_material(): if SynthesizeMaterialUI(self.config, self.device).synthesize_material():
self.synthesized_material = True
done += 1 done += 1
if KEYWORDS_DAILY_QUEST.Use_Consumables_1_time in quests: if KEYWORDS_DAILY_QUEST.Use_Consumables_1_time in quests:
if ConsumableUsageUI(self.config, self.device).use_consumable(): if ConsumableUsageUI(self.config, self.device).use_consumable():
@ -308,6 +316,8 @@ class DailyQuestUI(DungeonUI, RouteLoader):
def run(self): def run(self):
self.config.update_battle_pass_quests() self.config.update_battle_pass_quests()
self.claimed_point_reward = False
self.synthesized_material = False
for _ in range(5): for _ in range(5):
got = self.get_daily_rewards() got = self.get_daily_rewards()
@ -319,17 +329,23 @@ class DailyQuestUI(DungeonUI, RouteLoader):
break break
# Scheduler # Scheduler
logger.attr('claimed_point_reward', self.claimed_point_reward)
logger.attr('synthesized_material', self.synthesized_material)
with self.config.multi_set(): with self.config.multi_set():
# Check battle pass # Check battle pass
if self.config.stored.DailyActivity.value == 500: # Cannot archive as daily is done by synthesizing material
quests = self.config.stored.BattlePassWeeklyQuest.load_quests() # but battle pass quests need synthesizing consumables.
if KEYWORD_BATTLE_PASS_QUEST.Consume_a_total_of_1_Trailblaze_Power_1400_Trailblazer_Power_max in quests: # if self.synthesized_material:
logger.info('Achieved battle pass quest Consume_a_total_of_1_Trailblaze_Power_1400_Trailblazer_Power_max') # quests = self.config.stored.BattlePassWeeklyQuest.load_quests()
if self.config.stored.BattlePassLevel.is_full(): # if KEYWORD_BATTLE_PASS_QUEST.Synthesize_Consumables_1_times in quests:
logger.info('BattlePassLevel full, no task call') # logger.info('Done weekly quest Synthesize_Consumables_1_times once')
else: # self.config.stored.BattlePassQuestSynthesizeConsumables.add()
self.config.task_call('BattlePass') # if self.config.stored.BattlePassQuestSynthesizeConsumables.is_full():
self.config.task_call('DataUpdate') # logger.info('Achieve weekly quest BattlePassQuestSynthesizeConsumables')
# self.config.task_call('BattlePass')
# Update dashboard
if self.claimed_point_reward:
self.config.task_call('DataUpdate')
# Delay self # Delay self
self.config.task_delay(server_update=True) self.config.task_delay(server_update=True)

View File

@ -11,8 +11,10 @@ from tasks.dungeon.stamina import DungeonStamina
class Dungeon(DungeonStamina, DungeonEvent, Combat): class Dungeon(DungeonStamina, DungeonEvent, Combat):
called_daily_support = False called_daily_support = False
achieved_daily_quest = False achieved_daily_quest = False
achieved_weekly_quest = False
running_double = False running_double = False
daily_quests = [] daily_quests = []
weekly_quests = []
def _dungeon_run(self, dungeon: DungeonList, team: int = None, wave_limit: int = 0, support_character: str = None, def _dungeon_run(self, dungeon: DungeonList, team: int = None, wave_limit: int = 0, support_character: str = None,
skip_ui_switch: bool = False): skip_ui_switch: bool = False):
@ -76,31 +78,75 @@ class Dungeon(DungeonStamina, DungeonEvent, Combat):
count = self.combat(team=team, wave_limit=wave_limit, support_character=support_character) count = self.combat(team=team, wave_limit=wave_limit, support_character=support_character)
# Update quest states # Update quest states
if dungeon.is_Calyx_Golden \ with self.config.multi_set():
and KEYWORDS_DAILY_QUEST.Clear_Calyx_Golden_1_times in self.daily_quests: # Calyx_Golden
logger.info('Achieved daily quest Clear_Calyx_Golden_1_times') if dungeon.is_Calyx_Golden:
self.achieved_daily_quest = True if KEYWORDS_DAILY_QUEST.Clear_Calyx_Golden_1_times in self.daily_quests:
if dungeon.is_Calyx_Crimson \ logger.info('Achieved daily quest Clear_Calyx_Golden_1_times')
and KEYWORDS_DAILY_QUEST.Clear_Calyx_Crimson_1_times in self.daily_quests: self.achieved_daily_quest = True
logger.info('Achieve daily quest Clear_Calyx_Crimson_1_times') if KEYWORD_BATTLE_PASS_QUEST.Clear_Calyx_1_times in self.weekly_quests:
self.achieved_daily_quest = True logger.info('Done weekly quest Clear_Calyx_1_times once')
if dungeon.is_Stagnant_Shadow \ self.config.stored.BattlePassQuestCalyx.add()
and KEYWORDS_DAILY_QUEST.Clear_Stagnant_Shadow_1_times in self.daily_quests: if self.config.stored.BattlePassQuestCalyx.is_full():
logger.info('Achieve daily quest Clear_Stagnant_Shadow_1_times') logger.info('Achieved weekly quest BattlePassQuestCalyx')
self.achieved_daily_quest = True self.achieved_weekly_quest = True
if dungeon.is_Cavern_of_Corrosion \ # Calyx_Crimson
and KEYWORDS_DAILY_QUEST.Clear_Cavern_of_Corrosion_1_times in self.daily_quests: if dungeon.is_Calyx_Crimson:
logger.info('Achieve daily quest Clear_Cavern_of_Corrosion_1_times') if KEYWORDS_DAILY_QUEST.Clear_Calyx_Crimson_1_times in self.daily_quests:
self.achieved_daily_quest = True logger.info('Achieve daily quest Clear_Calyx_Crimson_1_times')
if support_character is not None: self.achieved_daily_quest = True
self.called_daily_support = True if KEYWORD_BATTLE_PASS_QUEST.Clear_Calyx_1_times in self.weekly_quests:
if KEYWORDS_DAILY_QUEST.Obtain_victory_in_combat_with_Support_Characters_1_times: logger.info('Done weekly quest Clear_Calyx_1_times once')
logger.info('Achieve daily quest Obtain_victory_in_combat_with_Support_Characters_1_times') self.config.stored.BattlePassQuestCalyx.add()
self.achieved_daily_quest = True if self.config.stored.BattlePassQuestCalyx.is_full():
logger.info('Achieved weekly quest BattlePassQuestCalyx')
self.achieved_weekly_quest = True
# Stagnant_Shadow
if dungeon.is_Stagnant_Shadow:
if KEYWORDS_DAILY_QUEST.Clear_Stagnant_Shadow_1_times in self.daily_quests:
logger.info('Achieve daily quest Clear_Stagnant_Shadow_1_times')
self.achieved_daily_quest = True
# Cavern_of_Corrosion
if dungeon.is_Cavern_of_Corrosion:
if KEYWORDS_DAILY_QUEST.Clear_Cavern_of_Corrosion_1_times in self.daily_quests:
logger.info('Achieve daily quest Clear_Cavern_of_Corrosion_1_times')
self.achieved_daily_quest = True
if KEYWORD_BATTLE_PASS_QUEST.Clear_Cavern_of_Corrosion_1_times in self.weekly_quests:
logger.info('Done weekly quest Clear_Cavern_of_Corrosion_1_times once')
self.config.stored.BattlePassQuestCavernOfCorrosion.add()
if self.config.stored.BattlePassQuestCavernOfCorrosion.is_full():
logger.info('Achieved weekly quest Clear_Cavern_of_Corrosion_1_times')
self.achieved_weekly_quest = True
# Echo_of_War
if dungeon.is_Echo_of_War:
if KEYWORDS_DAILY_QUEST.Complete_Echo_of_War_1_times in self.daily_quests:
logger.info('Achieve daily quest Complete_Echo_of_War_1_times')
self.achieved_daily_quest = True
if KEYWORD_BATTLE_PASS_QUEST.Complete_Echo_of_War_1_times in self.weekly_quests:
logger.info('Done weekly quest Complete_Echo_of_War_1_times once')
self.config.stored.BattlePassQuestEchoOfWar.add()
if self.config.stored.BattlePassQuestEchoOfWar.is_full():
logger.info('Achieved weekly quest Complete_Echo_of_War_1_times')
self.achieved_weekly_quest = True
# Support quest
if support_character is not None:
self.called_daily_support = True
if KEYWORDS_DAILY_QUEST.Obtain_victory_in_combat_with_Support_Characters_1_times:
logger.info('Achieve daily quest Obtain_victory_in_combat_with_Support_Characters_1_times')
self.achieved_daily_quest = True
# Stamina quest
if KEYWORD_BATTLE_PASS_QUEST.Consume_a_total_of_1_Trailblaze_Power_1400_Trailblazer_Power_max in self.weekly_quests:
cost = self.combat_wave_cost * count
logger.info(f'Done Consume_a_total_of_1_Trailblaze_Power_1400_Trailblazer_Power_max stamina {cost}')
self.config.stored.BattlePassQuestTrailblazePower.add(cost)
if self.config.stored.BattlePassQuestTrailblazePower.is_full():
logger.info('Achieved weekly quest Consume_a_total_of_1_Trailblaze_Power_1400_Trailblazer_Power_max')
self.achieved_weekly_quest = True
# Check trailblaze power, this may stop current task
if self.is_trailblaze_power_exhausted():
self.delay_dungeon_task(dungeon)
# Check trailblaze power, this may stop current task
if self.is_trailblaze_power_exhausted():
self.delay_dungeon_task(dungeon)
return count return count
def dungeon_run( def dungeon_run(
@ -147,8 +193,10 @@ class Dungeon(DungeonStamina, DungeonEvent, Combat):
self.config.update_daily_quests() self.config.update_daily_quests()
self.called_daily_support = False self.called_daily_support = False
self.achieved_daily_quest = False self.achieved_daily_quest = False
self.achieved_weekly_quest = False
self.running_double = False self.running_double = False
self.daily_quests = self.config.stored.DailyQuest.load_quests() self.daily_quests = self.config.stored.DailyQuest.load_quests()
self.weekly_quests = self.config.stored.BattlePassWeeklyQuest.load_quests()
# Update double event records # Update double event records
if (self.config.stored.DungeonDouble.is_expired() if (self.config.stored.DungeonDouble.is_expired()
@ -242,6 +290,9 @@ class Dungeon(DungeonStamina, DungeonEvent, Combat):
if self.achieved_daily_quest: if self.achieved_daily_quest:
self.config.task_call('DailyQuest') self.config.task_call('DailyQuest')
self.config.task_stop() self.config.task_stop()
if self.achieved_weekly_quest:
self.config.task_call('BattlePass')
self.config.task_stop()
# Use all stamina # Use all stamina
if final.is_Simulated_Universe: if final.is_Simulated_Universe:
@ -265,15 +316,11 @@ class Dungeon(DungeonStamina, DungeonEvent, Combat):
def delay_dungeon_task(self, dungeon: DungeonList): def delay_dungeon_task(self, dungeon: DungeonList):
logger.attr('achieved_daily_quest', self.achieved_daily_quest) logger.attr('achieved_daily_quest', self.achieved_daily_quest)
logger.attr('achieved_weekly_quest', self.achieved_weekly_quest)
with self.config.multi_set(): with self.config.multi_set():
# Check battle pass # Check battle pass
quests = self.config.stored.BattlePassWeeklyQuest.load_quests() if self.achieved_weekly_quest:
if KEYWORD_BATTLE_PASS_QUEST.Consume_a_total_of_1_Trailblaze_Power_1400_Trailblazer_Power_max in quests: self.config.task_call('BattlePass')
logger.info('Probably achieved battle pass quest Consume_a_total_of_1_Trailblaze_Power_1400_Trailblazer_Power_max')
if self.config.stored.BattlePassLevel.is_full():
logger.info('BattlePassLevel full, no task call')
else:
self.config.task_call('BattlePass')
# Check daily # Check daily
if self.achieved_daily_quest: if self.achieved_daily_quest:
self.config.task_call('DailyQuest') self.config.task_call('DailyQuest')

View File

@ -30,7 +30,6 @@ class WeeklyDungeon(Dungeon):
ocr = DigitCounter(OCR_WEEKLY_LIMIT) ocr = DigitCounter(OCR_WEEKLY_LIMIT)
current, _, _ = ocr.ocr_single_line(self.device.image) current, _, _ = ocr.ocr_single_line(self.device.image)
total = self.config.stored.EchoOfWar.FIXED_TOTAL total = self.config.stored.EchoOfWar.FIXED_TOTAL
remain = total - current
if current <= total: if current <= total:
logger.attr('EchoOfWar', f'{current}/{total}') logger.attr('EchoOfWar', f'{current}/{total}')
self.config.stored.EchoOfWar.value = current self.config.stored.EchoOfWar.value = current
@ -44,7 +43,9 @@ class WeeklyDungeon(Dungeon):
self.config.update_daily_quests() self.config.update_daily_quests()
self.called_daily_support = False self.called_daily_support = False
self.achieved_daily_quest = False self.achieved_daily_quest = False
self.achieved_weekly_quest = False
self.daily_quests = self.config.stored.DailyQuest.load_quests() self.daily_quests = self.config.stored.DailyQuest.load_quests()
self.weekly_quests = self.config.stored.BattlePassWeeklyQuest.load_quests()
dungeon = DungeonList.find(self.config.Weekly_Name) dungeon = DungeonList.find(self.config.Weekly_Name)
@ -71,11 +72,15 @@ class WeeklyDungeon(Dungeon):
# Combat # Combat
count = self.dungeon_run(dungeon, wave_limit=min(remain, 3)) count = self.dungeon_run(dungeon, wave_limit=min(remain, 3))
logger.attr('achieved_daily_quest', self.achieved_daily_quest)
logger.attr('achieved_weekly_quest', self.achieved_weekly_quest)
with self.config.multi_set(): with self.config.multi_set():
# Check daily quests
if count: if count:
if KEYWORDS_DAILY_QUEST.Complete_Echo_of_War_1_times in self.daily_quests: # Check battle pass
logger.info('Achieve daily quest Complete_Echo_of_War_1_times') if self.achieved_weekly_quest:
self.config.task_call('BattlePass')
# Check daily
if self.achieved_daily_quest:
self.config.task_call('DailyQuest') self.config.task_call('DailyQuest')
# Finished all remains # Finished all remains
if count >= remain: if count >= remain:

View File

@ -1,5 +1,6 @@
from module.logger import logger from module.logger import logger
from tasks.daily.keywords.daily_quest import Complete_Simulated_Universe_1_times from tasks.battle_pass.keywords import KEYWORD_BATTLE_PASS_QUEST
from tasks.daily.keywords import KEYWORDS_DAILY_QUEST
from tasks.rogue.entry.entry import RogueEntry from tasks.rogue.entry.entry import RogueEntry
from tasks.rogue.exception import RogueReachedWeeklyPointLimit, RogueTeamNotPrepared from tasks.rogue.exception import RogueReachedWeeklyPointLimit, RogueTeamNotPrepared
from tasks.rogue.route.loader import RouteLoader from tasks.rogue.route.loader import RouteLoader
@ -30,6 +31,7 @@ class Rogue(RouteLoader, RogueEntry):
return True return True
def run(self): def run(self):
self.config.update_battle_pass_quests()
self.config.update_daily_quests() self.config.update_daily_quests()
while 1: while 1:
# Run # Run
@ -43,10 +45,15 @@ class Rogue(RouteLoader, RogueEntry):
# Archived daily quest # Archived daily quest
if success: if success:
quests = self.config.stored.DailyQuest.load_quests() quests = self.config.stored.DailyQuest.load_quests()
if Complete_Simulated_Universe_1_times in quests: if KEYWORDS_DAILY_QUEST.Complete_Simulated_Universe_1_times in quests:
logger.info('Achieve daily quest Complete_Simulated_Universe_1_times') logger.info('Achieve daily quest Complete_Simulated_Universe_1_times')
self.config.task_call('DailyQuest') self.config.task_call('DailyQuest')
self.config.task_stop() self.config.task_stop()
quests = self.config.stored.BattlePassWeeklyQuest.load_quests()
if KEYWORD_BATTLE_PASS_QUEST.Complete_Simulated_Universe_1_times in quests:
logger.info('Achieve battle pass quest Complete_Simulated_Universe_1_times')
self.config.task_call('BattlePass')
self.config.task_stop()
# End # End
if not success: if not success:
self.config.task_delay(server_update=True) self.config.task_delay(server_update=True)