Add route profile patrol selection

This commit is contained in:
王鹏
2026-05-12 17:09:19 +08:00
parent 0d493ee180
commit 2a4684e700
6 changed files with 1462 additions and 185 deletions

View File

@@ -3,6 +3,7 @@ import math
import os
import time
from hardware_control import hw_ctrl
from route_profile import normalize_points
# 修理商所在位置(游戏坐标),按实际位置修改
VENDOR_POS = (30.08, 71.51)
@@ -18,6 +19,8 @@ class LogisticsManager:
self.bag_full = False
self.is_returning = False
self.route_file = route_file or VENDOR_FILE
self.route_points = []
self.route_name = ""
self.bag_full_hearthstone = False # 包满时用炉石回城而非走路修理
self.hearthstone_key = "b" # 炉石按键
self.hearthstone_cast_sec = 12.0 # 炉石施法等待秒数
@@ -26,6 +29,8 @@ class LogisticsManager:
self.bag_slot_threshold = 2
self.durability_threshold = 0.2
self.mailbox_route_file = os.path.join("recorder", "mailbox.json")
self.mailbox_route_points = []
self.mailbox_route_name = ""
self.mailbox_interact_key = "8"
self.mail_recipient_key = ""
self.mail_send_key = "f8"
@@ -46,6 +51,35 @@ class LogisticsManager:
return cwd_path
return os.path.join(os.path.dirname(os.path.abspath(__file__)), path)
def set_repair_route(self, route):
route = route or {}
self.route_name = str(route.get("name") or "修理商路线").strip()
self.route_points = normalize_points(route.get("points") or [])
def set_mailbox_route(self, route):
route = route or {}
self.mailbox_route_name = str(route.get("name") or "邮箱路线").strip()
self.mailbox_route_points = normalize_points(route.get("points") or [])
def _load_configured_route(self, configured_points, route_file, source_name, label):
points = normalize_points(configured_points or [])
if points:
return points, source_name or label
resolved_file = self._resolve_path(route_file)
if not resolved_file or not os.path.exists(resolved_file):
return None, resolved_file
try:
with open(resolved_file, "r", encoding="utf-8") as f:
data = json.load(f)
except Exception as exc:
print(f">>> [{label}] 路线读取失败: {exc}")
return None, resolved_file
points = normalize_points(data)
return points, resolved_file
def _sleep_with_stop(self, seconds, stop_check=None):
end_at = time.time() + max(0.0, float(seconds))
while time.time() < end_at:
@@ -199,9 +233,14 @@ class LogisticsManager:
炉石 -> 跑到邮箱路线终点 -> 交互打开邮箱 -> 按 MailboxCourier 宏键 -> 等待后停止。
Python 不判断邮件是否发完,发送细节交给游戏内插件。
"""
route_file = self._resolve_path(self.mailbox_route_file)
if not route_file or not os.path.exists(route_file):
print(f">>> [后勤-邮箱] 邮箱路线不存在,已停止: {route_file}")
path, route_source = self._load_configured_route(
self.mailbox_route_points,
self.mailbox_route_file,
self.mailbox_route_name,
"后勤-邮箱",
)
if not path:
print(f">>> [后勤-邮箱] 邮箱路线不存在或为空,已停止: {route_source}")
self.is_returning = False
return False
@@ -216,20 +255,7 @@ class LogisticsManager:
self.is_returning = False
return False
try:
with open(route_file, "r", encoding="utf-8") as f:
path = json.load(f)
except Exception as exc:
print(f">>> [后勤-邮箱] 邮箱路线读取失败: {exc}")
self.is_returning = False
return False
if not path:
print(f">>> [后勤-邮箱] 邮箱路线为空,已停止: {route_file}")
self.is_returning = False
return False
print(f">>> [后勤-邮箱] 开始跑邮箱路线: {route_file}")
print(f">>> [后勤-邮箱] 开始跑邮箱路线: {route_source}")
old_enable_mount = getattr(patrol, "enable_mount", None)
if old_enable_mount is not None:
patrol.enable_mount = False
@@ -282,9 +308,14 @@ class LogisticsManager:
耐久低修理流程:
炉石 -> 从修理路线最近点接入 -> 到达 NPC -> 按目标键 -> 按交互/修理键。
"""
route_file = self._resolve_path(self.route_file)
if not route_file or not os.path.exists(route_file):
print(f">>> [后勤-修理] 修理路线不存在,已停止: {route_file}")
path, route_source = self._load_configured_route(
self.route_points,
self.route_file,
self.route_name,
"后勤-修理",
)
if not path:
print(f">>> [后勤-修理] 修理路线不存在或为空,已停止: {route_source}")
self.is_returning = False
return False
@@ -299,20 +330,7 @@ class LogisticsManager:
self.is_returning = False
return False
try:
with open(route_file, "r", encoding="utf-8") as f:
path = json.load(f)
except Exception as exc:
print(f">>> [后勤-修理] 修理路线读取失败: {exc}")
self.is_returning = False
return False
if not path:
print(f">>> [后勤-修理] 修理路线为空,已停止: {route_file}")
self.is_returning = False
return False
print(f">>> [后勤-修理] 开始跑修理路线: {route_file}")
print(f">>> [后勤-修理] 开始跑修理路线: {route_source}")
ok = patrol.navigate_path(
get_state,
path,