Skip to content

Commit 1470b1d

Browse files
committed
🐛 fix(commissions): 修正自动处理密函异常报错
1 parent a5a632a commit 1470b1d

6 files changed

Lines changed: 41 additions & 26 deletions

File tree

src/tasks/AutoDefence.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
logger = Logger.get_logger(__name__)
1010

11-
DEFAULT_ACTION_TIMEOUT = 10
12-
1311

1412
class AutoDefence(DNAOneTimeTask, CommissionsTask, BaseCombatTask):
1513

@@ -27,7 +25,6 @@ def __init__(self, *args, **kwargs):
2725
"超时时间": "波次超时后将发出提示",
2826
})
2927

30-
self.action_timeout = DEFAULT_ACTION_TIMEOUT
3128
self.quick_assist_task = QuickAssistTask(self)
3229
self.external_movement = _default_movement
3330
self._external_config = None
@@ -87,7 +84,7 @@ def do_run(self):
8784
elif _status == Mission.CONTINUE:
8885
self.log_info("任务继续")
8986
self.init_for_next_round()
90-
self.wait_until(self.in_team, time_out=DEFAULT_ACTION_TIMEOUT)
87+
self.wait_until(self.in_team, time_out=self.action_timeout)
9188

9289
self.sleep(0.1)
9390

@@ -139,7 +136,7 @@ def handle_mission_start(self):
139136
if self.external_movement is not _default_movement:
140137
self.log_info("任务开始,执行外部移动逻辑")
141138
self.external_movement(delay=2)
142-
time_out = DEFAULT_ACTION_TIMEOUT + 10
139+
time_out = self.action_timeout + 10
143140
self.log_info(f"外部移动执行完毕,等待战斗开始,{time_out}秒后超时")
144141
if not self.wait_until(lambda: self.current_wave != -1 or self.find_esc_menu(), post_action=self.get_wave_info,
145142
time_out=time_out):

src/tasks/AutoExcavation.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
logger = Logger.get_logger(__name__)
1010

11-
DEFAULT_ACTION_TIMEOUT = 10
12-
13-
1411
class AutoExcavation(DNAOneTimeTask, CommissionsTask, BaseCombatTask):
1512

1613
def __init__(self, *args, **kwargs):
@@ -26,7 +23,6 @@ def __init__(self, *args, **kwargs):
2623
for key in keys_to_remove:
2724
self.default_config.pop(key, None)
2825

29-
self.action_timeout = DEFAULT_ACTION_TIMEOUT
3026
self.quick_assist_task = QuickAssistTask(self)
3127
self.skill_tick = self.create_skill_ticker()
3228

@@ -52,7 +48,7 @@ def do_run(self):
5248

5349
_status = self.handle_mission_interface(stop_func=self.stop_func)
5450
if _status == Mission.START:
55-
self.wait_until(self.in_team, time_out=DEFAULT_ACTION_TIMEOUT)
51+
self.wait_until(self.in_team, time_out=self.action_timeout)
5652
self.sleep(2)
5753
self.init_all()
5854
self.handle_mission_start()
@@ -62,7 +58,7 @@ def do_run(self):
6258
elif _status == Mission.CONTINUE:
6359
self.log_info("任务继续")
6460
self.init_for_next_round()
65-
self.wait_until(self.in_team, time_out=DEFAULT_ACTION_TIMEOUT)
61+
self.wait_until(self.in_team, time_out=self.action_timeout)
6662

6763
self.sleep(2)
6864
if not self.find_target_health_bar():

src/tasks/AutoExploration.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
logger = Logger.get_logger(__name__)
1010

11-
DEFAULT_ACTION_TIMEOUT = 10
12-
1311

1412
class AutoExploration(DNAOneTimeTask, CommissionsTask, BaseCombatTask):
1513

@@ -27,7 +25,6 @@ def __init__(self, *args, **kwargs):
2725
'超时时间': '超时后将发出提示',
2826
})
2927

30-
self.action_timeout = DEFAULT_ACTION_TIMEOUT
3128
self.quick_assist_task = QuickAssistTask(self)
3229
self.external_movement = _default_movement
3330
self._external_config = None
@@ -87,7 +84,7 @@ def do_run(self):
8784
elif _status == Mission.CONTINUE:
8885
self.log_info("任务继续")
8986
self.init_for_next_round()
90-
self.wait_until(self.in_team, time_out=DEFAULT_ACTION_TIMEOUT)
87+
self.wait_until(self.in_team, time_out=self.action_timeout)
9188

9289
self.sleep(0.1)
9390

@@ -129,7 +126,7 @@ def handle_mission_start(self):
129126
if self.external_movement is not _default_movement:
130127
self.log_info("任务开始")
131128
self.external_movement(delay=2)
132-
time_out = DEFAULT_ACTION_TIMEOUT + 10
129+
time_out = self.action_timeout + 10
133130
self.log_info(f"外部移动执行完毕,等待战斗开始,{time_out}秒后超时")
134131
if not self.wait_until(lambda: self.find_serum() or self.find_esc_menu(), time_out=time_out):
135132
self.log_info("超时重开")

src/tasks/AutoHedge.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
logger = Logger.get_logger(__name__)
1414

15-
DEFAULT_ACTION_TIMEOUT = 10
16-
1715

1816
class AutoHedge(DNAOneTimeTask, CommissionsTask, BaseCombatTask):
1917

@@ -34,7 +32,6 @@ def __init__(self, *args, **kwargs):
3432
'超时时间': '超时后将发出提示',
3533
})
3634

37-
self.action_timeout = DEFAULT_ACTION_TIMEOUT
3835
self.quick_assist_task = QuickAssistTask(self)
3936
self.external_movement = _default_movement
4037
self.external_movement_evac = _default_movement
@@ -98,7 +95,7 @@ def do_run(self):
9895

9996
_status = self.handle_mission_interface(stop_func=self.stop_func)
10097
if _status == Mission.START:
101-
self.wait_until(self.in_team, time_out=DEFAULT_ACTION_TIMEOUT)
98+
self.wait_until(self.in_team, time_out=self.action_timeout)
10299
self.init_all()
103100
self.handle_mission_start()
104101
elif _status == Mission.STOP:
@@ -161,7 +158,7 @@ def handle_mission_start(self):
161158
if self.external_movement is not _default_movement:
162159
self.log_info("任务开始")
163160
self.external_movement(delay=2)
164-
time_out = DEFAULT_ACTION_TIMEOUT + 10
161+
time_out = self.action_timeout + 10
165162
self.log_info(f"外部移动执行完毕,等待战斗开始,{time_out}秒后超时")
166163
if not self.wait_until(lambda: self.runtime_state["in_progress"] or self.find_esc_menu(), post_action=self.update_mission_status,
167164
time_out=time_out):

src/tasks/BaseDNATask.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,21 @@ def _perform_random_click(self, x_abs, y_abs, use_safe_move=False, safe_move_box
363363
self.pydirect_interaction.click(down_time=_down_time)
364364

365365
self.sleep(_after_sleep)
366+
367+
def click_btn_random(self, box: Box, down_time=0.0, post_sleep=0.0, after_sleep=0.0):
368+
safe_move_box = box.copy(x_offset=-box.width*0.20, width_offset=box.width * 8.1,
369+
y_offset=-box.height*0.30, height_offset=box.height * 0.7, name='safe_move_box')
370+
random_x = random.uniform(box.x + box.width, box.x + self.width * 0.12)
371+
random_y = random.uniform(box.y, box.y + box.height)
372+
373+
self._perform_random_click(
374+
random_x, random_y,
375+
use_safe_move=True,
376+
safe_move_box=safe_move_box,
377+
down_time=down_time,
378+
post_sleep=post_sleep,
379+
after_sleep=after_sleep
380+
)
366381

367382
def click_box_random(self, box: Box, down_time=0.0, post_sleep=0.0, after_sleep=0.0, use_safe_move=False, safe_move_box=None, left_extend=0.0, right_extend=0.0, up_extend=0.0, down_extend=0.0):
368383
le_px = left_extend * self.width
@@ -432,6 +447,8 @@ def rel_move_if_in_win(self, x=0.5, y=0.5, box=None):
432447
x (float): 相对 x 坐标 (0.0 到 1.0)。
433448
y (float): 相对 y 坐标 (0.0 到 1.0)。
434449
"""
450+
if box is not None:
451+
self.draw_boxes(box.name, box, "blue")
435452
if not self.is_mouse_in_window() or not self.is_mouse_in_box(box=box):
436453
return False
437454
abs_pos = self.executor.device_manager.hwnd_window.get_abs_cords(self.width_of_screen(x),

src/tasks/CommissionsTask.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def choose_letter(self, timeout=0):
209209
return
210210
action_timeout = self.action_timeout if timeout == 0 else timeout
211211
if self.commission_config.get("自动处理密函", False):
212-
if (letter_btn:=self.find_letter_interface()):
212+
if self.find_letter_interface():
213213
box = self.box_of_screen_scaled(2560, 1440, 1190, 610, 2450, 820, name="letter_drag_area", hcenter=True)
214214
letter_roi = self.box_of_screen_scaled(2560, 1440, 565, 651, 732, 805, name="letter_roi", hcenter=True)
215215
letter_snapshot = letter_roi.crop_frame(self.frame)
@@ -223,13 +223,24 @@ def choose_letter(self, timeout=0):
223223
self.log_info_notify("密函已耗尽")
224224
self.soundBeep()
225225
raise TaskDisabledException
226+
227+
deadline = time.time() + action_timeout
228+
while time.time() < deadline:
229+
letter_btn = self.find_letter_btn()
230+
if letter_btn:
231+
self.move_back_from_safe_position()
232+
break
233+
else:
234+
self.move_mouse_to_safe_position()
235+
self.next_frame()
236+
else:
237+
self.log_info_notify("未找到密函确认按钮")
238+
self.soundBeep()
239+
raise TaskDisabledException
226240

227241
self.wait_until(
228242
condition=lambda: not self.find_letter_interface(),
229-
post_action=lambda: (
230-
self.click_box_random(letter_btn, use_safe_move=True, safe_move_box=box, right_extend=0.1),
231-
self.sleep(1),
232-
),
243+
post_action=lambda: self.click_btn_random(letter_btn, after_sleep=1),
233244
time_out=action_timeout,
234245
raise_if_not_found=True,
235246
)

0 commit comments

Comments
 (0)