feat(ai): 追击冲刺带冷却——CD 期巡逻,冷却结束仍在追逐区则再冲(PatrolBetweenChases) 按需求:冲刺打完 → CD 期切到巡逻(Move_Patrol) → 冷却结束且玩家仍在追逐区 → 再冲刺。 PerceptionStateMachine 加 opt-in 开关 PatrolBetweenChases: - Chase → Patrol When !IsAbilityRunning(chase):冲刺是 committed 冲锋,感知丢失 也不中途打断,打完(能力结束)即降巡逻。 - Idle/Patrol/Alert → Chase 加冷却门 CanUseAbility(chase):CD 中不回追击, 避免"CD 期在追逐区每帧 Chase↔Patrol 来回抖"(用户担心的错切/抖动)。 - 默认关:不影响其他敌人(leftAllZones 旧行为保留)。 E001CaoZhiAi 打开开关。追击能力保持单次冲刺不变,冷却=ABL_E001_Chase.cooldown(1s)。 测试:PerceptionStateMachineTests +5(CD 转换矩阵含"CD 期多帧不抖动"负例), FakeCombat 加可控 CanUse。全量 75/75 绿。PlayMode 实测循环 Move_Patrol(CD)→Chase(冲)→Move_Patrol,inChase 全程 true 亦不抖,0 报错。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> @
53 lines
2.0 KiB
C#
53 lines
2.0 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 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;
|
|
}
|
|
}
|