-
Notifications
You must be signed in to change notification settings - Fork 846
/
combat.py
271 lines (233 loc) · 8.84 KB
/
combat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
from module.combat.assets import *
from module.combat.combat import Combat as Combat_
from module.logger import logger
from module.os_combat.assets import *
from module.os_handler.assets import *
from module.os_handler.map_event import MapEventHandler
class ContinuousCombat(Exception):
pass
class Combat(Combat_, MapEventHandler):
def combat_appear(self):
"""
Returns:
bool: If enter combat.
"""
if not self.is_in_map():
if self.is_combat_loading():
return True
if self.appear(BATTLE_PREPARATION):
return True
if self.appear(SIREN_PREPARATION, offset=(20, 20)):
return True
if self.appear(BATTLE_PREPARATION_WITH_OVERLAY) and self.handle_combat_automation_confirm():
return True
return False
def combat_preparation(self, balance_hp=False, emotion_reduce=False, auto='combat_auto', fleet_index=1):
"""
Args:
balance_hp (bool):
emotion_reduce (bool):
auto (str):
fleet_index (int):
"""
logger.info('Combat preparation.')
skip_first_screenshot = True
# if emotion_reduce:
# self.emotion.wait(fleet=fleet_index)
# if balance_hp:
# self.hp_balance()
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if self.appear(BATTLE_PREPARATION):
if self.handle_combat_automation_set(auto=auto == 'combat_auto'):
continue
if self.handle_retirement():
continue
# if self.handle_combat_low_emotion():
# continue
# if balance_hp and self.handle_emergency_repair_use():
# continue
if self.appear_then_click(BATTLE_PREPARATION, interval=2):
continue
if self.appear_then_click(SIREN_PREPARATION, offset=(20, 20), interval=2):
continue
if self.handle_popup_confirm('ENHANCED_ENEMY'):
continue
if self.handle_combat_automation_confirm():
continue
if self.handle_story_skip():
continue
# End
if self.is_combat_executing():
# if emotion_reduce:
# self.emotion.reduce(fleet_index)
break
def handle_exp_info(self):
if self.is_combat_executing():
return False
if self.__os_combat_drop:
sleep = (1.5, 2)
else:
sleep = (0.25, 0.5)
if self.appear_then_click(EXP_INFO_S):
self.device.sleep(sleep)
return True
if self.appear_then_click(EXP_INFO_A):
self.device.sleep(sleep)
return True
if self.appear_then_click(EXP_INFO_B):
self.device.sleep(sleep)
return True
if self.appear_then_click(EXP_INFO_C):
self.device.sleep(sleep)
return True
if self.appear_then_click(EXP_INFO_D):
self.device.sleep(sleep)
return True
return False
def handle_get_items(self, drop=None):
"""
Click CLICK_SAFE_AREA instead of button itself.
Args:
drop (DropImage):
Returns:
bool:
"""
if self.appear(GET_ITEMS_1, offset=5, interval=self.battle_status_click_interval):
if drop:
drop.handle_add(self, before=2)
self.device.click(CLICK_SAFE_AREA)
self.interval_reset(BATTLE_STATUS_S)
self.interval_reset(BATTLE_STATUS_A)
self.interval_reset(BATTLE_STATUS_B)
return True
if self.appear(GET_ITEMS_2, offset=5, interval=self.battle_status_click_interval):
if drop:
drop.handle_add(self, before=2)
self.device.click(CLICK_SAFE_AREA)
self.interval_reset(BATTLE_STATUS_S)
self.interval_reset(BATTLE_STATUS_A)
self.interval_reset(BATTLE_STATUS_B)
return True
if self.appear(GET_ADAPTABILITY, offset=5, interval=self.battle_status_click_interval):
if drop:
drop.handle_add(self, before=2)
self.device.click(CLICK_SAFE_AREA)
self.interval_reset(BATTLE_STATUS_S)
self.interval_reset(BATTLE_STATUS_A)
self.interval_reset(BATTLE_STATUS_B)
return True
return False
def _os_combat_expected_end(self):
if self.handle_map_event(drop=self.__os_combat_drop):
return False
if self.combat_appear():
raise ContinuousCombat
return self.handle_os_in_map()
__os_combat_drop = None
def combat_status(self, drop=None, expected_end=None):
self.__os_combat_drop = drop
super().combat_status(drop=drop, expected_end=self._os_combat_expected_end)
def combat(self, *args, save_get_items=False, **kwargs):
"""
This handle continuous combat in operation siren.
In siren scanning device, there are 2 ambush enemies with no interval.
Fleet goto siren scanning device, attack one enemy, skip TB, attack another.
Function `combat` has to confirm that combat was finished, and is_in_map.
When handling siren scanning device, it will stuck in the second combat.
This function inherits it and detect the second combat.
"""
for count in range(3):
if count >= 2:
logger.warning('Too many continuous combat')
try:
super().combat(*args, save_get_items=save_get_items, **kwargs)
break
except ContinuousCombat:
logger.info('Continuous combat detected')
continue
def handle_auto_search_battle_status(self, drop=None):
if self.appear(BATTLE_STATUS_C, interval=self.battle_status_click_interval):
logger.warning('Battle Status C')
# raise GameStuckError('Battle status C')
if drop:
drop.handle_add(self)
else:
self.device.sleep((0.25, 0.5))
self.device.click(BATTLE_STATUS_C)
return True
if self.appear(BATTLE_STATUS_D, interval=self.battle_status_click_interval):
logger.warning('Battle Status D')
# raise GameStuckError('Battle Status D')
if drop:
drop.handle_add(self)
else:
self.device.sleep((0.25, 0.5))
self.device.click(BATTLE_STATUS_D)
return True
return False
def handle_auto_search_exp_info(self):
if self.appear_then_click(EXP_INFO_C):
self.device.sleep((0.25, 0.5))
return True
if self.appear_then_click(EXP_INFO_D):
self.device.sleep((0.25, 0.5))
return True
return False
def auto_search_combat(self, drop=None):
"""
Args:
drop (DropImage):
Returns:
bool: True if enemy cleared, False if fleet died.
Pages:
in: is_combat_loading()
out: combat status
"""
logger.info('Auto search combat loading')
self.device.screenshot_interval_set('combat')
while 1:
self.device.screenshot()
if self.handle_combat_automation_confirm():
continue
# End
if self.handle_os_auto_search_map_option(drop=drop):
break
if self.is_combat_executing():
break
if self.is_in_map():
break
logger.info('Auto Search combat execute')
self.submarine_call_reset()
self.device.click_record_clear()
submarine_mode = 'do_not_use'
if self.config.Submarine_Fleet:
submarine_mode = self.config.Submarine_Mode
success = True
while 1:
self.device.screenshot()
if self.handle_submarine_call(submarine_mode):
continue
# Don't change auto search option if failed
enable = success if success is not None else None
if self.handle_os_auto_search_map_option(drop=drop, enable=enable):
continue
# End
if self.is_combat_executing():
continue
if self.handle_auto_search_battle_status():
success = None
continue
if self.handle_auto_search_exp_info():
success = None
continue
if self.handle_map_event():
continue
if self.is_in_map():
self.device.screenshot_interval_set()
break
logger.info('Combat end.')
return success