fix(enemy): Approach 逼近改用 aggro/视野双刷新的 LastKnown(修 aggro 先命中扑向错误点)+补 Attack 退出测试

This commit is contained in:
2026-07-24 12:47:48 +08:00
parent f77ab71555
commit 022e4f18d2
3 changed files with 35 additions and 9 deletions
@@ -357,6 +357,33 @@ namespace BaseGames.Tests.EditMode.AI
Assert.AreEqual("Death", rt.CurrentStateName);
}
// 进 Attack 后玩家脱离全部感知区:攻击仍在跑 → 不回 Approach,改判 leftAllZones → Rest(Patrol)。
[Test]
public void Attack_ToRest_WhenLeftAllZones()
{
var ctx = new Ctx();
var rt = new AiRuntime(GraphApproach(), ctx);
ctx.S.Chase = true; rt.Tick(0.1f); // → Approach
ctx.C.Eligible = true; rt.Tick(0.1f); // → Attack, Running="best"
Assert.AreEqual("Attack", rt.CurrentStateName);
ctx.S.Chase = false; ctx.S.Vision = false; // 攻击仍 running,但脱离全部感知
rt.Tick(0.1f);
Assert.AreEqual("Patrol", rt.CurrentStateName);
}
// 死亡是全局事件,从 Attack 态也能达 Death。
[Test]
public void ApproachAttack_Death_FromAttack()
{
var ctx = new Ctx();
var rt = new AiRuntime(GraphApproach(), ctx);
ctx.S.Chase = true; rt.Tick(0.1f); // → Approach
ctx.C.Eligible = true; rt.Tick(0.1f); // → Attack
Assert.AreEqual("Attack", rt.CurrentStateName);
rt.Send(AiSignal.Died); rt.Tick(0.1f);
Assert.AreEqual("Death", rt.CurrentStateName);
}
// ── 死亡(全局事件,任意态可达)───────────────────────────────────
[Test]