Skip to content

Commit ca9df0f

Browse files
committed
♻️ refactor(jitter): 移动鼠标抖动逻辑至基础任务
- 将 `setup_jitter` 方法从 `CommissionsTask` 移动到 `BaseDNATask`
1 parent 0b80ab2 commit ca9df0f

2 files changed

Lines changed: 40 additions & 40 deletions

File tree

src/tasks/BaseDNATask.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,46 @@ def try_bring_to_front(self):
521521
self.sleep(1)
522522
else:
523523
raise Exception("Failed to bring window to front after multiple retries.")
524+
525+
def setup_jitter(self):
526+
def _jitter_loop_task():
527+
current_drift = [0, 0]
528+
if self.executor.current_task:
529+
self.log_info("jitter loop task start")
530+
while self.executor.current_task is not None and not self.executor.exit_event.is_set():
531+
if self.executor.paused:
532+
time.sleep(0.1)
533+
continue
534+
if self.afk_config.get("鼠标抖动强制在游戏窗口内", True):
535+
self.set_mouse_in_window()
536+
537+
dist_sq = current_drift[0]**2 + current_drift[1]**2
538+
539+
# 距离原点太近(<2px) -> 往外润 (3~5px)
540+
if dist_sq < 4:
541+
target_x = random.choice([-3, -2, 2, 3])
542+
target_y = random.choice([-3, -2, 2, 3])
543+
# 距离原点太远 -> 往回拉 (目标是原点附近的 -1~1px)
544+
else:
545+
target_x = random.randint(-1, 1)
546+
target_y = random.randint(-1, 1)
547+
548+
move_x = target_x - current_drift[0]
549+
move_y = target_y - current_drift[1]
550+
551+
if move_x != 0 or move_y != 0:
552+
self.genshin_interaction.do_move_mouse_relative(move_x, move_y)
553+
current_drift[0] += move_x
554+
current_drift[1] += move_y
555+
556+
deadline = time.time() + random.uniform(3.0, 6.0)
557+
while time.time() < deadline:
558+
if self.executor.current_task is None or self.executor.exit_event.is_set():
559+
self.log_info("jitter loop task stopped")
560+
return
561+
time.sleep(0.1)
562+
563+
self.thread_pool_executor.submit(_jitter_loop_task)
524564

525565
track_point_color = {
526566
"r": (121, 255), # Red range

src/tasks/CommissionsTask.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -361,46 +361,6 @@ def action():
361361
self.get_current_char().send_geniemon_key()
362362

363363
return self.create_ticker(action, interval=lambda: self.config.get("技能释放频率", 5), interval_random_range=(0.8, 1.2))
364-
365-
def setup_jitter(self):
366-
def _jitter_loop_task():
367-
current_drift = [0, 0]
368-
if self.executor.current_task:
369-
self.log_info("jitter loop task start")
370-
while self.executor.current_task is not None and not self.executor.exit_event.is_set():
371-
if self.executor.paused:
372-
time.sleep(0.1)
373-
continue
374-
if self.afk_config.get("鼠标抖动强制在游戏窗口内", True):
375-
self.set_mouse_in_window()
376-
377-
dist_sq = current_drift[0]**2 + current_drift[1]**2
378-
379-
# 距离原点太近(<2px) -> 往外润 (3~5px)
380-
if dist_sq < 4:
381-
target_x = random.choice([-3, -2, 2, 3])
382-
target_y = random.choice([-3, -2, 2, 3])
383-
# 距离原点太远 -> 往回拉 (目标是原点附近的 -1~1px)
384-
else:
385-
target_x = random.randint(-1, 1)
386-
target_y = random.randint(-1, 1)
387-
388-
move_x = target_x - current_drift[0]
389-
move_y = target_y - current_drift[1]
390-
391-
if move_x != 0 or move_y != 0:
392-
self.genshin_interaction.do_move_mouse_relative(move_x, move_y)
393-
current_drift[0] += move_x
394-
current_drift[1] += move_y
395-
396-
deadline = time.time() + random.uniform(3.0, 6.0)
397-
while time.time() < deadline:
398-
if self.executor.current_task is None or self.executor.exit_event.is_set():
399-
self.log_info("jitter loop task stopped")
400-
return
401-
time.sleep(0.1)
402-
403-
self.thread_pool_executor.submit(_jitter_loop_task)
404364

405365
def get_round_info(self):
406366
"""获取并更新当前轮次信息。"""

0 commit comments

Comments
 (0)