From 8f1707a5c7f70a27ec9f8fd76a03c1f6caefbfed Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 27 May 2024 23:09:46 +0800 Subject: [PATCH] Add: Planning daily quests to do normal quests less often --- tasks/assignment/assignment.py | 10 +++++- tasks/daily/daily_quest.py | 66 +++++++++++++++++++++++++++++++++- tasks/dungeon/dungeon.py | 8 ++++- 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/tasks/assignment/assignment.py b/tasks/assignment/assignment.py index c75e157d8..8a76ded7d 100644 --- a/tasks/assignment/assignment.py +++ b/tasks/assignment/assignment.py @@ -1,5 +1,7 @@ -from datetime import datetime +from datetime import datetime, timedelta +from module.config.stored.classes import now +from module.config.utils import get_server_next_update from module.logger import logger from tasks.assignment.claim import AssignmentClaim from tasks.assignment.keywords import (KEYWORDS_ASSIGNMENT_GROUP, @@ -76,6 +78,12 @@ class Assignment(AssignmentClaim, SynthesizeUI): # ValueError: min() arg is an empty sequence logger.error('Empty dispatched list, delay 2 hours instead') self.config.task_delay(minute=120) + # Check future daily + if now() > get_server_next_update(self.config.Scheduler_ServerUpdate) - timedelta(minutes=110) \ + and KEYWORDS_DAILY_QUEST.Dispatch_1_assignments in quests: + logger.error( + "Assigment is scheduled tomorrow but today's assignment daily haven't been finished yet") + self.config.task_call('DailyQuest') def _check_inlist(self, assignments: list[AssignmentEntry], duration: int): """ diff --git a/tasks/daily/daily_quest.py b/tasks/daily/daily_quest.py index d10953647..c186101c9 100644 --- a/tasks/daily/daily_quest.py +++ b/tasks/daily/daily_quest.py @@ -1,8 +1,11 @@ +from datetime import timedelta + import cv2 import numpy as np from module.base.timer import Timer from module.base.utils import crop +from module.config.utils import DEFAULT_TIME, get_server_next_update from module.logger import logger from module.ocr.ocr import Ocr, OcrResultButton from module.ocr.utils import split_and_pair_buttons @@ -165,6 +168,7 @@ class DailyQuestUI(DungeonUI, RouteLoader): """ self.claimed_point_reward will be set if claimed any point reward """ + def get_active(): for b in [ ACTIVE_POINTS_1_UNLOCK, @@ -244,7 +248,7 @@ class DailyQuestUI(DungeonUI, RouteLoader): int: Number of quests done """ logger.hr('Recognize quests', level=1) - quests = self.daily_quests_recognition() + quests = self.config.stored.DailyQuest.load_quests() done = 0 logger.hr('Do quests', level=1) @@ -313,6 +317,62 @@ class DailyQuestUI(DungeonUI, RouteLoader): return done + def check_future_achieve(self): + """ + Returns: + bool: True if daily activity will full, skip doing normal quests + False if daily activity will not full, do normal quests + """ + point = self.config.stored.DailyActivity.value + if point >= self.config.stored.DailyActivity.FIXED_TOTAL: + logger.warning('DailyActivity full, no need to check future') + return True + quests = self.config.stored.DailyQuest.load_quests() + if not len(quests): + logger.warning('DailyQuest empty, cannot check future') + return True + + # Get task schedule + assignment = self.config.cross_get('Assignment.Scheduler.NextRun', default=DEFAULT_TIME) + dungeon = self.config.cross_get('Dungeon.Scheduler.NextRun', default=DEFAULT_TIME) + reset = get_server_next_update(self.config.Scheduler_ServerUpdate) + logger.info(f'Assignment next run: {assignment}') + logger.info(f'Dungeon next run: {dungeon}') + logger.info(f'Daily reset: {reset}') + + # Calculate quests to be done in the future + future = 0 + if KEYWORDS_DAILY_QUEST.Obtain_victory_in_combat_with_Support_Characters_1_times in quests: + # 10min in advance to do quests + if dungeon < reset - timedelta(minutes=10): + logger.info('Daily support can be achieved in the future') + future += 200 + else: + logger.info('Daily support cannot achieved, dungeon task is scheduled tomorrow') + if KEYWORDS_DAILY_QUEST.Consume_120_Trailblaze_Power in quests: + # 12h10min in advance, waiting for stamina + if dungeon < reset - timedelta(hours=12, minutes=10): + logger.info('Stamina consume can be achieved in the future') + future += 200 + else: + logger.info('Stamina consume cannot achieved, dungeon task is scheduled tomorrow') + if KEYWORDS_DAILY_QUEST.Dispatch_1_assignments in quests: + # 10min in advance to do quests + if assignment < reset - timedelta(minutes=10): + logger.info('Assignment can be achieved in the future') + future += 100 + else: + logger.info('Assignment cannot achieved, assignment task is scheduled tomorrow') + + # Check + logger.attr('Future daily activity', future) + if point + future >= self.config.stored.DailyActivity.FIXED_TOTAL: + logger.info('Daily activity will full, skip doing normal quests') + return True + else: + logger.info('Daily activity will not full, do normal quests') + return False + def run(self): self.config.update_battle_pass_quests() self.claimed_point_reward = False @@ -322,6 +382,10 @@ class DailyQuestUI(DungeonUI, RouteLoader): got = self.get_daily_rewards() if got: break + self.daily_quests_recognition() + future = self.check_future_achieve() + if future: + break done = self.do_daily_quests() if not done: logger.info('No more quests able to do') diff --git a/tasks/dungeon/dungeon.py b/tasks/dungeon/dungeon.py index dd4455971..db2c86851 100644 --- a/tasks/dungeon/dungeon.py +++ b/tasks/dungeon/dungeon.py @@ -133,7 +133,7 @@ class Dungeon(DungeonStamina, DungeonEvent, Combat): # 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: + if KEYWORDS_DAILY_QUEST.Obtain_victory_in_combat_with_Support_Characters_1_times in self.daily_quests: logger.info('Achieve daily quest Obtain_victory_in_combat_with_Support_Characters_1_times') self.achieved_daily_quest = True # Stamina quest @@ -305,6 +305,12 @@ class Dungeon(DungeonStamina, DungeonEvent, Combat): # Check daily if self.achieved_daily_quest: self.config.task_call('DailyQuest') + else: + # Check future daily + if KEYWORDS_DAILY_QUEST.Obtain_victory_in_combat_with_Support_Characters_1_times in self.daily_quests: + logger.error("Dungeon ran but support daily haven't been finished yet") + self.config.task_call('DailyQuest') + # Delay tasks self.dungeon_stamina_delay(dungeon)