From 45633563557f1e9de5c0206b0d1f28b51cc520b3 Mon Sep 17 00:00:00 2001 From: Air111 <1796389814@qq.com> Date: Sat, 13 Jul 2024 18:17:09 +0800 Subject: [PATCH] Opt: reduce config write frequency --- module/campaign/run.py | 113 ++++++++++++++-------------- module/coalition/coalition.py | 49 ++++++------ module/combat/auto_search_combat.py | 5 +- module/raid/raid.py | 5 +- 4 files changed, 88 insertions(+), 84 deletions(-) diff --git a/module/campaign/run.py b/module/campaign/run.py index 6bc83142b8..35d1424953 100644 --- a/module/campaign/run.py +++ b/module/campaign/run.py @@ -72,67 +72,68 @@ def triggered_stop_condition(self, oil_check=True): Returns: bool: If triggered a stop condition. """ - # Run count limit - if self.run_limit and self.config.StopCondition_RunCount <= 0: - logger.hr('Triggered stop condition: Run count') - self.config.StopCondition_RunCount = 0 - self.config.Scheduler_Enable = False - handle_notify( - self.config.Error_OnePushConfig, - title=f"Alas <{self.config.config_name}> campaign finished", - content=f"<{self.config.config_name}> {self.name} reached run count limit" - ) - return True - # Lv120 limit - if self.config.StopCondition_ReachLevel and self.campaign.config.LV_TRIGGERED: - logger.hr(f'Triggered stop condition: Reach level {self.config.StopCondition_ReachLevel}') - self.config.Scheduler_Enable = False - handle_notify( - self.config.Error_OnePushConfig, - title=f"Alas <{self.config.config_name}> campaign finished", - content=f"<{self.config.config_name}> {self.name} reached level limit" - ) - return True - # Oil limit - if oil_check: - self.status_get_gems() - self.get_coin() - if self.get_oil() < max(500, self.config.StopCondition_OilLimit): - logger.hr('Triggered stop condition: Oil limit') + with self.config.multi_set(): + # Run count limit + if self.run_limit and self.config.StopCondition_RunCount <= 0: + logger.hr('Triggered stop condition: Run count') + self.config.StopCondition_RunCount = 0 + self.config.Scheduler_Enable = False + handle_notify( + self.config.Error_OnePushConfig, + title=f"Alas <{self.config.config_name}> campaign finished", + content=f"<{self.config.config_name}> {self.name} reached run count limit" + ) + return True + # Lv120 limit + if self.config.StopCondition_ReachLevel and self.campaign.config.LV_TRIGGERED: + logger.hr(f'Triggered stop condition: Reach level {self.config.StopCondition_ReachLevel}') + self.config.Scheduler_Enable = False + handle_notify( + self.config.Error_OnePushConfig, + title=f"Alas <{self.config.config_name}> campaign finished", + content=f"<{self.config.config_name}> {self.name} reached level limit" + ) + return True + # Oil limit + if oil_check: + self.status_get_gems() + self.get_coin() + if self.get_oil() < max(500, self.config.StopCondition_OilLimit): + logger.hr('Triggered stop condition: Oil limit') + self.config.task_delay(minute=(120, 240)) + return True + # Auto search oil limit + if self.campaign.auto_search_oil_limit_triggered: + logger.hr('Triggered stop condition: Auto search oil limit') self.config.task_delay(minute=(120, 240)) return True - # Auto search oil limit - if self.campaign.auto_search_oil_limit_triggered: - logger.hr('Triggered stop condition: Auto search oil limit') - self.config.task_delay(minute=(120, 240)) - return True - # If Get a New Ship - if self.config.StopCondition_GetNewShip and self.campaign.config.GET_SHIP_TRIGGERED: - logger.hr('Triggered stop condition: Get new ship') - self.config.Scheduler_Enable = False - handle_notify( - self.config.Error_OnePushConfig, - title=f"Alas <{self.config.config_name}> campaign finished", - content=f"<{self.config.config_name}> {self.name} got new ship" - ) - return True - # Event limit - if oil_check and self.campaign.event_pt_limit_triggered(): - logger.hr('Triggered stop condition: Event PT limit') - return True - # Auto search TaskBalancer - if self.config.TaskBalancer_Enable and self.campaign.auto_search_coin_limit_triggered: - logger.hr('Triggered stop condition: Auto search coin limit') - self.handle_task_balancer() - return True - # TaskBalancer - if oil_check and self.run_count >= 1: - if self.config.TaskBalancer_Enable and self.triggered_task_balancer(): - logger.hr('Triggered stop condition: Coin limit') + # If Get a New Ship + if self.config.StopCondition_GetNewShip and self.campaign.config.GET_SHIP_TRIGGERED: + logger.hr('Triggered stop condition: Get new ship') + self.config.Scheduler_Enable = False + handle_notify( + self.config.Error_OnePushConfig, + title=f"Alas <{self.config.config_name}> campaign finished", + content=f"<{self.config.config_name}> {self.name} got new ship" + ) + return True + # Event limit + if oil_check and self.campaign.event_pt_limit_triggered(): + logger.hr('Triggered stop condition: Event PT limit') + return True + # Auto search TaskBalancer + if self.config.TaskBalancer_Enable and self.campaign.auto_search_coin_limit_triggered: + logger.hr('Triggered stop condition: Auto search coin limit') self.handle_task_balancer() return True + # TaskBalancer + if oil_check and self.run_count >= 1: + if self.config.TaskBalancer_Enable and self.triggered_task_balancer(): + logger.hr('Triggered stop condition: Coin limit') + self.handle_task_balancer() + return True - return False + return False def _triggered_app_restart(self): """ diff --git a/module/coalition/coalition.py b/module/coalition/coalition.py index f36c537dd5..32d5915456 100644 --- a/module/coalition/coalition.py +++ b/module/coalition/coalition.py @@ -49,31 +49,32 @@ def triggered_stop_condition(self, oil_check=False, pt_check=False): Returns: bool: If triggered a stop condition. """ - # Run count limit - if self.run_limit and self.config.StopCondition_RunCount <= 0: - logger.hr('Triggered stop condition: Run count') - self.config.StopCondition_RunCount = 0 - self.config.Scheduler_Enable = False - return True - # Oil limit - if oil_check: - if self.get_oil() < max(500, self.config.StopCondition_OilLimit): - logger.hr('Triggered stop condition: Oil limit') - self.config.task_delay(minute=(120, 240)) + with self.config.multi_set(): + # Run count limit + if self.run_limit and self.config.StopCondition_RunCount <= 0: + logger.hr('Triggered stop condition: Run count') + self.config.StopCondition_RunCount = 0 + self.config.Scheduler_Enable = False return True - # Event limit - if pt_check: - if self.event_pt_limit_triggered(): - logger.hr('Triggered stop condition: Event PT limit') - return True - # TaskBalancer - if self.run_count >= 1: - if self.config.TaskBalancer_Enable and self.triggered_task_balancer(): - logger.hr('Triggered stop condition: Coin limit') - self.handle_task_balancer() - return True - - return False + # Oil limit + if oil_check: + if self.get_oil() < max(500, self.config.StopCondition_OilLimit): + logger.hr('Triggered stop condition: Oil limit') + self.config.task_delay(minute=(120, 240)) + return True + # Event limit + if pt_check: + if self.event_pt_limit_triggered(): + logger.hr('Triggered stop condition: Event PT limit') + return True + # TaskBalancer + if self.run_count >= 1: + if self.config.TaskBalancer_Enable and self.triggered_task_balancer(): + logger.hr('Triggered stop condition: Coin limit') + self.handle_task_balancer() + return True + + return False def coalition_execute_once(self, event, stage, fleet): """ diff --git a/module/combat/auto_search_combat.py b/module/combat/auto_search_combat.py index 3c95c22572..5b221c2c44 100644 --- a/module/combat/auto_search_combat.py +++ b/module/combat/auto_search_combat.py @@ -185,8 +185,9 @@ def auto_search_moving(self, skip_first_screenshot=True): if self.is_auto_search_running(): checked_fleet = self.auto_search_watch_fleet(checked_fleet) if not checked_oil or not checked_coin: - checked_oil = self.auto_search_watch_oil(checked_oil) - checked_coin = self.auto_search_watch_coin(checked_coin) + with self.config.multi_set(): + checked_oil = self.auto_search_watch_oil(checked_oil) + checked_coin = self.auto_search_watch_coin(checked_coin) if self.handle_retirement(): self.map_offensive_auto_search() continue diff --git a/module/raid/raid.py b/module/raid/raid.py index bf9c18944d..c388a32104 100644 --- a/module/raid/raid.py +++ b/module/raid/raid.py @@ -222,8 +222,9 @@ def check_coin(): if self.appear(BATTLE_PREPARATION, offset=(30, 20)): if self.handle_combat_automation_set(auto=auto == 'combat_auto'): continue - check_oil() - check_coin() + with self.config.multi_set(): + check_oil() + check_coin() if self.handle_raid_ticket_use(): continue if self.handle_retirement():