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

@@ -14,6 +14,7 @@ from game_state import parse_game_state, load_layout_config
from coordinate_patrol import CoordinatePatrol
from death_manager import DeathManager
from logistics_manager import LogisticsManager
from route_profile import load_route_profile
# 定义按键常量
KEY_TAB = '3'
@@ -239,6 +240,7 @@ class AutoBotMove:
self,
waypoints=None,
waypoints_path=None,
route_profile_path=None,
prepare_route_path=None,
vendor_path=None,
attack_loop_path=None,
@@ -289,11 +291,35 @@ class AutoBotMove:
self.logistics_resume_cooldown_until = 0.0
# stop_check: 返回 True 表示需要立即停止(用于中断阻塞中的后勤/路线导航)
self._stop_check = stop_check if callable(stop_check) else (lambda: False)
if waypoints is None:
self.route_profile = None
self.route_profile_name = ""
self.patrol_routes = []
self.current_patrol_route_name = ""
if route_profile_path:
self.route_profile = load_route_profile(route_profile_path)
self.route_profile_name = self.route_profile.get("name") or ""
self.patrol_routes = list(self.route_profile.get("patrol_routes") or [])
if self.patrol_routes:
waypoints = self.patrol_routes[0]["points"]
prepare_route = self.route_profile.get("prepare_route")
if prepare_route:
self.prepare_route_waypoints = list(prepare_route["points"])
else:
self.prepare_route_waypoints = []
print(
f">>> [路线方案] 已加载: {self.route_profile_name}"
f"巡逻路线 {len(self.patrol_routes)}"
)
elif waypoints is None:
path = waypoints_path or get_config_path(WAYPOINTS_FILE)
waypoints = load_waypoints(path) or DEFAULT_WAYPOINTS
self.prepare_route_waypoints = []
if prepare_route_path:
self.prepare_route_waypoints = []
else:
self.prepare_route_waypoints = []
if (not route_profile_path) and prepare_route_path:
try:
self.prepare_route_waypoints = [
(float(point[0]), float(point[1]))
@@ -320,11 +346,17 @@ class AutoBotMove:
resurrection_waypoints_path=resurrection_waypoints_path,
resurrection_route_a_path=resurrection_route_a_path,
resurrection_route_b_path=resurrection_route_b_path,
resurrection_routes=(
self.route_profile.get("resurrection_routes") if self.route_profile else None
),
release_spirit_key=layout.get('release_spirit_key', '9') if release_spirit_key is None else release_spirit_key,
resurrect_key=layout.get('resurrect_key', '0') if resurrect_key is None else resurrect_key,
)
vendor_file = vendor_path or get_config_path('vendor.json')
self.logistics_manager = LogisticsManager(vendor_file)
if self.route_profile:
self.logistics_manager.set_repair_route(self.route_profile.get("vendor_route"))
self.logistics_manager.set_mailbox_route(self.route_profile.get("mailbox_route"))
self.logistics_manager.bag_full_hearthstone = bool(layout.get("bag_full_hearthstone", False))
self.logistics_manager.hearthstone_key = str(layout.get("hearthstone_key", "b") or "b")
self.logistics_manager.hearthstone_cast_sec = float(layout.get("hearthstone_wait_sec", 12.0))
@@ -345,6 +377,31 @@ class AutoBotMove:
self.logistics_manager.mailbox_open_wait_sec = float(layout.get("mailbox_open_wait_sec", 2.0))
self.logistics_manager.mail_send_wait_sec = float(layout.get("mail_send_wait_sec", 60.0))
if self.patrol_routes and self.prepare_route_completed:
self._select_random_patrol_route("启动")
def _select_random_patrol_route(self, reason=""):
if not self.patrol_routes:
return False
route = random.choice(self.patrol_routes)
points = list(route.get("points") or [])
if not points:
return False
self.current_patrol_route_name = str(route.get("name") or "未命名巡逻路线")
reverse_route = random.choice((False, True))
direction_name = "逆向" if reverse_route else "正向"
if reverse_route:
points = list(reversed(points))
self.patrol_controller.waypoints = points
self.patrol_controller.current_index = 0
self.patrol_controller.reset_stuck()
prefix = f"{reason}" if reason else ""
print(
f">>> [巡逻路线] {prefix}随机选择: "
f"{self.current_patrol_route_name},方向: {direction_name}{len(points)} 点)"
)
return True
def _has_prepare_route(self) -> bool:
return bool(self.prepare_route_waypoints)
@@ -364,6 +421,7 @@ class AutoBotMove:
if self.prepare_route_waypoints:
print(">>> [后勤] 全自动续跑:重置准备路线,准备返回巡逻。")
else:
self._select_random_patrol_route("后勤返回")
print(">>> [后勤] 全自动续跑:未配置准备路线,直接恢复巡逻。")
def _snap_prepare_route_to_nearest(self, state):
@@ -418,6 +476,7 @@ class AutoBotMove:
self.is_moving = False
self.patrol_controller.stop_all()
self.patrol_controller.reset_stuck()
self._select_random_patrol_route("准备路线完成")
print(">>> [准备路线] 准备路线完成,开始正式巡逻...")
return
@@ -443,6 +502,7 @@ class AutoBotMove:
self.is_moving = False
self.patrol_controller.stop_all()
self.patrol_controller.reset_stuck()
self._select_random_patrol_route("准备路线完成")
print(">>> [准备路线] 准备路线完成,开始正式巡逻...")
def _is_effective_target(self, state) -> bool: