Add coin stop condition

This commit is contained in:
kotoricon 2026-05-02 21:04:19 +08:00
parent 5f4f968c25
commit f8a821344c
12 changed files with 91 additions and 9 deletions

View File

@ -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,

View File

@ -5,6 +5,7 @@ from module.campaign.campaign_status import CampaignStatus
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 @@ class CampaignEvent(CampaignStatus):
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:

View File

@ -98,6 +98,10 @@ class CampaignRun(CampaignEvent):
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')

View File

@ -85,7 +85,7 @@ class Coalition(CoalitionCombat, CampaignEvent):
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 @@ class Coalition(CoalitionCombat, CampaignEvent):
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 @@ class Coalition(CoalitionCombat, CampaignEvent):
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 @@ class Coalition(CoalitionCombat, CampaignEvent):
# 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 @@ class Coalition(CoalitionCombat, CampaignEvent):
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 @@ class Coalition(CoalitionCombat, CampaignEvent):
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():

View File

@ -160,6 +160,7 @@ Campaign:
AmbushEvade: true
StopCondition:
OilLimit: 1000
CoinLimit: 0
RunCount: 0
MapAchievement:
value: non_stop

View File

@ -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

View File

@ -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"
}
}
}
}

View File

@ -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": "ファイルを選択してください"
}
}
}
}

View File

@ -862,6 +862,10 @@
"name": "石油低于 X 后推迟",
"help": "石油过低时推迟任务,石油充足后继续出击"
},
"CoinLimit": {
"name": "物资大于 X 后停止",
"help": "物资大于该数值后停止当前任务\n0 表示不限制物资"
},
"RunCount": {
"name": "出击次数大于 X 后停止",
"help": "每运行一次,次数减一,归零后停止任务\n0 表示不限制次数"
@ -2755,4 +2759,4 @@
"ChooseFile": "选择文件"
}
}
}
}

View File

@ -862,6 +862,10 @@
"name": "石油低於 X 後推遲",
"help": "石油過低時推遲任務,石油充足後繼續出擊"
},
"CoinLimit": {
"name": "物資大於 X 後停止",
"help": "物資大於該數值後停止當前任務\n0 表示不限制物資"
},
"RunCount": {
"name": "出擊次數大於 X 後停止",
"help": "每執行一次,次數減一,歸零後停止任務\n0 表示不限制次數"
@ -2755,4 +2759,4 @@
"ChooseFile": "選擇檔案"
}
}
}
}

View File

@ -58,6 +58,10 @@ class HospitalCombat(Combat, HospitalUI, CampaignEvent):
@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()

View File

@ -231,6 +231,10 @@ class Raid(MapOperation, RaidCombat, CampaignEvent):
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():