Approach 边序注释:attackInRange 先于 leftAllZones 的前提是攻击射程恒小于 感知区(EnemyAttackSelector.Eligible 的 InAttackRange 门),故两条件不会相争; 若未来出现射程更大的招式,应由 AI 配方校验器报错,而非靠调边序绕开。 FakeCombat 新增 BestAttackFails 开关(与 Eligible 解耦),补测 Attack 唯一出边 attackDone 的自愈不变量:UseBestAttack 触发失败时不留下运行中能力,下一帧即可 自愈回 Approach,不会永久卡死。
61 lines
2.5 KiB
C#
61 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using BaseGames.AI;
|
|
|
|
namespace BaseGames.Tests.EditMode.AI
|
|
{
|
|
public sealed class FakeSensor : ISensor
|
|
{
|
|
public bool Sees; public float LostForValue; public Vector2 Last;
|
|
public bool Chase; public bool Vision;
|
|
public bool InChaseZone() => Chase;
|
|
public bool InVisionZone() => Vision;
|
|
public bool SeesPlayer() => Sees;
|
|
public bool InRange(float range) => Sees; // 简化:可见即在范围
|
|
public bool LostFor(float seconds) => LostForValue >= seconds;
|
|
public Vector2 LastKnown => Last;
|
|
}
|
|
|
|
public sealed class FakeCombat : ICombatant
|
|
{
|
|
public string Running; public List<string> Used = new List<string>();
|
|
public bool CanUse = true; // 供 CD 门控测试控制(默认可用,向后兼容)
|
|
public bool UseAbility(string id) { Used.Add(id); Running = id; return true; }
|
|
public bool IsAbilityRunning(string id = null) => id == null ? Running != null : Running == id;
|
|
public bool NoAbilityRunning => Running == null;
|
|
public bool CanUseAbility(string id) => CanUse;
|
|
public void InterruptAbilities() => Running = null;
|
|
public bool Eligible; // 测试控制:是否有合格攻击
|
|
public bool BestAttackFails; // 模拟:选招器认为够得着,但实际没触发成功
|
|
public bool HasEligibleAttack() => Eligible;
|
|
public bool UseBestAttack()
|
|
{
|
|
if (!Eligible || BestAttackFails) return false;
|
|
Used.Add("best"); Running = "best"; return true;
|
|
}
|
|
}
|
|
|
|
public sealed class FakeVitals : IActorVitals
|
|
{
|
|
public bool Alive = true; public bool Controllable = true; public float Hp = 1f;
|
|
public bool IsAlive => Alive;
|
|
public bool IsControllable => Controllable;
|
|
public float HpPercent => Hp;
|
|
public bool HpBelow(float ratio) => Hp < ratio;
|
|
}
|
|
|
|
public sealed class FakeAiContext : IAiContext
|
|
{
|
|
public FakeSensor S = new FakeSensor();
|
|
public FakeLocomotion L = new FakeLocomotion();
|
|
public FakeCombat C = new FakeCombat();
|
|
public FakeVitals V = new FakeVitals();
|
|
public Blackboard BB = new Blackboard();
|
|
public ISensor Sensor => S;
|
|
public IEnemyLocomotion Locomotion => L;
|
|
public ICombatant Combat => C;
|
|
public IActorVitals Vitals => V;
|
|
public Blackboard Blackboard => BB;
|
|
}
|
|
}
|