-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfunction_ark.py
281 lines (266 loc) · 10.7 KB
/
function_ark.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
272
273
274
275
276
277
278
279
280
281
from basic_function import *
import time
import os
import config_ark
import globalvar
# time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time()))
def judge_where(handle,count_max=60):
#判断当前位置
def _judge(im):
for keys,pic_data in config_ark.pic_where.items():
if pic_locate(pic_data, im, globalvar.get_thresh_pic(),False,True) != None:
current_pos = keys
return current_pos
return None
im = prtsc(handle)
count =0
current_pos = _judge(im)
while(current_pos ==None):
print('no situation detected, detect two seconds later')
time.sleep(2)
im = prtsc(handle)
current_pos = _judge(im)
count+=1
if count >=count_max:
if count_max == 60:
temp_im = Image.fromarray(im)
temp_im.save(os.path.join(config_ark.IMG_SAVE,'error_{}.png'.format(
time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())))))
# io.imsave(os.path.join(config_ark.IMG_SAVE,'error_{}.png'.format(
# time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())))), im)
raise Exception('模拟器可能卡死')
else:
return current_pos
return current_pos
def confirm_where(handle,pic_data,rgb_bool = True,confirm_once=True):
#验证当前是否处于某位置
def _judge(im):
if pic_locate(pic_data, im, globalvar.get_thresh_pic(), rgb_bool= rgb_bool,findall=False) != None:
return True
else:
return False
time.sleep(1)
im = prtsc(handle)
count =0
exist = _judge(im)
if confirm_once ==True:
return exist
if confirm_once==False:
count_max = 60
else:
count_max = confirm_once
while (exist == False):
print('no situation detected, detect two seconds later')
time.sleep(2)
im = prtsc(handle)
exist = _judge(im)
count += 1
if count >= count_max:
if count_max ==60:
temp_im = Image.fromarray(im)
temp_im.save(os.path.join(config_ark.IMG_SAVE,'error_{}.png'.format(
time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())))))
# io.imsave(os.path.join(config_ark.IMG_SAVE,'error_{}.png'.format(
# time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())))), im)
raise Exception('模拟器可能卡死')
else:
return exist
return exist
def pic_position(handle,pic_data,thresh=None,findall=False,once=False):
#寻找图像位于模拟器的像素位置,左上为(0,0)
if thresh==None:
thresh = globalvar.get_thresh_pic()
count = 0
if once != False and once != True:
count_max = once
else:
count_max = 60
while(1):
im = prtsc(handle)
position = pic_locate(pic_data, im, thresh, findall,rgb_bool=False)
if position!=None or once==True:
break
time.sleep(2)
count +=1
if count>=count_max:
if count_max ==60:
temp_im = Image.fromarray(im)
temp_im.save(os.path.join(config_ark.IMG_SAVE,'error_{}.png'.format(
time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())))))
# io.imsave(os.path.join(config_ark.IMG_SAVE,'error_{}.png'.format(
# time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())))), im)
raise Exception('模拟器可能卡死')
else:
return position
return position
def enter_where(handle,where):
#利用导航进入各个主界面
#先判断当前所在位置,若为公告:关闭 战斗中:等待 战斗结束:随意点击 若与where一致:不操作 主界面:点击对应位置
# where: 表示进入的位置 目前暂时只支持"作战"
# return false:失败 true:成功
current_pos = judge_where(handle,60) #若有不存在当前图像库的状况保存
if current_pos == "gonggao":
position = pic_position(handle,config_ark.pic_where["gonggao"],once=True)
if position!=None:
mouse_click(handle,position["result"])
if confirm_where(handle,config_ark.pic_where["gonggao"]) and where=="zhandou_xuanze":
mouse_click(handle,config_ark.points["zhandou_enter"])
if confirm_where(handle,config_ark.pic_where[where],confirm_once=5):
return True
else:
print("人为关闭公告,略过\n")
elif current_pos == "zhujiemian":
mouse_click(handle, config_ark.points["zhandou_enter"])
if confirm_where(handle, config_ark.pic_where[where], confirm_once=5):
return True
else:
#暂时用不上,懒得写
pass
#enter_where(handle,where) 不使用迭代,较危险
return False
def enter_chapter(handle,where):
#从战斗进入主线,物资,活动关卡等
#where为关卡完整信息,如 "ZX-1-1-11"
tmp = where.split('|')
sub_class = tmp[0] + "|" + tmp[1]
chapter = tmp[0]
if chapter in ['ZX','PR','WZ']:
confirm_pic = config_ark.guanqia_pic[chapter]
sub_class_pic = config_ark.guanqia_pic[sub_class]
elif chapter is 'HD':
confirm_pic = config_ark.pic_huodong[chapter]
sub_class_pic = config_ark.pic_huodong[sub_class]
else:
#实际上不可能出现
temp_str = None
raise Exception
#进入一级章节
position = pic_position(handle,confirm_pic,once=True)
if position!=None:
mouse_click(handle,position["result"])
time.sleep(1)
else:
return False
cnt=0
#进入子章节
while (1):
position = pic_position(handle, sub_class_pic,once=1)
if position!=None:
break
mouse_drag(handle, config_ark.points['drag_left'], globalvar.get_drag_speed())
cnt += 1
if cnt > 10:
print("主线进入失败,重新进入战斗界面")
return False
mouse_click(handle,position["result"])
print("进入{}".format(sub_class))
return True
def enter_zhuxian(handle,where,daili_confirm=True):
"""
:param handle:
:param where: exp 'ZX|1|1-11' 'HD|1|xx-xx'
:param daili_confirm:
:return:
"""
#从章节进入主线
#开始拖拽至最最右侧
#先判定是否有选择的关卡
chapter = where.split('|')[0]
if chapter == 'HD':
tmp1 = config_ark.pic_huodong[where]
tmp2 = config_ark.pic_huodong[where+'_confirm']
else:
tmp1 = config_ark.guanqia_pic[where]
tmp2 = config_ark.guanqia_pic[where+'_confirm']
position = pic_position(handle, tmp1,once=True)
if position==None:
position = pic_position(handle,tmp2,once=True)
if position==None:
print('当前界面未检测到选择关卡,划至最右侧寻找')
for i in range(20):
mouse_drag(handle, config_ark.points['drag_right'], 3)
cnt = 0
while (1):
position = pic_position(handle, tmp1,once=1)
if position != None:
break
mouse_drag(handle, config_ark.points['drag_left'], globalvar.get_drag_speed())
cnt += 1
if cnt > 20:
print("主线进入失败,重新进入战斗界面")
return False
mouse_click(handle, position["result"])
time.sleep(1)
print("选择关卡")
#if confirm_where(handle, config_ark.guanqia_pic["{}_confirm".format(where)], confirm_once=2):
if daili_confirm==True:
position = pic_position(handle, config_ark.pic_confirm["daili_do"], once=True)
if position != None:
print("代理已使用")
# i += 1
pass
else:
mouse_click(handle, config_ark.points['daili'])
time.sleep(1)
print("使用代理")
else:
return False
mouse_click(handle, config_ark.points["peizhi_enter"])
print("进入队伍配置界面")
#else:
#return False
time.sleep(3)
return True
def set_direction(handle,xy,direction):
#direction left ,right up down
if direction == "left":
temp_xy = [xy[0]-config_ark.BUSHU_OFFSET,xy[1]]
mouse_drag(handle,(xy,temp_xy),globalvar.get_drag_speed())
elif direction == "right":
temp_xy = [xy[0]+config_ark.BUSHU_OFFSET,xy[1]]
mouse_drag(handle,(xy,temp_xy),globalvar.get_drag_speed())
elif direction == "up":
temp_xy = [xy[0],xy[1]-config_ark.BUSHU_OFFSET]
mouse_drag(handle,(xy,temp_xy),globalvar.get_drag_speed())
elif direction == "down":
temp_xy = [xy[0],xy[1]-config_ark.BUSHU_OFFSET]
mouse_drag(handle,(xy,temp_xy),globalvar.get_drag_speed())
def battle_speed_set(handle,speed=2):
if speed ==2:
position = pic_position(handle,config_ark.pic_confirm["1xspeed"],once=True)
if position!=None:
mouse_click(handle,position["result"])
time.sleep(0.5)
if confirm_where(handle,config_ark.pic_confirm["2xspeed"],confirm_once=True):
print("战斗速度修改为2x")
return True
else:
print("当前战斗速度为2x")
return True
return False
def staff_set(handle,name_or_xy,target_xy,direction):
"""
部署干员,自动检查费用是否足够及部署目标位置是否正确
:param handle: 窗口句柄
:param name_or_xy: 部署干员名称或xy坐标
:param target_xy: 部署位置xy坐标
:return: true部署正确,false未知错误
"""
if isinstance(name_or_xy,str):
#干员名称
assert(name_or_xy in config_ark.staff_pic.keys())
staff_pic = config_ark.staff_pic[name_or_xy]
i = 0
while(i<30):
i += 1
position = pic_position(handle,staff_pic,globalvar.get_thresh_pic(),once=True)
if position!=None:
mouse_drag(handle,(position["result"],target_xy),globalvar.get_drag_speed())
time.sleep(1)
if pic_position(handle,config_ark.pic_confirm["bushu_fangxiang"],thresh=globalvar.get_thresh_pic()-0.1,once=True)!=None:
set_direction(handle,target_xy,direction)
time.sleep(2)
return True
else:
print("No staff{} detected".format(name_or_xy))
return False