从 PerceptionStateMachine 的 private static 辅助方法提升为公开原语,供后续 模块化重构(骨架+可插拔模块)与定制 AiScript 复用。新增 AbilityOnce: 只在进入时触发能力、不每帧重触发,修复用 Ability() 驱动死亡态时演出播完 被 Tick 无限重播的隐患(现有 PerceptionStateMachine 因 E001 死亡能力 id 为空未暴露,本次不改它,留待 T11 整体退役)。
69 lines
2.3 KiB
C#
69 lines
2.3 KiB
C#
using NUnit.Framework;
|
|
using BaseGames.AI;
|
|
using BaseGames.Enemies;
|
|
|
|
namespace BaseGames.Tests.EditMode.AI
|
|
{
|
|
public class AiStateFragmentsTests
|
|
{
|
|
static AiRuntime Run(System.Action<BrainBuilder> build, FakeAiContext ctx)
|
|
{
|
|
var b = new BrainBuilder();
|
|
b.Entry("S");
|
|
build(b);
|
|
return new AiRuntime(b.Build(), ctx);
|
|
}
|
|
|
|
[Test]
|
|
public void Locomotion_SetsModeOnEnter()
|
|
{
|
|
var ctx = new FakeAiContext();
|
|
Run(b => AiStateFragments.Locomotion(b, "S", LocomotionMode.Patrol), ctx);
|
|
Assert.AreEqual(LocomotionMode.Patrol, ctx.L.CurrentMode);
|
|
}
|
|
|
|
[Test]
|
|
public void Locomotion_FaceMode_FacesLastKnown()
|
|
{
|
|
var ctx = new FakeAiContext();
|
|
ctx.S.Last = new UnityEngine.Vector2(3f, 0f);
|
|
Run(b => AiStateFragments.Locomotion(b, "S", LocomotionMode.Face), ctx);
|
|
Assert.AreEqual(new UnityEngine.Vector2(3f, 0f), ctx.L.FacedAt);
|
|
}
|
|
|
|
[Test]
|
|
public void Ability_RetriggersOnTick_WhenNotRunning()
|
|
{
|
|
var ctx = new FakeAiContext();
|
|
var rt = Run(b => AiStateFragments.Ability(b, "S", "atk"), ctx);
|
|
Assert.AreEqual(1, ctx.C.Used.Count);
|
|
ctx.C.Running = null; // 模拟被受击打断
|
|
rt.Tick(0.1f);
|
|
Assert.AreEqual(2, ctx.C.Used.Count); // 重新触发
|
|
}
|
|
|
|
[Test]
|
|
public void AbilityOnce_DoesNotRetrigger()
|
|
{
|
|
var ctx = new FakeAiContext();
|
|
var rt = Run(b => AiStateFragments.AbilityOnce(b, "S", "death"), ctx);
|
|
Assert.AreEqual(1, ctx.C.Used.Count);
|
|
ctx.C.Running = null; // 演出播完
|
|
rt.Tick(0.1f);
|
|
rt.Tick(0.1f);
|
|
Assert.AreEqual(1, ctx.C.Used.Count); // 不重播
|
|
}
|
|
|
|
[Test]
|
|
public void LostAllZones_TrueOnlyWhenBothZonesEmpty()
|
|
{
|
|
var ctx = new FakeAiContext();
|
|
Assert.IsTrue(AiStateFragments.LostAllZones(ctx));
|
|
ctx.S.Chase = true;
|
|
Assert.IsFalse(AiStateFragments.LostAllZones(ctx));
|
|
ctx.S.Chase = false; ctx.S.Vision = true;
|
|
Assert.IsFalse(AiStateFragments.LostAllZones(ctx));
|
|
}
|
|
}
|
|
}
|