From f8a821344c81ea0a56e9b513715c7255005a0ba8 Mon Sep 17 00:00:00 2001 From: kotoricon <8659834+kotoricon@users.noreply.github.com> Date: Sat, 2 May 2026 21:04:19 +0800 Subject: [PATCH] Add coin stop condition --- config/template.json | 17 +++++++++++++++ module/campaign/campaign_event.py | 31 ++++++++++++++++++++++++++++ module/campaign/run.py | 4 ++++ module/coalition/coalition.py | 14 ++++++++----- module/config/argument/argument.yaml | 1 + module/config/config_generated.py | 1 + module/config/i18n/en-US.json | 6 +++++- module/config/i18n/ja-JP.json | 6 +++++- module/config/i18n/zh-CN.json | 6 +++++- module/config/i18n/zh-TW.json | 6 +++++- module/event_hospital/combat.py | 4 ++++ module/raid/raid.py | 4 ++++ 12 files changed, 91 insertions(+), 9 deletions(-) diff --git a/config/template.json b/config/template.json index 8fd8a1558c..74cde4d03b 100644 --- a/config/template.json +++ b/config/template.json @@ -98,6 +98,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -172,6 +173,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -246,6 +248,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -326,6 +329,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -382,6 +386,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -456,6 +461,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -534,6 +540,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -571,6 +578,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -619,6 +627,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -679,6 +688,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -757,6 +767,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -835,6 +846,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -913,6 +925,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -991,6 +1004,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -1065,6 +1079,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -1142,6 +1157,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, @@ -1190,6 +1206,7 @@ }, "StopCondition": { "OilLimit": 1000, + "CoinLimit": 0, "RunCount": 0, "MapAchievement": "non_stop", "StageIncrease": false, diff --git a/module/campaign/campaign_event.py b/module/campaign/campaign_event.py index 541cb00a55..30399bb691 100644 --- a/module/campaign/campaign_event.py +++ b/module/campaign/campaign_event.py @@ -5,6 +5,7 @@ from module.config.config_updater import COALITIONS, EVENTS, GEMS_FARMINGS, HOSPITAL, MARITIME_ESCORTS, RAIDS from module.config.utils import DEFAULT_TIME from module.logger import logger +from module.notify import handle_notify from module.ui.assets import CAMPAIGN_MENU_NO_EVENT from module.ui.page import page_campaign_menu, page_coalition, page_event, page_sp from module.war_archives.assets import WAR_ARCHIVES_CAMPAIGN_CHECK @@ -75,6 +76,36 @@ def event_pt_limit_triggered(self): else: return False + def coin_limit_triggered(self): + """ + Returns: + bool: If coin amount is greater than StopCondition.CoinLimit + """ + limit = int( + re.sub(r'[,.\'",。]', '', str(self.config.StopCondition_CoinLimit)) + ) + if limit <= 0: + return False + + coin = self.get_coin() + if coin == 0: + # Avoid wrong/zero OCR result + logger.warning('Coin not found') + return False + + logger.attr('Coin_limit', f'{coin}/{limit}') + if coin > limit: + logger.hr(f'Reach coin limit: {limit}') + 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.config.Campaign_Name} reached coin limit" + ) + return True + else: + return False + def event_time_limit_triggered(self): """ Returns: diff --git a/module/campaign/run.py b/module/campaign/run.py index abaa5b5cbd..bdfd3fd197 100644 --- a/module/campaign/run.py +++ b/module/campaign/run.py @@ -98,6 +98,10 @@ def triggered_stop_condition(self, oil_check=True): logger.hr('Triggered stop condition: Oil limit') self.config.task_delay(minute=(120, 240)) return True + # Coin limit + if oil_check and self.coin_limit_triggered(): + logger.hr('Triggered stop condition: Coin limit') + return True # Auto search oil limit if self.campaign.auto_search_oil_limit_triggered: logger.hr('Triggered stop condition: Auto search oil limit') diff --git a/module/coalition/coalition.py b/module/coalition/coalition.py index eab449e3da..a61367d272 100644 --- a/module/coalition/coalition.py +++ b/module/coalition/coalition.py @@ -85,7 +85,7 @@ def _coalition_has_oil_icon(self): return False return True - def triggered_stop_condition(self, oil_check=False, pt_check=False): + def triggered_stop_condition(self, oil_check=False, pt_check=False, coin_check=False): """ Returns: bool: If triggered a stop condition. @@ -107,6 +107,10 @@ def triggered_stop_condition(self, oil_check=False, pt_check=False): if self.event_pt_limit_triggered(): logger.hr('Triggered stop condition: Event PT limit') return True + # Coin limit + if coin_check and self.coin_limit_triggered(): + logger.hr('Triggered stop condition: Coin limit') + return True # TaskBalancer if self.run_count >= 1: if self.config.TaskBalancer_Enable and self.triggered_task_balancer(): @@ -147,7 +151,7 @@ def coalition_execute_once(self, event, stage, fleet): self.coalition_map_exit(event) raise - if self._coalition_has_oil_icon and self.triggered_stop_condition(oil_check=True): + if self._coalition_has_oil_icon and self.triggered_stop_condition(oil_check=True, coin_check=True): self.coalition_map_exit(event) raise ScriptEnd @@ -189,7 +193,7 @@ def run(self, event='', mode='', fleet='', total=0): # UI switches if not self._coalition_has_oil_icon: self.ui_goto(page_campaign_menu) - if self.triggered_stop_condition(oil_check=True): + if self.triggered_stop_condition(oil_check=True, coin_check=True): break self.device.stuck_record_clear() self.device.click_record_clear() @@ -198,7 +202,7 @@ def run(self, event='', mode='', fleet='', total=0): self.coalition_ensure_mode(event, 'battle') # End - if self.triggered_stop_condition(pt_check=True): + if self.triggered_stop_condition(pt_check=True, coin_check=True): break # Run @@ -216,7 +220,7 @@ def run(self, event='', mode='', fleet='', total=0): if self.config.StopCondition_RunCount: self.config.StopCondition_RunCount -= 1 # End - if self.triggered_stop_condition(pt_check=True): + if self.triggered_stop_condition(pt_check=True, coin_check=True): break # Scheduler if self.config.task_switched(): diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index 72e3302d52..933ea84f37 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -160,6 +160,7 @@ Campaign: AmbushEvade: true StopCondition: OilLimit: 1000 + CoinLimit: 0 RunCount: 0 MapAchievement: value: non_stop diff --git a/module/config/config_generated.py b/module/config/config_generated.py index 22e0a53142..5956b2d63a 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -84,6 +84,7 @@ class GeneratedConfig: # Group `StopCondition` StopCondition_OilLimit = 1000 + StopCondition_CoinLimit = 0 StopCondition_RunCount = 0 StopCondition_MapAchievement = 'non_stop' # non_stop, 100_percent_clear, map_3_stars, threat_safe, threat_safe_without_3_stars StopCondition_StageIncrease = False diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index af6eb61c3e..8145d435b9 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -862,6 +862,10 @@ "name": "Keep Oil Above X", "help": "Delay current task if oil is found to be below this number" }, + "CoinLimit": { + "name": "Stop When Coins Are Above X", + "help": "Stop the current task when coins are found to be above this number\n0 means no coin limit" + }, "RunCount": { "name": "Run Level X Time(s)", "help": "Automatically decreases by 1 for every completion and stops the current task upon reaching zero; saving as 0 implies unlimited runs until a different stop condition is met" @@ -2755,4 +2759,4 @@ "ChooseFile": "Choose file" } } -} \ No newline at end of file +} diff --git a/module/config/i18n/ja-JP.json b/module/config/i18n/ja-JP.json index c7b68226d1..1cc2712369 100644 --- a/module/config/i18n/ja-JP.json +++ b/module/config/i18n/ja-JP.json @@ -862,6 +862,10 @@ "name": "StopCondition.OilLimit.name", "help": "StopCondition.OilLimit.help" }, + "CoinLimit": { + "name": "StopCondition.CoinLimit.name", + "help": "StopCondition.CoinLimit.help" + }, "RunCount": { "name": "StopCondition.RunCount.name", "help": "StopCondition.RunCount.help" @@ -2755,4 +2759,4 @@ "ChooseFile": "ファイルを選択してください" } } -} \ No newline at end of file +} diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index c48b283dd2..0da26e983c 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -862,6 +862,10 @@ "name": "石油低于 X 后推迟", "help": "石油过低时推迟任务,石油充足后继续出击" }, + "CoinLimit": { + "name": "物资大于 X 后停止", + "help": "物资大于该数值后停止当前任务\n0 表示不限制物资" + }, "RunCount": { "name": "出击次数大于 X 后停止", "help": "每运行一次,次数减一,归零后停止任务\n0 表示不限制次数" @@ -2755,4 +2759,4 @@ "ChooseFile": "选择文件" } } -} \ No newline at end of file +} diff --git a/module/config/i18n/zh-TW.json b/module/config/i18n/zh-TW.json index 761ad94eed..ac29b3cdab 100644 --- a/module/config/i18n/zh-TW.json +++ b/module/config/i18n/zh-TW.json @@ -862,6 +862,10 @@ "name": "石油低於 X 後推遲", "help": "石油過低時推遲任務,石油充足後繼續出擊" }, + "CoinLimit": { + "name": "物資大於 X 後停止", + "help": "物資大於該數值後停止當前任務\n0 表示不限制物資" + }, "RunCount": { "name": "出擊次數大於 X 後停止", "help": "每執行一次,次數減一,歸零後停止任務\n0 表示不限制次數" @@ -2755,4 +2759,4 @@ "ChooseFile": "選擇檔案" } } -} \ No newline at end of file +} diff --git a/module/event_hospital/combat.py b/module/event_hospital/combat.py index 370412ca5f..f0a3963405 100644 --- a/module/event_hospital/combat.py +++ b/module/event_hospital/combat.py @@ -58,6 +58,10 @@ def check_oil(): @run_once def check_coin(): + if self.coin_limit_triggered(): + logger.hr('Triggered stop condition: Coin limit') + self.config.task_stop() + return True if self.config.TaskBalancer_Enable and self.triggered_task_balancer(): logger.hr('Triggered stop condition: Coin limit') self.handle_task_balancer() diff --git a/module/raid/raid.py b/module/raid/raid.py index 2d160eb8ab..9a5cfaa3ec 100644 --- a/module/raid/raid.py +++ b/module/raid/raid.py @@ -231,6 +231,10 @@ def triggered_stop_condition(self, oil_check=False, pt_check=False, coin_check=F if self.event_pt_limit_triggered(): logger.hr('Triggered stop condition: Event PT limit') return True + # Coin limit + if coin_check and self.coin_limit_triggered(): + logger.hr('Triggered stop condition: Coin limit') + return True # TaskBalancer if coin_check: if self.config.TaskBalancer_Enable and self.triggered_task_balancer():