Skip to content

Commit f8a8213

Browse files
committed
Add coin stop condition
1 parent 5f4f968 commit f8a8213

12 files changed

Lines changed: 91 additions & 9 deletions

File tree

config/template.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
},
9999
"StopCondition": {
100100
"OilLimit": 1000,
101+
"CoinLimit": 0,
101102
"RunCount": 0,
102103
"MapAchievement": "non_stop",
103104
"StageIncrease": false,
@@ -172,6 +173,7 @@
172173
},
173174
"StopCondition": {
174175
"OilLimit": 1000,
176+
"CoinLimit": 0,
175177
"RunCount": 0,
176178
"MapAchievement": "non_stop",
177179
"StageIncrease": false,
@@ -246,6 +248,7 @@
246248
},
247249
"StopCondition": {
248250
"OilLimit": 1000,
251+
"CoinLimit": 0,
249252
"RunCount": 0,
250253
"MapAchievement": "non_stop",
251254
"StageIncrease": false,
@@ -326,6 +329,7 @@
326329
},
327330
"StopCondition": {
328331
"OilLimit": 1000,
332+
"CoinLimit": 0,
329333
"RunCount": 0,
330334
"MapAchievement": "non_stop",
331335
"StageIncrease": false,
@@ -382,6 +386,7 @@
382386
},
383387
"StopCondition": {
384388
"OilLimit": 1000,
389+
"CoinLimit": 0,
385390
"RunCount": 0,
386391
"MapAchievement": "non_stop",
387392
"StageIncrease": false,
@@ -456,6 +461,7 @@
456461
},
457462
"StopCondition": {
458463
"OilLimit": 1000,
464+
"CoinLimit": 0,
459465
"RunCount": 0,
460466
"MapAchievement": "non_stop",
461467
"StageIncrease": false,
@@ -534,6 +540,7 @@
534540
},
535541
"StopCondition": {
536542
"OilLimit": 1000,
543+
"CoinLimit": 0,
537544
"RunCount": 0,
538545
"MapAchievement": "non_stop",
539546
"StageIncrease": false,
@@ -571,6 +578,7 @@
571578
},
572579
"StopCondition": {
573580
"OilLimit": 1000,
581+
"CoinLimit": 0,
574582
"RunCount": 0,
575583
"MapAchievement": "non_stop",
576584
"StageIncrease": false,
@@ -619,6 +627,7 @@
619627
},
620628
"StopCondition": {
621629
"OilLimit": 1000,
630+
"CoinLimit": 0,
622631
"RunCount": 0,
623632
"MapAchievement": "non_stop",
624633
"StageIncrease": false,
@@ -679,6 +688,7 @@
679688
},
680689
"StopCondition": {
681690
"OilLimit": 1000,
691+
"CoinLimit": 0,
682692
"RunCount": 0,
683693
"MapAchievement": "non_stop",
684694
"StageIncrease": false,
@@ -757,6 +767,7 @@
757767
},
758768
"StopCondition": {
759769
"OilLimit": 1000,
770+
"CoinLimit": 0,
760771
"RunCount": 0,
761772
"MapAchievement": "non_stop",
762773
"StageIncrease": false,
@@ -835,6 +846,7 @@
835846
},
836847
"StopCondition": {
837848
"OilLimit": 1000,
849+
"CoinLimit": 0,
838850
"RunCount": 0,
839851
"MapAchievement": "non_stop",
840852
"StageIncrease": false,
@@ -913,6 +925,7 @@
913925
},
914926
"StopCondition": {
915927
"OilLimit": 1000,
928+
"CoinLimit": 0,
916929
"RunCount": 0,
917930
"MapAchievement": "non_stop",
918931
"StageIncrease": false,
@@ -991,6 +1004,7 @@
9911004
},
9921005
"StopCondition": {
9931006
"OilLimit": 1000,
1007+
"CoinLimit": 0,
9941008
"RunCount": 0,
9951009
"MapAchievement": "non_stop",
9961010
"StageIncrease": false,
@@ -1065,6 +1079,7 @@
10651079
},
10661080
"StopCondition": {
10671081
"OilLimit": 1000,
1082+
"CoinLimit": 0,
10681083
"RunCount": 0,
10691084
"MapAchievement": "non_stop",
10701085
"StageIncrease": false,
@@ -1142,6 +1157,7 @@
11421157
},
11431158
"StopCondition": {
11441159
"OilLimit": 1000,
1160+
"CoinLimit": 0,
11451161
"RunCount": 0,
11461162
"MapAchievement": "non_stop",
11471163
"StageIncrease": false,
@@ -1190,6 +1206,7 @@
11901206
},
11911207
"StopCondition": {
11921208
"OilLimit": 1000,
1209+
"CoinLimit": 0,
11931210
"RunCount": 0,
11941211
"MapAchievement": "non_stop",
11951212
"StageIncrease": false,

module/campaign/campaign_event.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from module.config.config_updater import COALITIONS, EVENTS, GEMS_FARMINGS, HOSPITAL, MARITIME_ESCORTS, RAIDS
66
from module.config.utils import DEFAULT_TIME
77
from module.logger import logger
8+
from module.notify import handle_notify
89
from module.ui.assets import CAMPAIGN_MENU_NO_EVENT
910
from module.ui.page import page_campaign_menu, page_coalition, page_event, page_sp
1011
from module.war_archives.assets import WAR_ARCHIVES_CAMPAIGN_CHECK
@@ -75,6 +76,36 @@ def event_pt_limit_triggered(self):
7576
else:
7677
return False
7778

79+
def coin_limit_triggered(self):
80+
"""
81+
Returns:
82+
bool: If coin amount is greater than StopCondition.CoinLimit
83+
"""
84+
limit = int(
85+
re.sub(r'[,.\'",。]', '', str(self.config.StopCondition_CoinLimit))
86+
)
87+
if limit <= 0:
88+
return False
89+
90+
coin = self.get_coin()
91+
if coin == 0:
92+
# Avoid wrong/zero OCR result
93+
logger.warning('Coin not found')
94+
return False
95+
96+
logger.attr('Coin_limit', f'{coin}/{limit}')
97+
if coin > limit:
98+
logger.hr(f'Reach coin limit: {limit}')
99+
self.config.Scheduler_Enable = False
100+
handle_notify(
101+
self.config.Error_OnePushConfig,
102+
title=f"Alas <{self.config.config_name}> campaign finished",
103+
content=f"<{self.config.config_name}> {self.config.Campaign_Name} reached coin limit"
104+
)
105+
return True
106+
else:
107+
return False
108+
78109
def event_time_limit_triggered(self):
79110
"""
80111
Returns:

module/campaign/run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ def triggered_stop_condition(self, oil_check=True):
9898
logger.hr('Triggered stop condition: Oil limit')
9999
self.config.task_delay(minute=(120, 240))
100100
return True
101+
# Coin limit
102+
if oil_check and self.coin_limit_triggered():
103+
logger.hr('Triggered stop condition: Coin limit')
104+
return True
101105
# Auto search oil limit
102106
if self.campaign.auto_search_oil_limit_triggered:
103107
logger.hr('Triggered stop condition: Auto search oil limit')

module/coalition/coalition.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _coalition_has_oil_icon(self):
8585
return False
8686
return True
8787

88-
def triggered_stop_condition(self, oil_check=False, pt_check=False):
88+
def triggered_stop_condition(self, oil_check=False, pt_check=False, coin_check=False):
8989
"""
9090
Returns:
9191
bool: If triggered a stop condition.
@@ -107,6 +107,10 @@ def triggered_stop_condition(self, oil_check=False, pt_check=False):
107107
if self.event_pt_limit_triggered():
108108
logger.hr('Triggered stop condition: Event PT limit')
109109
return True
110+
# Coin limit
111+
if coin_check and self.coin_limit_triggered():
112+
logger.hr('Triggered stop condition: Coin limit')
113+
return True
110114
# TaskBalancer
111115
if self.run_count >= 1:
112116
if self.config.TaskBalancer_Enable and self.triggered_task_balancer():
@@ -147,7 +151,7 @@ def coalition_execute_once(self, event, stage, fleet):
147151
self.coalition_map_exit(event)
148152
raise
149153

150-
if self._coalition_has_oil_icon and self.triggered_stop_condition(oil_check=True):
154+
if self._coalition_has_oil_icon and self.triggered_stop_condition(oil_check=True, coin_check=True):
151155
self.coalition_map_exit(event)
152156
raise ScriptEnd
153157

@@ -189,7 +193,7 @@ def run(self, event='', mode='', fleet='', total=0):
189193
# UI switches
190194
if not self._coalition_has_oil_icon:
191195
self.ui_goto(page_campaign_menu)
192-
if self.triggered_stop_condition(oil_check=True):
196+
if self.triggered_stop_condition(oil_check=True, coin_check=True):
193197
break
194198
self.device.stuck_record_clear()
195199
self.device.click_record_clear()
@@ -198,7 +202,7 @@ def run(self, event='', mode='', fleet='', total=0):
198202
self.coalition_ensure_mode(event, 'battle')
199203

200204
# End
201-
if self.triggered_stop_condition(pt_check=True):
205+
if self.triggered_stop_condition(pt_check=True, coin_check=True):
202206
break
203207

204208
# Run
@@ -216,7 +220,7 @@ def run(self, event='', mode='', fleet='', total=0):
216220
if self.config.StopCondition_RunCount:
217221
self.config.StopCondition_RunCount -= 1
218222
# End
219-
if self.triggered_stop_condition(pt_check=True):
223+
if self.triggered_stop_condition(pt_check=True, coin_check=True):
220224
break
221225
# Scheduler
222226
if self.config.task_switched():

module/config/argument/argument.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ Campaign:
160160
AmbushEvade: true
161161
StopCondition:
162162
OilLimit: 1000
163+
CoinLimit: 0
163164
RunCount: 0
164165
MapAchievement:
165166
value: non_stop

module/config/config_generated.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class GeneratedConfig:
8484

8585
# Group `StopCondition`
8686
StopCondition_OilLimit = 1000
87+
StopCondition_CoinLimit = 0
8788
StopCondition_RunCount = 0
8889
StopCondition_MapAchievement = 'non_stop' # non_stop, 100_percent_clear, map_3_stars, threat_safe, threat_safe_without_3_stars
8990
StopCondition_StageIncrease = False

module/config/i18n/en-US.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@
862862
"name": "Keep Oil Above X",
863863
"help": "Delay current task if oil is found to be below this number"
864864
},
865+
"CoinLimit": {
866+
"name": "Stop When Coins Are Above X",
867+
"help": "Stop the current task when coins are found to be above this number\n0 means no coin limit"
868+
},
865869
"RunCount": {
866870
"name": "Run Level X Time(s)",
867871
"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 @@
27552759
"ChooseFile": "Choose file"
27562760
}
27572761
}
2758-
}
2762+
}

module/config/i18n/ja-JP.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@
862862
"name": "StopCondition.OilLimit.name",
863863
"help": "StopCondition.OilLimit.help"
864864
},
865+
"CoinLimit": {
866+
"name": "StopCondition.CoinLimit.name",
867+
"help": "StopCondition.CoinLimit.help"
868+
},
865869
"RunCount": {
866870
"name": "StopCondition.RunCount.name",
867871
"help": "StopCondition.RunCount.help"
@@ -2755,4 +2759,4 @@
27552759
"ChooseFile": "ファイルを選択してください"
27562760
}
27572761
}
2758-
}
2762+
}

module/config/i18n/zh-CN.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@
862862
"name": "石油低于 X 后推迟",
863863
"help": "石油过低时推迟任务,石油充足后继续出击"
864864
},
865+
"CoinLimit": {
866+
"name": "物资大于 X 后停止",
867+
"help": "物资大于该数值后停止当前任务\n0 表示不限制物资"
868+
},
865869
"RunCount": {
866870
"name": "出击次数大于 X 后停止",
867871
"help": "每运行一次,次数减一,归零后停止任务\n0 表示不限制次数"
@@ -2755,4 +2759,4 @@
27552759
"ChooseFile": "选择文件"
27562760
}
27572761
}
2758-
}
2762+
}

module/config/i18n/zh-TW.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@
862862
"name": "石油低於 X 後推遲",
863863
"help": "石油過低時推遲任務,石油充足後繼續出擊"
864864
},
865+
"CoinLimit": {
866+
"name": "物資大於 X 後停止",
867+
"help": "物資大於該數值後停止當前任務\n0 表示不限制物資"
868+
},
865869
"RunCount": {
866870
"name": "出擊次數大於 X 後停止",
867871
"help": "每執行一次,次數減一,歸零後停止任務\n0 表示不限制次數"
@@ -2755,4 +2759,4 @@
27552759
"ChooseFile": "選擇檔案"
27562760
}
27572761
}
2758-
}
2762+
}

0 commit comments

Comments
 (0)