add 任务跟随模式

This commit is contained in:
王鹏
2026-03-20 10:11:05 +08:00
parent 8ad9d1b695
commit 9bcc3a467c
3 changed files with 115 additions and 6 deletions

38
quest_follow.py Normal file
View File

@@ -0,0 +1,38 @@
"""
任务跟随按固定间隔向游戏发送「跟随」与「交互」按键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}")