forked from chriszxv/AzurLaneBot
/
rescue_mode.py
244 lines (182 loc) · 7.24 KB
/
rescue_mode.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
import time
import pyautogui
import cv2
import sys
from enum import Enum
pyautogui.FAILSAFE = True
class GameState(Enum):
Other = 'other'
PreCombat = 'precombat'
SubChapter = 'subchapter'
Formation = 'formation'
Complete = 'complete'
def localeImage(image, confidence=0.7, grayscale=True):
return pyautogui.locateOnScreen(image + '.png', confidence=confidence, grayscale=grayscale)
def clickImage(targetImage, confidence=0.7):
location = localeImage(targetImage, confidence=confidence)
if location is not None:
x, y = pyautogui.center(location)
pyautogui.click(x, y)
pyautogui.PAUSE = 1.0
return
def clickImageUntilSuccess(targetImage, confidence=0.7):
location = None
while location is None:
print('...')
location = localeImage(targetImage, confidence=confidence)
x, y = pyautogui.center(location)
pyautogui.click(x, y)
pyautogui.PAUSE = 1.0
return
def pressKey(key, count=1):
print('press ' + str(key) + ' ' + str(count) + ' time(s)...')
while(count > 0):
pyautogui.keyDown(key)
pyautogui.keyUp(key)
pyautogui.PAUSE = 0.3
count = count - 1
return
def checkGameState():
location = localeImage(
'.\\images\\precombat\\rescue_signal_1', confidence=0.7)
if location is not None:
return GameState.PreCombat
location = localeImage(
'.\\images\\precombat\\rescue_signal_2', confidence=0.7)
if location is not None:
return GameState.PreCombat
location = localeImage('.\\images\\subchapter\\offensive', confidence=0.9)
if location is not None:
return GameState.SubChapter
location = localeImage(
'.\\images\\formation\\auto_fight_off', confidence=0.7)
if location is not None:
return GameState.Formation
location = localeImage(
'.\\images\\formation\\auto_fight_on', confidence=0.7)
if location is not None:
return GameState.Formation
location = localeImage('.\\images\\complete\\confirm', confidence=0.7)
if location is not None:
return GameState.Complete
return GameState.Other
def handleOtherState():
pressKey('C')
return
def handlePreCombatState():
print('handle rescue chapter:')
handleRescueChapter()
print('handle sub chapter:')
handleSubChapter()
return
def handleRescueChapter():
print('click rescue signal...')
clickImage('.\\images\\precombat\\rescue_signal_1')
clickImage('.\\images\\precombat\\rescue_signal_2')
print('click rescue...')
clickImageUntilSuccess('.\\images\\precombat\\rescue')
return
def handleSubChapter():
print('click sub chapter...')
clickImage('.\\images\\precombat\\sub_chapter_X_5', confidence=0.7)
print('click strike button 1...')
clickImage('.\\images\\precombat\\strike', confidence=0.7)
print('click strike button 2...')
clickImage('.\\images\\precombat\\strike', confidence=0.7)
return
def handleSubChapterState():
print('wait animation...')
time.sleep(3.0)
findShipBoss()
findShipBattleship()
findShipBoss()
findShipDestroyer()
findShipBoss()
findShipCarrier()
findShipBoss()
print('find confirm...')
clickImage('.\\images\\subchapter\\confirm', confidence=0.7)
return
def findShipBoss():
print('click ship boss...')
clickImage('.\\images\\subchapter\\ship_boss_1', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_boss_2', confidence=0.7)
# clickImage('.\\images\\subchapter\\ship_boss_3', confidence = 0.7)
# clickImage('.\\images\\subchapter\\ship_boss_4', confidence = 0.7)
# clickImage('.\\images\\subchapter\\ship_boss_5', confidence = 0.7)
# clickImage('.\\images\\subchapter\\ship_boss_6', confidence = 0.7)
clickImage('.\\images\\subchapter\\ship_boss_7', confidence=0.7)
return
def findShipBattleship():
print('click ship battleship...')
clickImage('.\\images\\subchapter\\ship_battleship_1', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_battleship_2', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_battleship_3', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_battleship_4', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_battleship_5', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_battleship_6', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_battleship_7', confidence=0.7)
return
def findShipDestroyer():
print('click ship destroyer...')
clickImage('.\\images\\subchapter\\ship_destroyer_1', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_destroyer_2', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_destroyer_3', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_destroyer_4', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_destroyer_5', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_destroyer_6', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_destroyer_7', confidence=0.7)
return
def findShipCarrier():
print('click ship carrier...')
clickImage('.\\images\\subchapter\\ship_carrier_1', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_carrier_2', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_carrier_3', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_carrier_4', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_carrier_5', confidence=0.7)
clickImage('.\\images\\subchapter\\ship_carrier_6', confidence=0.7)
# clickImage('.\\images\\subchapter\\ship_carrier_7', confidence = 0.7)
return
def handleFormationState():
print('click auto off if exists...')
location = localeImage(
'.\\images\\formation\\auto_fight_off', confidence=0.9, grayscale=False)
if location is not None:
clickImageUntilSuccess('.\\images\\formation\\auto_fight_off')
print('wait animation...')
time.sleep(2.0)
print('click auto submarine support off if exists...')
location = localeImage(
'.\\images\\formation\\auto_submarine_support_off', confidence=0.9, grayscale=False)
if location is not None:
clickImageUntilSuccess(
'.\\images\\formation\\auto_submarine_support_off')
print('click weigh anchor')
clickImage('.\\images\\formation\\weigh_anchor', confidence=0.7)
return
def handleInCompleteState():
clickImage('.\\images\\complete\\confirm', confidence=0.7)
return
def main():
scriptName = sys.argv[0]
print('Start running: ' + scriptName)
print('Press Ctrl-C to quit.')
while True:
print('...')
currentGameState = checkGameState()
print(
'============================================================================')
print('Current Game State: ' + currentGameState.name)
if currentGameState == GameState.Other:
handleOtherState()
elif currentGameState == GameState.PreCombat:
handlePreCombatState()
elif currentGameState == GameState.SubChapter:
handleSubChapterState()
elif currentGameState == GameState.Formation:
handleFormationState()
elif currentGameState == GameState.Complete:
handleInCompleteState()
return
if __name__ == '__main__':
main()