ResourceFull 未挂 BossResource 时改为显式抛——原先静默返回 false, 是 CLAUDE.md 第 6 条禁止的下游兜底,且与紧邻的 Boss facet 行为不一致。 FakeBossControl.DistanceToAnchor 不再忽略 index。测试改用 TearDown 清理 (本项目关闭了 Domain/Scene Reload,失败断言会把物体永久留在打开的场景里)。 BeginPhaseTransition 去掉死的默认参数;接口补充重入契约说明。 顺带去重:FakeAiContext 实现 IEnemyActor,删除两个测试内的本地 Ctx 副本 ——一个接口成员改动要同步三份是复发性成本。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
66 lines
2.7 KiB
C#
66 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using BaseGames.AI;
|
|
using BaseGames.Enemies;
|
|
|
|
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, IEnemyActor
|
|
{
|
|
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 FakeBossControl B = new FakeBossControl();
|
|
public bool HasAlert = true;
|
|
public ISensor Sensor => S;
|
|
public IEnemyLocomotion Locomotion => L;
|
|
public ICombatant Combat => C;
|
|
public IActorVitals Vitals => V;
|
|
public Blackboard Blackboard => BB;
|
|
public IBossControl Boss => B;
|
|
public bool HasAlertState => HasAlert;
|
|
}
|
|
}
|