test(enemy): 补测 Attack 单出边的自愈路径,写明边序依赖的射程前提
Approach 边序注释:attackInRange 先于 leftAllZones 的前提是攻击射程恒小于 感知区(EnemyAttackSelector.Eligible 的 InAttackRange 门),故两条件不会相争; 若未来出现射程更大的招式,应由 AI 配方校验器报错,而非靠调边序绕开。 FakeCombat 新增 BestAttackFails 开关(与 Eligible 解耦),补测 Attack 唯一出边 attackDone 的自愈不变量:UseBestAttack 触发失败时不留下运行中能力,下一帧即可 自愈回 Approach,不会永久卡死。
This commit is contained in:
@@ -88,5 +88,23 @@ namespace BaseGames.Tests.EditMode.AI
|
|||||||
rt.Tick(0.1f);
|
rt.Tick(0.1f);
|
||||||
Assert.AreEqual(Rest, rt.CurrentStateName); // 再经 Approach 自然脱战
|
Assert.AreEqual(Rest, rt.CurrentStateName); // 再经 Approach 自然脱战
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Attack_SelfHealsToApproach_WhenNothingActuallyTriggered()
|
||||||
|
{
|
||||||
|
// Attack 只有 attackDone 一条出边,安全性依赖:"UseBestAttack 失败时不会留下运行中的能力"。
|
||||||
|
// 若该不变量被破坏,敌人会永久卡在 Attack 里出不来。
|
||||||
|
var ctx = new FakeAiContext();
|
||||||
|
ctx.S.Chase = true;
|
||||||
|
ctx.C.Eligible = true;
|
||||||
|
ctx.C.BestAttackFails = true; // 够得着,但触发失败
|
||||||
|
var rt = RunAlone(ctx);
|
||||||
|
rt.Tick(0.1f);
|
||||||
|
Assert.AreEqual(ApproachAttackEngagement.Attack, rt.CurrentStateName);
|
||||||
|
Assert.IsNull(ctx.C.Running); // 什么都没启动
|
||||||
|
|
||||||
|
rt.Tick(0.1f);
|
||||||
|
Assert.AreEqual(ApproachAttackEngagement.Approach, rt.CurrentStateName); // 下一帧自愈
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,11 @@ namespace BaseGames.Tests.EditMode.AI
|
|||||||
public bool CanUseAbility(string id) => CanUse;
|
public bool CanUseAbility(string id) => CanUse;
|
||||||
public void InterruptAbilities() => Running = null;
|
public void InterruptAbilities() => Running = null;
|
||||||
public bool Eligible; // 测试控制:是否有合格攻击
|
public bool Eligible; // 测试控制:是否有合格攻击
|
||||||
|
public bool BestAttackFails; // 模拟:选招器认为够得着,但实际没触发成功
|
||||||
public bool HasEligibleAttack() => Eligible;
|
public bool HasEligibleAttack() => Eligible;
|
||||||
public bool UseBestAttack()
|
public bool UseBestAttack()
|
||||||
{
|
{
|
||||||
if (!Eligible) return false;
|
if (!Eligible || BestAttackFails) return false;
|
||||||
Used.Add("best"); Running = "best"; return true;
|
Used.Add("best"); Running = "best"; return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ namespace BaseGames.Enemies
|
|||||||
.OnEnter(x => x.Locomotion.Pursue(x.Sensor.LastKnown))
|
.OnEnter(x => x.Locomotion.Pursue(x.Sensor.LastKnown))
|
||||||
.Tick (x => x.Locomotion.Pursue(x.Sensor.LastKnown))
|
.Tick (x => x.Locomotion.Pursue(x.Sensor.LastKnown))
|
||||||
.OnExit(x => x.Locomotion.Stop())
|
.OnExit(x => x.Locomotion.Stop())
|
||||||
|
// 边序:attackInRange 先于 leftAllZones。前提是攻击射程恒小于感知区
|
||||||
|
// (EnemyAttackSelector.Eligible 的 InAttackRange 门),故"够得着"不会在
|
||||||
|
// "已脱离全部感知"之后仍成立,两条件不会相争。若将来出现射程大于追击区的招式,
|
||||||
|
// 那属于射程/感知区配置错误,由 AI 配方校验器报出,不要靠调整此处边序绕开。
|
||||||
.To(Attack).When(x => x.Combat.HasEligibleAttack(), "attackInRange")
|
.To(Attack).When(x => x.Combat.HasEligibleAttack(), "attackInRange")
|
||||||
.To(rest) .When(AiStateFragments.LostAllZones, "leftAllZones");
|
.To(rest) .When(AiStateFragments.LostAllZones, "leftAllZones");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user