39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
|
|
"""
|
|||
|
|
任务跟随:按固定间隔向游戏发送「跟随」与「交互」按键(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}")
|