Skip to content

Commit c529309

Browse files
committed
修复各种卡住问题, 加快执行速度
1 parent fe5d2d8 commit c529309

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

config.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
'use_gui': True,
66
'config_folder': 'configs',
77
'gui_icon': 'icon.png',
8-
# 'auth': {
9-
# 'app_id': 'ok-ls',
10-
# 'trial': True
11-
# },
8+
'wait_until_before_delay': 0, # default 1 , for wait_until() function
9+
'wait_until_check_delay': 0,
10+
'wait_until_settle_time': 0.5,
1211
'ocr': {
1312
'lib': 'rapidocr_openvino',
1413
'target_height': 540
@@ -27,7 +26,6 @@
2726
'require_bg': True
2827
},
2928
'start_timeout': 120, # default 60
30-
'wait_until_before_delay': 2, # default 1 , for wait_until() function
3129
'window_size': {
3230
'width': 1200,
3331
'height': 800,

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ numpy==2.1.3
5353
# rapidocr-openvino
5454
# shapely
5555
pydirectinput==1.0.4
56-
ok-script==0.0.460
56+
ok-script==0.0.463
5757
# via -r .\requirements.in
5858
opencv-contrib-python==4.10.0.84
5959
# via -r .\requirements.in

src/tasks/BaseGfTask.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def skip_dialogs(self, end_match, end_box=None, time_out=120, has_dialog=True):
4444
elif self.find_boxes(boxes, match=re.compile(r'回合$'), boundary='top_left'):
4545
self.sleep(3)
4646
elif pop_up := self.find_boxes(boxes, match=pop_ups):
47-
self.click(pop_up)
47+
self.back()
4848
self.sleep(2)
4949
else:
5050
if has_dialog:
@@ -98,9 +98,13 @@ def auto_battle(self, end_match=None, end_box=None, has_dialog=False):
9898
if results[0].name != '战斗失败':
9999
self.wait_click_ocr(match='确认', box='bottom_right', raise_if_not_found=False, time_out=5)
100100
if end_match:
101-
match = self.wait_ocr(match=end_match, box=end_box, raise_if_not_found=True, time_out=30)
102-
if match:
103-
self.log_info(f'battle end matched: {match}')
101+
while True:
102+
match = self.wait_ocr(match=end_match + pop_ups, box=end_box, raise_if_not_found=True, time_out=30)
103+
if match[0].name in pop_ups:
104+
self.back(after_sleep=2)
105+
continue
106+
if match:
107+
self.log_info(f'battle end matched: {match}')
104108
self.sleep(2)
105109

106110
def is_main(self, recheck_time=0, esc=True):
@@ -118,7 +122,7 @@ def is_main(self, recheck_time=0, esc=True):
118122
return False
119123
if esc:
120124
self.back()
121-
self.sleep(1)
125+
self.sleep(4)
122126
# self.do_handle_alert()
123127
self.next_frame()
124128

@@ -201,8 +205,6 @@ def wait_pop_up(self, time_out=15, other=None, box='bottom'):
201205
check += other
202206
else:
203207
check.append(other)
204-
while self.wait_click_ocr(match=pop_ups, box=box, time_out=(time_out - (time.time() - start)),
205-
after_sleep=2,
206-
recheck_time=1,
207-
raise_if_not_found=False):
208-
pass
208+
while self.wait_ocr(match=pop_ups, box=box, time_out=(time_out - (time.time() - start)),
209+
raise_if_not_found=False):
210+
self.back(after_sleep=2)

src/tasks/DailyTask.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ def activity(self):
110110
if activities := self.wait_ocr(match=[re.compile(r'^\d+天\d+小时')], box='bottom_left',
111111
raise_if_not_found=False, time_out=4):
112112
self.click(activities[0])
113-
if self.wait_click_ocr(match=['活动战役', '物资模式'], box='bottom', after_sleep=0.5,
114-
raise_if_not_found=False, time_out=4, log=True):
113+
if to_click := self.wait_ocr(match=['活动战役', '物资模式'], box='bottom',
114+
raise_if_not_found=False, time_out=4, log=True):
115+
self.sleep(2)
116+
self.click(to_click)
115117
battles = self.wait_ocr(match=map_re, time_out=4)
116118
if battles:
117119
self.click(battles[-1])
@@ -150,7 +152,7 @@ def arena(self):
150152
self.wait_click_ocr(match=['战役推进'], box='right', after_sleep=0.5, raise_if_not_found=True)
151153
self.wait_click_ocr(match=['模拟作战'], box='top_right', after_sleep=0.5, raise_if_not_found=True)
152154
self.wait_click_ocr(match=['实兵演习'], box='bottom', after_sleep=0.5, raise_if_not_found=True)
153-
self.wait_pop_up(time_out=4)
155+
self.wait_pop_up(time_out=10)
154156
remaining_count = self.arena_remaining()
155157
count = 0
156158
if remaining_count > 1:
@@ -187,7 +189,7 @@ def bingqi(self):
187189
def guild(self):
188190
self.info_set('current_task', 'guild')
189191
self.wait_click_ocr(match=['班组'], box='bottom_right', after_sleep=0.5, raise_if_not_found=True)
190-
self.wait_click_ocr(match=['要务'], box='bottom_right', after_sleep=0.5, raise_if_not_found=True)
192+
self.wait_click_ocr(match=['要务'], box='bottom_right', after_sleep=0.5, raise_if_not_found=True, settle_time=2)
191193
result = self.wait_ocr(match=['开始作战', '每日要务已完成'], box='bottom_right',
192194
raise_if_not_found=True, log=True)
193195
if result[0].name == '开始作战':
@@ -267,8 +269,8 @@ def wait_click_ocr_with_pop_up(self, match, box=None):
267269

268270
def do_wait_pop_up_and_click(self, match, box):
269271
boxes = self.ocr()
270-
if pop_up := find_boxes_by_name(boxes, pop_ups):
271-
self.click(pop_up)
272+
if find_boxes_by_name(boxes, pop_ups):
273+
self.back(after_sleep=2)
272274
return False
273275
elif click := find_boxes_by_name(boxes, match):
274276
if click := find_boxes_within_boundary(click, self.get_box_by_name(box)):
@@ -284,8 +286,8 @@ def wait_ocr_with_possible_pop_up(self, match, box=None, raise_if_not_found=True
284286

285287
def do_wait_ocr_with_possible_pop_up(self, match, box):
286288
boxes = self.ocr()
287-
if pop_up := find_boxes_by_name(boxes, pop_ups):
288-
self.click(pop_up)
289+
if find_boxes_by_name(boxes, pop_ups):
290+
self.back(after_sleep=2)
289291
return False
290292
elif click := find_boxes_by_name(boxes, match):
291293
if box:
@@ -324,9 +326,7 @@ def challenge_arena_opponent(self):
324326
self.click(box)
325327
self.wait_click_ocr(match=['进攻'], box='bottom_right', after_sleep=0.5,
326328
raise_if_not_found=True)
327-
self.auto_battle()
328-
self.wait_ocr_with_possible_pop_up(match='刷新', box='bottom_right', raise_if_not_found=True,
329-
time_out=30)
329+
self.auto_battle(end_match='刷新')
330330
self.sleep(3)
331331
challenged += 1
332332
continue

0 commit comments

Comments
 (0)