From b5030e0ab135b2d76fa1f7149cf54e79c35feee2 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Sun, 27 Aug 2023 17:27:47 +0800 Subject: [PATCH] Add: Link task Assignment with daily tasks --- module/config/config.py | 14 ++++++++++++++ tasks/assignment/assignment.py | 23 ++++++++++++++++++----- tasks/assignment/keywords/__init__.py | 10 +++++----- tasks/dungeon/dungeon.py | 11 +---------- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/module/config/config.py b/module/config/config.py index 4da400e6f..79d16abf8 100644 --- a/module/config/config.py +++ b/module/config/config.py @@ -484,6 +484,20 @@ class AzurLaneConfig(ConfigUpdater, ManualConfig, GeneratedConfig, ConfigWatcher def is_task_enabled(self, task): return bool(self.cross_get(keys=[task, 'Scheduler', 'Enable'], default=False)) + def update_daily_quests(self): + """ + Raises: + TaskEnd: Call task `DailyQuest` and stop current task + """ + if self.stored.DailyActivity.is_expired(): + logger.info('Daily activity expired, call task to update') + self.task_call('DailyQuest') + self.task_stop() + if self.stored.DailyQuest.is_expired(): + logger.info('Daily quests expired, call task to update') + self.task_call('DailyQuest') + self.task_stop() + @property def DEVICE_SCREENSHOT_METHOD(self): return self.Emulator_ScreenshotMethod diff --git a/tasks/assignment/assignment.py b/tasks/assignment/assignment.py index 24191c754..e15877253 100644 --- a/tasks/assignment/assignment.py +++ b/tasks/assignment/assignment.py @@ -3,19 +3,27 @@ from datetime import datetime from module.logger import logger from module.ocr.ocr import Duration from tasks.assignment.assets.assets_assignment_claim import CLAIM -from tasks.assignment.assets.assets_assignment_ui import (DISPATCHED, - OCR_ASSIGNMENT_TIME) +from tasks.assignment.assets.assets_assignment_ui import ( + DISPATCHED, + OCR_ASSIGNMENT_TIME, +) from tasks.assignment.claim import AssignmentClaim -from tasks.assignment.keywords import * +from tasks.assignment.keywords import ( + AssignmentEntry, + KEYWORDS_ASSIGNMENT_GROUP, +) from tasks.base.page import page_assignment, page_menu +from tasks.daily.keywords import KEYWORDS_DAILY_QUEST from tasks.daily.synthesize import SynthesizeUI class Assignment(AssignmentClaim, SynthesizeUI): def run(self, assignments: list[AssignmentEntry] = None, duration: int = None): + self.config.update_daily_quests() + if assignments is None: assignments = ( - getattr(self.config, f'Assignment_Name_{i+1}', None) for i in range(4)) + getattr(self.config, f'Assignment_Name_{i + 1}', None) for i in range(4)) # remove duplicate while keeping order assignments = list(dict.fromkeys( x for x in assignments if x is not None)) @@ -46,7 +54,12 @@ class Assignment(AssignmentClaim, SynthesizeUI): # Scheduler delay = min(self.dispatched.values()) logger.info(f'Delay assignment check to {str(delay)}') - self.config.task_delay(target=delay) + with self.config.multi_set(): + quests = self.config.stored.DailyQuest.load_quests() + if KEYWORDS_DAILY_QUEST.Go_on_assignment_1_time in quests: + logger.info('Achieved daily quest Go_on_assignment_1_time') + self.config.task_call('DailyQuest') + self.config.task_delay(target=delay) def _check_inlist(self, assignments: list[AssignmentEntry], duration: int): """ diff --git a/tasks/assignment/keywords/__init__.py b/tasks/assignment/keywords/__init__.py index 3ecbdeebf..d307fb7ec 100644 --- a/tasks/assignment/keywords/__init__.py +++ b/tasks/assignment/keywords/__init__.py @@ -1,6 +1,6 @@ import tasks.assignment.keywords.entry as KEYWORDS_ASSIGNMENT_ENTRY import tasks.assignment.keywords.group as KEYWORDS_ASSIGNMENT_GROUP -from tasks.assignment.keywords.classes import AssignmentGroup, AssignmentEntry +from tasks.assignment.keywords.classes import AssignmentEntry, AssignmentGroup KEYWORDS_ASSIGNMENT_GROUP.Character_Materials.entries = ( KEYWORDS_ASSIGNMENT_ENTRY.Nine_Billion_Names, @@ -22,9 +22,9 @@ KEYWORDS_ASSIGNMENT_GROUP.Synthesis_Materials.entries = ( KEYWORDS_ASSIGNMENT_ENTRY.The_Blossom_in_the_Storm, ) for group in ( - KEYWORDS_ASSIGNMENT_GROUP.Character_Materials, - KEYWORDS_ASSIGNMENT_GROUP.EXP_Materials_Credits, - KEYWORDS_ASSIGNMENT_GROUP.Synthesis_Materials, + KEYWORDS_ASSIGNMENT_GROUP.Character_Materials, + KEYWORDS_ASSIGNMENT_GROUP.EXP_Materials_Credits, + KEYWORDS_ASSIGNMENT_GROUP.Synthesis_Materials, ): for entry in group.entries: - entry.group = group \ No newline at end of file + entry.group = group diff --git a/tasks/dungeon/dungeon.py b/tasks/dungeon/dungeon.py index 4553e90d8..f0e2c54da 100644 --- a/tasks/dungeon/dungeon.py +++ b/tasks/dungeon/dungeon.py @@ -117,16 +117,7 @@ class Dungeon(DungeonUI, DungeonEvent, Combat): support_character=support_character) def run(self): - # Update daily quests - if self.config.stored.DailyActivity.is_expired(): - logger.info('Daily activity expired, call task to update') - self.config.task_call('DailyQuest') - self.config.task_stop() - if self.config.stored.DailyQuest.is_expired(): - logger.info('Daily quests expired, call task to update') - self.config.task_call('DailyQuest') - self.config.task_stop() - + self.config.update_daily_quests() self.called_daily_support = False self.achieved_daily_quest = False self.daily_quests = self.config.stored.DailyQuest.load_quests()