Files
wow/quest_follow.py
2026-03-20 10:11:05 +08:00

39 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
任务跟随按固定间隔向游戏发送「跟随」与「交互」按键pydirectinput与 auto_bot 一致)。
"""
import time
import pydirectinput
class QuestFollowBot:
"""每隔 interval_sec 秒依次按下跟随键、交互键;不读取游戏状态。"""
def __init__(
self,
follow_key="f",
interact_key="4",
interval_sec=3.0,
log_callback=None,
):
self.follow_key = (follow_key or "f").strip().lower() or "f"
self.interact_key = (interact_key or "4").strip().lower() or "4"
self.interval_sec = max(0.5, float(interval_sec))
self._last_cycle = 0.0
self._log = log_callback or (lambda _m: None)
def execute_logic(self, state):
"""state 可为 None仅用于与时间间隔配合的定时按键。"""
now = time.time()
if now - self._last_cycle < self.interval_sec:
return
self._last_cycle = now
try:
pydirectinput.press(self.follow_key)
time.sleep(0.08)
pydirectinput.press(self.interact_key)
self._log(f"➡️ 任务跟随: {self.follow_key}{self.interact_key}")
except Exception as e:
self._log(f"❌ 任务跟随按键失败: {e}")