feat(enemy): ApproachAttackEngagement——攻击改为起手即打完,不中途收招

寻路逼近↔到射程选招攻击的交战模块。招式射程/冷却/权重归 EnemyAttackSelector,
本模块只决定何时逼近、何时出手。

有意的行为变更:Attack 态去掉 leftAllZones 边,玩家在前摇中跑出感知区不再
中途打断招式,招式完整打完后经 Approach 自然脱战。
This commit is contained in:
2026-07-29 12:53:49 +08:00
parent 5771ac414e
commit a700bef352
4 changed files with 153 additions and 0 deletions
@@ -0,0 +1,42 @@
using System;
using BaseGames.AI;
namespace BaseGames.Enemies
{
/// <summary>
/// 寻路逼近 ↔ 到射程选招攻击。招式的射程 / 冷却 / 权重由 EnemyAttackSelector 负责,
/// 本模块只决定"什么时候该逼近、什么时候该出手"。
/// </summary>
[Serializable]
public sealed class ApproachAttackEngagement : IEngagementModule
{
public const string Approach = "Approach";
public const string Attack = "Attack";
static readonly Func<IAiContext, bool> InChaseZone = x => x.Sensor.InChaseZone();
public string EntryState => Approach;
public Func<IAiContext, bool> CanEngage => InChaseZone;
public string EngageLabel => "InChaseZone";
public void Build(BrainBuilder b, string rest)
{
b.DeclareState(Approach)
.OnEnter(x => x.Locomotion.Pursue(x.Sensor.LastKnown))
.Tick (x => x.Locomotion.Pursue(x.Sensor.LastKnown))
.OnExit(x => x.Locomotion.Stop())
// 脱战边放在前面:脱战判定优先于是否有合格攻击,避免"已经脱离全部感知区,
// 却因为攻击选择器还没来得及清掉合格标记"而卡在交战里出不去。
.To(rest) .When(AiStateFragments.LostAllZones, "leftAllZones")
.To(Attack).When(x => x.Combat.HasEligibleAttack(), "attackInRange");
// 攻击一旦起手就打完:刻意不挂 leftAllZones 边。
// 玩家在前摇中跑出感知区时招式仍完整打完,之后经 Approach 自然脱战——
// 只多一帧,且消除了"起手到一半凭空收招"的观感缺陷。
b.DeclareState(Attack)
.OnEnter(x => { x.Locomotion.Stop(); x.Combat.UseBestAttack(); })
.OnExit (x => x.Combat.InterruptAbilities())
.To(Approach).When(x => !x.Combat.IsAbilityRunning(), "attackDone");
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 59bb25c040c4705419fdd7516909acba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: