@@ -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 )
0 commit comments