Pārlūkot izejas kodu

feat(safety): 全部战斗任务入口强制喝药防线 — 高危图(矿区/蜈蚣/沃玛)非 on 拒跑, 单任务补跑不再裸奔送死

wuzilong 1 mēnesi atpakaļ
vecāks
revīzija
5a88bee311

+ 32 - 0
pipeline_bot/pipeline/tasks/heal_guard.py

@@ -0,0 +1,32 @@
+"""heal_guard — 战斗任务共用的喝药防线。
+
+每个战斗任务(t02-t05/t08)入口调用 ensure_heal(ctx):
+读态已 on → 零帧直返; off → 切一次验证; 高危图(沃玛/蜈蚣)验证失败
+即拒绝开跑(裸奔送死 — 2026-10-01 姚孤沃玛双杀双死实证)。
+"""
+from __future__ import annotations
+
+from pbot.game.heal import enable_auto_heal
+from pipeline.ctx import PipelineContext, TaskResult
+
+_HIGH_RISK_FAIL = "高危图喝药保护未开启 — 拒绝开跑(防裸奔送死)"
+
+
+def ensure_heal(ctx: PipelineContext, high_risk: bool = False) -> TaskResult | None:
+    """确保喝药保护 on。
+
+    返回 None=已 on 可继续; 返回 TaskResult=失败(detail 含状态),
+    high_risk=True 时读态任何非 on 都拒绝, 否则告警放行(低危图)。
+    """
+    state = None
+    for _ in range(2):
+        state = enable_auto_heal(ctx.conn, ctx.sid, want_on=True,
+                                 world=ctx.world)
+        if state == "on":
+            ctx.log.info("[喝药✓] on")
+            return None
+        ctx.log.warning("[喝药✗] state=%s — 重试一轮", state)
+    if high_risk or state == "off":
+        return TaskResult.fail(f"{_HIGH_RISK_FAIL}(终态={state})")
+    ctx.log.warning("[喝药?] 终态=%s(低危图继续)", state)
+    return None

+ 5 - 0
pipeline_bot/pipeline/tasks/t02_biqi_kill20.py

@@ -31,10 +31,15 @@ def run_task(ctx: PipelineContext) -> TaskResult:
     from pbot.bot.kill import KillBehavior
     from pbot.bot.pathfind import load_walls_from_map
     from pbot.bot.runner import pump, run
+    from pipeline.tasks.heal_guard import ensure_heal
 
     root = Path(__file__).resolve().parents[2]
     walls = load_walls_from_map(str(root / "assets/maps/0.map"))
 
+    failed = ensure_heal(ctx)
+    if failed is not None:
+        return failed
+
     def _teleport(timeout_s: float = 120.0) -> bool:
         """Renwu 链传比奇; 到图即停(手动泵循环, 不靠 run 超时)。"""
         bh = KillBehavior(sid=ctx.sid, kill_target=0, land_only=True,

+ 5 - 0
pipeline_bot/pipeline/tasks/t03_cave_kill20.py

@@ -30,10 +30,15 @@ def run_task(ctx: PipelineContext) -> TaskResult:
     from pbot.bot.kill import KillBehavior
     from pbot.bot.pathfind import load_walls_from_map
     from pbot.bot.runner import pump, run
+    from pipeline.tasks.heal_guard import ensure_heal
 
     root = Path(__file__).resolve().parents[2]
     walls = load_walls_from_map(str(root / "assets/maps/d011.map"))
 
+    failed = ensure_heal(ctx)
+    if failed is not None:
+        return failed
+
     def _teleport(timeout_s: float = 120.0) -> bool:
         """Renwu 链传天然洞穴; 到图即停(手动泵循环, 不靠 run 超时)。"""
         bh = KillBehavior(sid=ctx.sid, kill_target=0, land_only=True,

+ 5 - 0
pipeline_bot/pipeline/tasks/t04_mine_kill20.py

@@ -27,8 +27,13 @@ def run_task(ctx: PipelineContext) -> TaskResult:
     from run_juece13_wugong_autofight import AutoFightBehavior
 
     from pbot.bot.runner import pump, run
+    from pipeline.tasks.heal_guard import ensure_heal
 
     walls = _d401_walls()
+
+    failed = ensure_heal(ctx, high_risk=True)
+    if failed is not None:
+        return failed
     total = 0
     for rnd in range(1, _MAX_ROUNDS + 1):
         if ctx.world.me.map_name != MINE_MAP:

+ 5 - 0
pipeline_bot/pipeline/tasks/t05_wugong_kill40.py

@@ -29,6 +29,7 @@ def run_task(ctx: PipelineContext) -> TaskResult:
     )
 
     from pbot.bot.runner import pump, run
+    from pipeline.tasks.heal_guard import ensure_heal
 
     # 防御性复位: t08 会覆写同模块常量为沃玛参数; 重跑/乱序时先还原蜈蚣默认
     wugong_mod = importlib.import_module("run_juece13_wugong_farthest")
@@ -37,6 +38,10 @@ def run_task(ctx: PipelineContext) -> TaskResult:
     wugong_mod._TELEPORT_ACTS = ("@jiuxian_move_1,1,2", "@act_move,1")  # noqa: SLF001
 
     walls = _cave_walls()
+
+    failed = ensure_heal(ctx, high_risk=True)
+    if failed is not None:
+        return failed
     total = 0
     for rnd in range(1, _MAX_ROUNDS + 1):
         if ctx.world.me.map_name != WUGONG_MAP:

+ 6 - 0
pipeline_bot/pipeline/tasks/t08_woma_farm.py

@@ -63,6 +63,7 @@ def run_task(ctx: PipelineContext) -> TaskResult:
     from pbot.bot.behavior import TickResult
     from pbot.bot.pathfind import load_walls_from_map
     from pbot.bot.runner import pump, run
+    from pipeline.tasks.heal_guard import ensure_heal
 
     # 沃玛参数覆写(CaveEnterBehavior 运行时读模块全局;
     # cap_woma_client 定案: ACK body=协议别名, 第二步 @act_move,3)
@@ -71,6 +72,11 @@ def run_task(ctx: PipelineContext) -> TaskResult:
     cave_mod._TELEPORT_ACTS = ("@jiuxian_move_1,1,3", "@act_move,3")  # noqa: SLF001
 
     walls = load_walls_from_map(str(root / "assets/maps/d022.map"))
+
+
+    failed = ensure_heal(ctx, high_risk=True)
+    if failed is not None:
+        return failed
     farthest = _make_farthest(walls)
     deadline = time.time() + ctx.woma_minutes * 60.0
     total = 0