Skip to content

Commit 18d2375

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

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

src/tasks/BaseDNATask.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ def soundBeep(self, _n=None):
226226
def log_info_notify(self, msg):
227227
self.log_info(msg, notify=self.afk_config['弹出通知'])
228228

229-
def move_mouse_to_safe_position(self, save_current_pos: bool = True, box: Union[Box, None] = None):
229+
def move_mouse_to_safe_position(self, save_current_pos: bool = True, boxes: Union[list[Box], Box, None] = None):
230230
if self.afk_config["防止鼠标干扰"]:
231231
self.old_mouse_pos = win32api.GetCursorPos() if save_current_pos else None
232-
if self.rel_move_if_in_win(0.95, 0.6, box=box):
232+
if self.rel_move_if_in_win(0.95, 0.6, boxes=boxes):
233233
pass
234234
else:
235235
self.old_mouse_pos = None
@@ -340,7 +340,7 @@ def set_mouse_in_window(self):
340340
abs_pos = self.executor.interaction.capture.get_abs_cords(random_x, random_y)
341341
win32api.SetCursorPos(abs_pos)
342342

343-
def _perform_random_click(self, x_abs, y_abs, use_safe_move=False, safe_move_box=None, down_time=0.0, post_sleep=0.0, after_sleep=0.0):
343+
def _perform_random_click(self, x_abs, y_abs, use_safe_move=False, safe_move_box: Union[list[Box], Box, None]=None, down_time=0.0, post_sleep=0.0, after_sleep=0.0):
344344
x = int(x_abs)
345345
y = int(y_abs)
346346

@@ -353,7 +353,7 @@ def _perform_random_click(self, x_abs, y_abs, use_safe_move=False, safe_move_box
353353
if not self.hwnd.is_foreground():
354354
if use_safe_move:
355355
_down_time = 0.01 if down_time == 0.0 else down_time
356-
self.move_mouse_to_safe_position(box=safe_move_box)
356+
self.move_mouse_to_safe_position(boxes=safe_move_box)
357357
self.click(x, y, down_time=_down_time)
358358
if use_safe_move:
359359
self.move_back_from_safe_position()
@@ -364,11 +364,18 @@ def _perform_random_click(self, x_abs, y_abs, use_safe_move=False, safe_move_box
364364

365365
self.sleep(_after_sleep)
366366

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,
367+
def click_btn_random(self, box: Box, safe_move_box: Box = None, down_time=0.0, post_sleep=0.0, after_sleep=0.0):
368+
box = box.copy(x_offset=-box.width*0.20, width_offset=box.width * 8.1,
369369
y_offset=-box.height*0.30, height_offset=box.height * 0.7, name='safe_move_box')
370370
random_x = random.uniform(box.x + box.width, box.x + self.width * 0.12)
371371
random_y = random.uniform(box.y, box.y + box.height)
372+
373+
if safe_move_box is not None:
374+
if isinstance(safe_move_box, Box):
375+
safe_move_box = [safe_move_box]
376+
safe_move_box.append(box)
377+
else:
378+
safe_move_box = box
372379

373380
self._perform_random_click(
374381
random_x, random_y,
@@ -439,18 +446,25 @@ def is_mouse_in_box(self, box: Box) -> bool:
439446
(x1, y1), (x2, y2) = [hwnd_window.get_abs_cords(x, y) for x, y in coords]
440447
return x1 <= mouse_x < x2 and y1 <= mouse_y < y2
441448

442-
def rel_move_if_in_win(self, x=0.5, y=0.5, box=None):
449+
def rel_move_if_in_win(self, x=0.5, y=0.5, boxes: Union[list[Box], Box, None] = None):
443450
"""
444451
如果鼠标在窗口内,则将其移动到游戏窗口内的相对位置。
445452
446453
Args:
447454
x (float): 相对 x 坐标 (0.0 到 1.0)。
448455
y (float): 相对 y 坐标 (0.0 到 1.0)。
449456
"""
450-
if box is not None:
451-
self.draw_boxes(box.name, box, "blue")
452-
if not self.is_mouse_in_window() or not self.is_mouse_in_box(box=box):
457+
if not self.is_mouse_in_window():
453458
return False
459+
if isinstance(boxes, Box):
460+
boxes = [boxes]
461+
if boxes is not None:
462+
self.draw_boxes("safe_move_box", boxes, "blue")
463+
for box in boxes:
464+
if self.is_mouse_in_box(box=box):
465+
break
466+
else:
467+
return False
454468
abs_pos = self.executor.device_manager.hwnd_window.get_abs_cords(self.width_of_screen(x),
455469
self.height_of_screen(y))
456470
win32api.SetCursorPos(abs_pos)

src/tasks/CommissionsTask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def choose_letter(self, timeout=0):
210210
action_timeout = self.action_timeout if timeout == 0 else timeout
211211
if self.commission_config.get("自动处理密函", False):
212212
if self.find_letter_interface():
213-
box = self.box_of_screen_scaled(2560, 1440, 1190, 610, 2450, 820, name="letter_drag_area", hcenter=True)
213+
box = self.box_of_screen_scaled(2560, 1440, 1170, 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)
216216
self.sleep(0.1)
@@ -240,7 +240,7 @@ def choose_letter(self, timeout=0):
240240

241241
self.wait_until(
242242
condition=lambda: not self.find_letter_interface(),
243-
post_action=lambda: self.click_btn_random(letter_btn, after_sleep=1),
243+
post_action=lambda: self.click_btn_random(letter_btn, after_sleep=1, safe_move_box=box),
244244
time_out=action_timeout,
245245
raise_if_not_found=True,
246246
)

0 commit comments

Comments
 (0)