77import win32con
88from datetime import datetime , timedelta
99from concurrent .futures import ThreadPoolExecutor
10+ from functools import cached_property
1011
11- from ok import BaseTask , Box , Logger , color_range_to_bound , run_in_new_thread , og
12+ from ok import BaseTask , Box , Logger , color_range_to_bound , run_in_new_thread , og , GenshinInteraction
1213
1314logger = Logger .get_logger (__name__ )
1415f_black_color = {
@@ -73,6 +74,7 @@ def __init__(self, *args, **kwargs):
7374 self .old_mouse_pos = None
7475 self .next_monthly_card_start = 0
7576 self ._logged_in = False
77+ self .sensitivity_config = self .get_global_config ('Game Sensitivity Config' ) # 游戏灵敏度配置
7678
7779 @property
7880 def f_search_box (self ) -> Box :
@@ -87,6 +89,15 @@ def f_search_box(self) -> Box:
8789 @property
8890 def thread_pool_executor (self ) -> ThreadPoolExecutor :
8991 return og .my_app .get_thread_pool_executor ()
92+
93+ @cached_property
94+ def genshin_interaction (self ):
95+ """
96+ 缓存 Interaction 实例,避免每次鼠标移动都重新创建对象。
97+ 需要确保 self.executor.interaction 和 self.hwnd 在此类初始化时可用。
98+ """
99+ # 确保引用的是正确的类
100+ return GenshinInteraction (self .executor .interaction .capture , self .hwnd )
90101
91102 def in_team (self ) -> bool :
92103 frame = self .frame
@@ -380,7 +391,39 @@ def get_spiral_dive_key(self):
380391 str: 螺旋飞跃的按键字符串。
381392 """
382393 return self .key_config ['HelixLeap Key' ]
383-
394+
395+ def calculate_sensitivity (self , dx , dy , original_Xsensitivity = 1.0 , original_Ysensitivity = 1.0 ):
396+ """计算玩家水平鼠标移动值和垂直鼠标移动值,并且移动鼠标.
397+
398+ Returns:
399+ int: 玩家水平鼠标移动值
400+ int: 玩家垂直鼠标移动值
401+
402+ """
403+ # 判断设置中灵敏度开关是否打开
404+ if self .sensitivity_config ['Game Sensitivity Switch' ]:
405+ # 获取设置中的游戏灵敏度
406+ game_Xsensitivity = round (self .sensitivity_config ['X-axis sensitivity' ], 1 )
407+ game_Ysensitivity = round (self .sensitivity_config ['Y-axis sensitivity' ], 1 )
408+
409+ # 判断和计算
410+ if original_Xsensitivity == game_Xsensitivity and original_Ysensitivity == game_Ysensitivity :
411+ calculate_dx = dx
412+ calculate_dy = dy
413+ else :
414+ calculate_dx = dx / round (game_Xsensitivity / original_Xsensitivity , 10 )
415+ calculate_dy = dy / round (game_Ysensitivity / original_Ysensitivity , 10 )
416+ else :
417+ calculate_dx = dx
418+ calculate_dy = dy
419+
420+ return calculate_dx , calculate_dy
421+
422+ def move_mouse_relative (self , dx , dy , original_Xsensitivity = 1.0 , original_Ysensitivity = 1.0 ):
423+ dx , dy = self .calculate_sensitivity (dx , dy , original_Xsensitivity , original_Ysensitivity )
424+ self .try_bring_to_front ()
425+ self .genshin_interaction .move_mouse_relative (int (dx ), int (dy ))
426+
384427 def try_bring_to_front (self ):
385428 if not self .hwnd .is_foreground ():
386429 win32api .keybd_event (win32con .VK_MENU , 0 , 0 , 0 )
0 commit comments