Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -172,6 +173,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -246,6 +248,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -326,6 +329,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -382,6 +386,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -456,6 +461,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -534,6 +540,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -571,6 +578,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -619,6 +627,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -679,6 +688,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -757,6 +767,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -835,6 +846,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -913,6 +925,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -991,6 +1004,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -1065,6 +1079,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -1142,6 +1157,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down Expand Up @@ -1190,6 +1206,7 @@
},
"StopCondition": {
"OilLimit": 1000,
"CoinLimit": 0,
"RunCount": 0,
"MapAchievement": "non_stop",
"StageIncrease": false,
Expand Down
31 changes: 31 additions & 0 deletions module/campaign/campaign_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions module/campaign/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
14 changes: 9 additions & 5 deletions module/coalition/coalition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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():
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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():
Expand Down
1 change: 1 addition & 0 deletions module/config/argument/argument.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Campaign:
AmbushEvade: true
StopCondition:
OilLimit: 1000
CoinLimit: 0
RunCount: 0
MapAchievement:
value: non_stop
Expand Down
1 change: 1 addition & 0 deletions module/config/config_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion module/config/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2755,4 +2759,4 @@
"ChooseFile": "Choose file"
}
}
}
}
6 changes: 5 additions & 1 deletion module/config/i18n/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2755,4 +2759,4 @@
"ChooseFile": "ファイルを選択してください"
}
}
}
}
6 changes: 5 additions & 1 deletion module/config/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,10 @@
"name": "石油低于 X 后推迟",
"help": "石油过低时推迟任务,石油充足后继续出击"
},
"CoinLimit": {
"name": "物资大于 X 后停止",
"help": "物资大于该数值后停止当前任务\n0 表示不限制物资"
},
"RunCount": {
"name": "出击次数大于 X 后停止",
"help": "每运行一次,次数减一,归零后停止任务\n0 表示不限制次数"
Expand Down Expand Up @@ -2755,4 +2759,4 @@
"ChooseFile": "选择文件"
}
}
}
}
6 changes: 5 additions & 1 deletion module/config/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,10 @@
"name": "石油低於 X 後推遲",
"help": "石油過低時推遲任務,石油充足後繼續出擊"
},
"CoinLimit": {
"name": "物資大於 X 後停止",
"help": "物資大於該數值後停止當前任務\n0 表示不限制物資"
},
"RunCount": {
"name": "出擊次數大於 X 後停止",
"help": "每執行一次,次數減一,歸零後停止任務\n0 表示不限制次數"
Expand Down Expand Up @@ -2755,4 +2759,4 @@
"ChooseFile": "選擇檔案"
}
}
}
}
4 changes: 4 additions & 0 deletions module/event_hospital/combat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions module/raid/raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down