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>
@
This commit is contained in:
2026-07-20 13:11:28 +08:00
parent 1a15473966
commit d7be0cc119
4 changed files with 111 additions and 7 deletions
@@ -27,6 +27,7 @@ namespace BaseGames.Enemies
PatrolMode = LocomotionMode.Patrol,
AlertMode = LocomotionMode.Face,
ChaseAbilityId = "e001_chase",
PatrolBetweenChases = true, // 冲刺=带冷却的冲锋:冲完→CD 期巡逻→冷却结束仍在追逐区→再冲
// DeathAbilityId 留空:死亡演出走物理状态机(EnemyBase.PerformDeath)
});
}
@@ -30,6 +30,10 @@ namespace BaseGames.Enemies
// 追击/死亡走能力(追击=接触伤害等战斗语义)
public string ChaseAbilityId;
public string DeathAbilityId;
// 追击=带冷却的冲刺能力时开启(opt-in):冲刺打完→巡逻(CD 期),冷却结束且仍在追逐区→再冲刺。
// 由冷却门控 Patrol→Chase,避免"CD 期在追逐区每帧 Chase↔Patrol 来回抖"。
public bool PatrolBetweenChases = false;
}
public static void Add(BrainBuilder b, Config c)
@@ -37,22 +41,36 @@ namespace BaseGames.Enemies
b.Entry(c.Entry);
b.Global().To(c.Death).OnEvent(AiSignal.Died); // 受击致死 → 死亡(全局最高优先)
// 进追击的条件:默认"在追逐区"。PatrolBetweenChases 时加冷却门——CD 中不回追击,
// 使 Chase(冲刺)→Patrol(CD 巡逻)→Chase 循环不抖动。
string chaseId = c.ChaseAbilityId;
System.Func<IAiContext, bool> canChase = c.PatrolBetweenChases
? (x => x.Sensor.InChaseZone() && x.Combat.CanUseAbility(chaseId))
: (x => x.Sensor.InChaseZone());
string chaseLabel = c.PatrolBetweenChases ? "InChaseZone+offCD" : "InChaseZone";
// 待机 / 巡逻:未发现态,升级转换相同(追逐优先、其次警觉)
AddLocomotionState(b, c.Idle, c.IdleMode)
.To(c.Chase).When(x => x.Sensor.InChaseZone(), "InChaseZone")
.To(c.Chase).When(canChase, chaseLabel)
.To(c.Alert).When(x => HasAlert(x) && x.Sensor.InVisionZone(), "InVision+HasAlert");
AddLocomotionState(b, c.Patrol, c.PatrolMode)
.To(c.Chase).When(x => x.Sensor.InChaseZone(), "InChaseZone")
.To(c.Chase).When(canChase, chaseLabel)
.To(c.Alert).When(x => HasAlert(x) && x.Sensor.InVisionZone(), "InVision+HasAlert");
// 警觉(仅升级路径出现):进追逐区→追击;脱离视野→R;在视野内保持(朝向玩家)
AddLocomotionState(b, c.Alert, c.AlertMode)
.To(c.Chase).When(x => x.Sensor.InChaseZone(), "InChaseZone")
.To(c.Chase).When(canChase, chaseLabel)
.To(c.Rest).When(x => !x.Sensor.InVisionZone(), "leftVision");
// 追击:脱离全部感知(追逐区 且 视野区都不在)→R(永不回警觉)。
AddAbilityState(b, c.Chase, c.ChaseAbilityId)
.To(c.Rest).When(x => !x.Sensor.InChaseZone() && !x.Sensor.InVisionZone(), "leftAllZones");
// 追击退出
// PatrolBetweenChases: 冲刺打完(能力结束)→R(CD 期巡逻);committed 冲锋不被感知丢失中途打断,
// 是否再冲刺交由 Patrol 侧冷却门控。
// 默认: 脱离全部感知(追逐区且视野区都不在)→R(永不回警觉)。
var chase = AddAbilityState(b, c.Chase, chaseId);
if (c.PatrolBetweenChases)
chase.To(c.Rest).When(x => !x.Combat.IsAbilityRunning(chaseId), "dashDone→CD");
else
chase.To(c.Rest).When(x => !x.Sensor.InChaseZone() && !x.Sensor.InVisionZone(), "leftAllZones");
// 死亡:终态(无转出);死亡演出走物理状态机
AddAbilityState(b, c.Death, c.DeathAbilityId);