fix(enemy): AiStateFragments 空能力 id 建图期报错,补 OnExit 收尾测试
Ability/AbilityOnce 建图期校验 abilityId 非空,与 BrainBuilder.RequireState 同一类"漏配即快速失败"约束保持一致,避免定制 AiScript 漏配 id 时产出静默 不作为的状态。同时补 4 个测试:Locomotion/Ability 的 OnExit 收尾行为,以及 两个原语对空 id 的报错行为。
This commit is contained in:
@@ -64,5 +64,55 @@ namespace BaseGames.Tests.EditMode.AI
|
||||
ctx.S.Chase = false; ctx.S.Vision = true;
|
||||
Assert.IsFalse(AiStateFragments.LostAllZones(ctx));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Locomotion_StopsOnExit()
|
||||
{
|
||||
var ctx = new FakeAiContext();
|
||||
var b = new BrainBuilder();
|
||||
b.Entry("S");
|
||||
AiStateFragments.Locomotion(b, "S", LocomotionMode.Patrol)
|
||||
.To("Out").When(x => x.Sensor.InChaseZone(), "leave");
|
||||
AiStateFragments.Terminal(b, "Out");
|
||||
var rt = new AiRuntime(b.Build(), ctx);
|
||||
Assert.AreEqual(LocomotionMode.Patrol, ctx.L.CurrentMode);
|
||||
|
||||
ctx.S.Chase = true;
|
||||
rt.Tick(0.1f);
|
||||
Assert.AreEqual("Out", rt.CurrentStateName);
|
||||
CollectionAssert.Contains(ctx.L.Calls, "Stop"); // 离开时收尾
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ability_InterruptsOnExit()
|
||||
{
|
||||
var ctx = new FakeAiContext();
|
||||
var b = new BrainBuilder();
|
||||
b.Entry("S");
|
||||
AiStateFragments.Ability(b, "S", "atk")
|
||||
.To("Out").When(x => x.Sensor.InChaseZone(), "leave");
|
||||
AiStateFragments.Terminal(b, "Out");
|
||||
var rt = new AiRuntime(b.Build(), ctx);
|
||||
Assert.AreEqual("atk", ctx.C.Running);
|
||||
|
||||
ctx.S.Chase = true;
|
||||
rt.Tick(0.1f);
|
||||
Assert.AreEqual("Out", rt.CurrentStateName);
|
||||
Assert.IsNull(ctx.C.Running); // InterruptAbilities() 已清空
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ability_Throws_WhenAbilityIdEmpty()
|
||||
{
|
||||
var b = new BrainBuilder();
|
||||
Assert.Throws<System.ArgumentException>(() => AiStateFragments.Ability(b, "S", ""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AbilityOnce_Throws_WhenAbilityIdNull()
|
||||
{
|
||||
var b = new BrainBuilder();
|
||||
Assert.Throws<System.ArgumentException>(() => AiStateFragments.AbilityOnce(b, "S", null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user