refactor(ai): IAiContext.Mover→Locomotion,删除 IMover

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-10 12:14:53 +08:00
co-authored by Claude Opus 4.8
parent f143efe4a3
commit 1ab0521061
7 changed files with 34 additions and 57 deletions
+10 -10
View File
@@ -11,12 +11,12 @@ namespace BaseGames.Tests.EditMode.AI
b.Entry("Patrol");
b.Global().To("Dead").OnEvent(AiSignal.Died);
b.State("Patrol")
.Tick(c => c.Mover.WalkRandom())
.Tick(c => c.Locomotion.SetMode(LocomotionMode.Patrol))
.To("Chase").When(c => c.Sensor.SeesPlayer(), "SeesPlayer");
b.State("Chase")
.OnEnter(c => c.Mover.FacePlayer())
.OnExit(c => c.Mover.Stop())
.Tick(c => c.Mover.MoveTo(c.Sensor.LastKnown))
.OnEnter(c => c.Locomotion.Face(c.Sensor.LastKnown))
.OnExit(c => c.Locomotion.Stop())
.Tick(c => c.Locomotion.MoveTo(c.Sensor.LastKnown))
.To("Search").When(c => c.Sensor.LostFor(2f), "LostFor(2s)");
b.State("Search")
.To("Patrol").After(3f);
@@ -37,7 +37,7 @@ namespace BaseGames.Tests.EditMode.AI
var ctx = new FakeAiContext();
var rt = new AiRuntime(Graph(), ctx);
rt.Tick(0.1f);
CollectionAssert.Contains(ctx.M.Calls, "WalkRandom");
CollectionAssert.Contains(ctx.L.Calls, "SetMode:Patrol");
}
[Test]
@@ -48,7 +48,7 @@ namespace BaseGames.Tests.EditMode.AI
ctx.S.Sees = true;
rt.Tick(0.1f);
Assert.AreEqual("Chase", rt.CurrentStateName);
CollectionAssert.Contains(ctx.M.Calls, "FacePlayer"); // Chase.OnEnter
CollectionAssert.Contains(ctx.L.Calls, "Face"); // Chase.OnEnter
}
[Test]
@@ -61,7 +61,7 @@ namespace BaseGames.Tests.EditMode.AI
rt.Tick(0.1f);
Assert.AreEqual("Patrol", rt.CurrentStateName); // 未转换
Assert.IsTrue(rt.IsSuspended);
CollectionAssert.DoesNotContain(ctx.M.Calls, "WalkRandom"); // Tick 也不跑
CollectionAssert.DoesNotContain(ctx.L.Calls, "SetMode:Patrol"); // Tick 也不跑
}
[Test]
@@ -98,7 +98,7 @@ namespace BaseGames.Tests.EditMode.AI
var rt = new AiRuntime(Graph(), ctx);
ctx.S.Sees = true; rt.Tick(0.1f); // Patrol -> Chase
ctx.S.Sees = false; ctx.S.LostForValue = 5f; rt.Tick(0.1f);// Chase -> Search (触发 Chase.OnExit)
CollectionAssert.Contains(ctx.M.Calls, "Stop");
CollectionAssert.Contains(ctx.L.Calls, "Stop");
}
[Test]
@@ -106,10 +106,10 @@ namespace BaseGames.Tests.EditMode.AI
{
var b = new BrainBuilder();
b.Entry("Start");
b.State("Start").OnEnter(c => c.Mover.LookAround());
b.State("Start").OnEnter(c => c.Locomotion.SetMode(LocomotionMode.Idle));
var ctx = new FakeAiContext();
var rt = new AiRuntime(b.Build(), ctx);
CollectionAssert.Contains(ctx.M.Calls, "LookAround");
CollectionAssert.Contains(ctx.L.Calls, "SetMode:Idle");
}
[Test]