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:
return self.total - self.value
def add(self, value=1):
self.value += value
@cached_property
def _attrs(self) -> dict:
attrs = super()._attrs

View File

@ -15,7 +15,7 @@ from tasks.daily.keywords import (
KEYWORDS_DAILY_QUEST,
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.dungeon.assets.assets_dungeon_ui import DAILY_TRAINING_CHECK
from tasks.dungeon.keywords import KEYWORDS_DUNGEON_TAB
@ -64,6 +64,9 @@ class DailyQuestOcr(Ocr):
class DailyQuestUI(DungeonUI, RouteLoader):
claimed_point_reward = False
synthesized_material = False
def _ensure_position(self, direction: str, skip_first_screenshot=True):
interval = Timer(5)
if direction == 'left':
@ -160,6 +163,9 @@ class DailyQuestUI(DungeonUI, RouteLoader):
return self.appear(ACTIVE_POINTS_5_CHECKED)
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():
for b in [
ACTIVE_POINTS_1_UNLOCK,
@ -188,6 +194,7 @@ class DailyQuestUI(DungeonUI, RouteLoader):
if interval.reached():
if active := get_active():
self.device.click(active)
self.claimed_point_reward = True
interval.reset()
# Write stored
@ -252,6 +259,7 @@ class DailyQuestUI(DungeonUI, RouteLoader):
"""
if KEYWORDS_DAILY_QUEST.Use_the_Omni_Synthesizer_1_times in quests:
if SynthesizeMaterialUI(self.config, self.device).synthesize_material():
self.synthesized_material = True
done += 1
if KEYWORDS_DAILY_QUEST.Use_Consumables_1_time in quests:
if ConsumableUsageUI(self.config, self.device).use_consumable():
@ -308,6 +316,8 @@ class DailyQuestUI(DungeonUI, RouteLoader):
def run(self):
self.config.update_battle_pass_quests()
self.claimed_point_reward = False
self.synthesized_material = False
for _ in range(5):
got = self.get_daily_rewards()
@ -319,16 +329,22 @@ class DailyQuestUI(DungeonUI, RouteLoader):
break
# Scheduler
logger.attr('claimed_point_reward', self.claimed_point_reward)
logger.attr('synthesized_material', self.synthesized_material)
with self.config.multi_set():
# Check battle pass
if self.config.stored.DailyActivity.value == 500:
quests = self.config.stored.BattlePassWeeklyQuest.load_quests()
if KEYWORD_BATTLE_PASS_QUEST.Consume_a_total_of_1_Trailblaze_Power_1400_Trailblazer_Power_max in quests:
logger.info('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')
# Cannot archive as daily is done by synthesizing material
# but battle pass quests need synthesizing consumables.
# if self.synthesized_material:
# quests = self.config.stored.BattlePassWeeklyQuest.load_quests()
# if KEYWORD_BATTLE_PASS_QUEST.Synthesize_Consumables_1_times in quests:
# logger.info('Done weekly quest Synthesize_Consumables_1_times once')
# self.config.stored.BattlePassQuestSynthesizeConsumables.add()
# if self.config.stored.BattlePassQuestSynthesizeConsumables.is_full():
# 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
self.config.task_delay(server_update=True)

View File

@ -11,8 +11,10 @@ from tasks.dungeon.stamina import DungeonStamina
class Dungeon(DungeonStamina, DungeonEvent, Combat):
called_daily_support = False
achieved_daily_quest = False
achieved_weekly_quest = False
running_double = False
daily_quests = []
weekly_quests = []
def _dungeon_run(self, dungeon: DungeonList, team: int = None, wave_limit: int = 0, support_character: str = None,
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)
# Update quest states
if dungeon.is_Calyx_Golden \
and KEYWORDS_DAILY_QUEST.Clear_Calyx_Golden_1_times in self.daily_quests:
with self.config.multi_set():
# Calyx_Golden
if dungeon.is_Calyx_Golden:
if KEYWORDS_DAILY_QUEST.Clear_Calyx_Golden_1_times in self.daily_quests:
logger.info('Achieved daily quest Clear_Calyx_Golden_1_times')
self.achieved_daily_quest = True
if dungeon.is_Calyx_Crimson \
and KEYWORDS_DAILY_QUEST.Clear_Calyx_Crimson_1_times in self.daily_quests:
if KEYWORD_BATTLE_PASS_QUEST.Clear_Calyx_1_times in self.weekly_quests:
logger.info('Done weekly quest Clear_Calyx_1_times once')
self.config.stored.BattlePassQuestCalyx.add()
if self.config.stored.BattlePassQuestCalyx.is_full():
logger.info('Achieved weekly quest BattlePassQuestCalyx')
self.achieved_weekly_quest = True
# Calyx_Crimson
if dungeon.is_Calyx_Crimson:
if KEYWORDS_DAILY_QUEST.Clear_Calyx_Crimson_1_times in self.daily_quests:
logger.info('Achieve daily quest Clear_Calyx_Crimson_1_times')
self.achieved_daily_quest = True
if dungeon.is_Stagnant_Shadow \
and KEYWORDS_DAILY_QUEST.Clear_Stagnant_Shadow_1_times in self.daily_quests:
if KEYWORD_BATTLE_PASS_QUEST.Clear_Calyx_1_times in self.weekly_quests:
logger.info('Done weekly quest Clear_Calyx_1_times once')
self.config.stored.BattlePassQuestCalyx.add()
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
if dungeon.is_Cavern_of_Corrosion \
and KEYWORDS_DAILY_QUEST.Clear_Cavern_of_Corrosion_1_times in self.daily_quests:
# 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)
return count
def dungeon_run(
@ -147,8 +193,10 @@ class Dungeon(DungeonStamina, DungeonEvent, Combat):
self.config.update_daily_quests()
self.called_daily_support = False
self.achieved_daily_quest = False
self.achieved_weekly_quest = False
self.running_double = False
self.daily_quests = self.config.stored.DailyQuest.load_quests()
self.weekly_quests = self.config.stored.BattlePassWeeklyQuest.load_quests()
# Update double event records
if (self.config.stored.DungeonDouble.is_expired()
@ -242,6 +290,9 @@ class Dungeon(DungeonStamina, DungeonEvent, Combat):
if self.achieved_daily_quest:
self.config.task_call('DailyQuest')
self.config.task_stop()
if self.achieved_weekly_quest:
self.config.task_call('BattlePass')
self.config.task_stop()
# Use all stamina
if final.is_Simulated_Universe:
@ -265,14 +316,10 @@ class Dungeon(DungeonStamina, DungeonEvent, Combat):
def delay_dungeon_task(self, dungeon: DungeonList):
logger.attr('achieved_daily_quest', self.achieved_daily_quest)
logger.attr('achieved_weekly_quest', self.achieved_weekly_quest)
with self.config.multi_set():
# Check battle pass
quests = self.config.stored.BattlePassWeeklyQuest.load_quests()
if KEYWORD_BATTLE_PASS_QUEST.Consume_a_total_of_1_Trailblaze_Power_1400_Trailblazer_Power_max in quests:
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:
if self.achieved_weekly_quest:
self.config.task_call('BattlePass')
# Check daily
if self.achieved_daily_quest:

View File

@ -30,7 +30,6 @@ class WeeklyDungeon(Dungeon):
ocr = DigitCounter(OCR_WEEKLY_LIMIT)
current, _, _ = ocr.ocr_single_line(self.device.image)
total = self.config.stored.EchoOfWar.FIXED_TOTAL
remain = total - current
if current <= total:
logger.attr('EchoOfWar', f'{current}/{total}')
self.config.stored.EchoOfWar.value = current
@ -44,7 +43,9 @@ class WeeklyDungeon(Dungeon):
self.config.update_daily_quests()
self.called_daily_support = False
self.achieved_daily_quest = False
self.achieved_weekly_quest = False
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)
@ -71,11 +72,15 @@ class WeeklyDungeon(Dungeon):
# Combat
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():
# Check daily quests
if count:
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')
# Check battle pass
if self.achieved_weekly_quest:
self.config.task_call('BattlePass')
# Check daily
if self.achieved_daily_quest:
self.config.task_call('DailyQuest')
# Finished all remains
if count >= remain:

View File

@ -1,5 +1,6 @@
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.exception import RogueReachedWeeklyPointLimit, RogueTeamNotPrepared
from tasks.rogue.route.loader import RouteLoader
@ -30,6 +31,7 @@ class Rogue(RouteLoader, RogueEntry):
return True
def run(self):
self.config.update_battle_pass_quests()
self.config.update_daily_quests()
while 1:
# Run
@ -43,10 +45,15 @@ class Rogue(RouteLoader, RogueEntry):
# Archived daily quest
if success:
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')
self.config.task_call('DailyQuest')
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
if not success:
self.config.task_delay(server_update=True)