Skip to content

Commit fe5d2d8

Browse files
committed
修复各种卡住问题
1 parent dc2d4ac commit fe5d2d8

File tree

4 files changed

+47
-23
lines changed

4 files changed

+47
-23
lines changed

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.458
56+
ok-script==0.0.460
5757
# via -r .\requirements.in
5858
opencv-contrib-python==4.10.0.84
5959
# via -r .\requirements.in

src/tasks/BaseGfTask.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def ensure_main(self, recheck_time=1, time_out=30, esc=True):
2525
if not self.wait_until(lambda: self.is_main(recheck_time=recheck_time, esc=esc), time_out=time_out):
2626
raise Exception("请从游戏主页进入")
2727

28-
def skip_dialogs(self, end_match, end_box=None, time_out=120):
28+
def skip_dialogs(self, end_match, end_box=None, time_out=120, has_dialog=True):
2929
self.info_set('current_task', 'skip_dialogs')
3030
self.sleep(5)
3131
start = time.time()
3232
while time.time() - start < time_out:
3333
boxes = self.ocr()
34-
if skip := self.find_boxes(boxes, match=['跳过'] + pop_ups):
34+
if skip := self.find_boxes(boxes, match=['跳过']):
3535
self.click(skip)
3636
self.sleep(2)
3737
elif no_alert := self.find_boxes(boxes, match='今日不再提示'):
@@ -43,15 +43,20 @@ def skip_dialogs(self, end_match, end_box=None, time_out=120):
4343
return result
4444
elif self.find_boxes(boxes, match=re.compile(r'回合$'), boundary='top_left'):
4545
self.sleep(3)
46+
elif pop_up := self.find_boxes(boxes, match=pop_ups):
47+
self.click(pop_up)
48+
self.sleep(2)
4649
else:
47-
self.click_relative(0.95, 0.04)
50+
if has_dialog:
51+
self.click_relative(0.95, 0.04)
4852
self.sleep(2)
4953
self.next_frame()
5054
raise Exception('跳过剧情超时!')
5155

52-
def auto_battle(self, end_match=None, end_box=None):
56+
def auto_battle(self, end_match=None, end_box=None, has_dialog=False):
5357
self.info_set('current_task', 'auto battle')
54-
result = self.skip_dialogs(end_match=['作战开始', '行动结束'], end_box='bottom', time_out=120)
58+
result = self.skip_dialogs(end_match=['作战开始', '行动结束'], end_box='bottom', time_out=120,
59+
has_dialog=has_dialog)
5560
if result[0].name == '作战开始':
5661
self.sleep(2)
5762
self.click_box(result, after_sleep=1)
@@ -76,7 +81,8 @@ def auto_battle(self, end_match=None, end_box=None):
7681

7782
results = []
7883
while results := self.skip_dialogs(
79-
end_match=['任务完成', '任务失败', '战斗失败', '对战胜利', '对战失败', '确认'], time_out=900):
84+
end_match=['任务完成', '任务失败', '战斗失败', '对战胜利', '对战失败', '确认'], time_out=900,
85+
has_dialog=has_dialog):
8086
for result in results:
8187
if result.name == '确认':
8288
self.click_box(result, after_sleep=2)
@@ -118,14 +124,17 @@ def is_main(self, recheck_time=0, esc=True):
118124

119125
def click(self, x=0, y=0, move_back=False, name=None, interval=-1, move=True,
120126
down_time=0.01, after_sleep=0):
121-
super().click(x, y, move_back=move_back, name=name, move=move, down_time=0.02, after_sleep=after_sleep,
127+
frame = self.frame
128+
super().click(x, y, move_back=move_back, name=name, move=move, down_time=0.04, after_sleep=after_sleep,
122129
interval=interval)
123-
124-
# def back(self, after_sleep=0):
125-
# if not self.is_adb() and not self.hwnd.visible:
126-
# self.click_relative(0.03, 0.04, after_sleep=after_sleep)
127-
# else:
128-
# super().back(after_sleep=after_sleep)
130+
if self.debug:
131+
self.screenshot('click', frame=frame)
132+
133+
def back(self, after_sleep=0):
134+
frame = self.frame
135+
super().back(after_sleep=after_sleep)
136+
if self.debug:
137+
self.screenshot('back', frame=frame)
129138

130139
def find_top_right_count(self):
131140
result = self.ocr(0.89, 0.01, 0.99, 0.1, match=re.compile(r"^\d+/\d+$"), box='top_right')

src/tasks/ClearMapTask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def run(self):
4141
self.click(text)
4242
count += 1
4343
if text[0].name == '挑战':
44-
self.auto_battle(end_match=map_re)
44+
self.auto_battle(end_match=map_re, has_dialog=True)
4545
else:
4646
self.skip_dialogs(end_match=map_re)
4747
else:

src/tasks/DailyTask.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def __init__(self, *args, **kwargs):
1414
self.name = "一键日常"
1515
self.description = "收菜"
1616
self.default_config.update({
17+
'活动情报补给': True,
1718
'活动自律': True,
1819
'公共区': True,
1920
'购买免费礼包': True,
@@ -36,6 +37,8 @@ def run(self):
3637
# user32.BlockInput(False)
3738
# return self.choose_chenyan()
3839
self.ensure_main(recheck_time=2, time_out=90)
40+
if self.config.get('活动情报补给'):
41+
self.activity_stamina()
3942
if self.config.get('活动自律'):
4043
self.activity()
4144
if self.config.get('公共区'):
@@ -58,13 +61,24 @@ def run(self):
5861
self.mail()
5962
self.log_info('少前2日常完成!', notify=True)
6063

64+
def activity_stamina(self):
65+
self.info_set('current_task', 'activity_stamina')
66+
self.wait_click_ocr(match=['活动'], box='bottom_right', after_sleep=0.5, raise_if_not_found=True)
67+
if self.wait_click_ocr(match=['情报补给'], box='left', time_out=3,
68+
raise_if_not_found=False, after_sleep=1):
69+
while self.wait_click_ocr(match=['领取'], box='bottom_right', time_out=3,
70+
raise_if_not_found=False, after_sleep=1):
71+
self.wait_pop_up(time_out=6)
72+
self.ensure_main()
73+
6174
def claim_quest(self):
6275
self.info_set('current_task', 'claim_quest')
6376
self.wait_click_ocr(match=['委托'], box='bottom_right', after_sleep=0.5, raise_if_not_found=True)
64-
self.wait_click_ocr(match=['一键领取', '无可领取报酬', '已全部领取'], box='bottom_right', time_out=4,
65-
raise_if_not_found=False, after_sleep=1)
77+
self.wait_click_ocr(match=['一键领取'], box='bottom', time_out=4,
78+
raise_if_not_found=False, after_sleep=2)
79+
# if results and results[0].name == '一键领取':
6680
results = self.ocr(match=['领取全部', '无可领取报酬', '已全部领取'], box='bottom_left')
67-
if results[0] == '领取全部':
81+
if results[0].name == '领取全部':
6882
self.click(results[0])
6983
self.wait_pop_up(time_out=4)
7084
self.ensure_main()
@@ -199,9 +213,10 @@ def guild(self):
199213
def chenyan(self):
200214
if not self.config.get('尘烟'):
201215
return
202-
end = self.ocr(match=re.compile('后结束'), box='bottom_right')
203-
if end:
204-
self.click(end, after_sleep=1)
216+
end = self.ocr(match=re.compile('后结束$'), box='bottom_right')
217+
if not end:
218+
return
219+
self.click(end, after_sleep=1)
205220
result = self.ocr(0.89, 0.01, 0.99, 0.1, match=stamina_re, box='top_right')
206221
if not result:
207222
raise Exception('找不到尘烟票')
@@ -289,7 +304,7 @@ def challenge_arena_opponent(self):
289304
if remaining_count <= 1:
290305
self.log_info(f'challenge arena complete {remaining_count}')
291306
break
292-
boxes = self.ocr(0, 0.55, 0.94, 0.62, match=re.compile(r"^[1-9]\d*$"))
307+
boxes = self.ocr(0, 0.51, 0.94, 0.59, match=re.compile(r"^[1-9]\d*$"))
293308
if len(boxes) != 5:
294309
if not waited_pop_up:
295310
waited_pop_up = True
@@ -312,7 +327,7 @@ def challenge_arena_opponent(self):
312327
self.auto_battle()
313328
self.wait_ocr_with_possible_pop_up(match='刷新', box='bottom_right', raise_if_not_found=True,
314329
time_out=30)
315-
self.sleep(1)
330+
self.sleep(3)
316331
challenged += 1
317332
continue
318333
if self.ocr(match=['刷新消耗'], box='bottom_right'):

0 commit comments

Comments
 (0)