Start the cooldown at a burst's first unrefused round; refused charged weapons never charge

A burst whose every round is refused fires nothing and leaves no cooldown: the cooldown moves from
Trigger to the first round Execute does not refuse, and CanFire holds a triggered burst that has not
yet fired. ChargedWeapon.Activate asks FireControl before it starts charging, so a refused weapon pays
no charge heat or audio. InReach is deleted: Designated carries the one range test and the lock gate,
and Combat reads it. GuidedProjectile answers Resolve while alive and keeps its binding through the
shot's flight time, so a faded round still shows the simulation's detonation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-29 21:16:52 +02:00
commit 136fddf15a
7 changed files with 113 additions and 27 deletions

View file

@ -35,6 +35,7 @@ public class GuidedProjectile : MonoBehaviour
private float _prevDist;
private bool _active;
private bool _alive;
private float _spawnTime;
private Vector3 _targetVelocity;
private Vector3 _previousTargetPosition;
@ -46,6 +47,11 @@ public class GuidedProjectile : MonoBehaviour
public Vector3 Velocity { get; set; }
public Entity SourceEntity { get; set; }
// How long after spawn the round keeps its binding to the simulation's verdict: the shot's own flight time (the
// manager sets it from the committed shot's ArrivalTime), so a round that faded out early still lives to show
// the detonation the simulation resolves at arrival. 0 (the default) kills the round when its fade ends.
public float BindingLifetime { get; set; }
public event Action OnKill;
// The simulation's verdict on this round, bound by GuidedProjectileManager to Zone.ShotCommitted and
@ -83,12 +89,15 @@ public class GuidedProjectile : MonoBehaviour
// one whose target is gone) just falls away, with no explosion to show.
public void Resolve(bool detonated, Vector3? point)
{
if (!_alive || !_active) return;
// A round that already faded out (overshot, out of flight) still shows the simulation's detonation: only a
// round that has been killed is done. The fade is stopped so it cannot Kill the round a second time.
if (!_alive) return;
if (!detonated)
{
StartCoroutine(FadeOut());
if (_active) StartCoroutine(FadeOut());
return;
}
StopAllCoroutines();
if (point.HasValue) transform.position = point.Value;
if (HitEffect != null)
{
@ -101,6 +110,7 @@ public class GuidedProjectile : MonoBehaviour
void OnEnable()
{
_active = _alive = true;
_spawnTime = Time.time;
_phase = Random.value * 100;
_prevDist = Single.MaxValue;
Particles.startColor = Color.white;
@ -212,6 +222,8 @@ public class GuidedProjectile : MonoBehaviour
yield return null;
}
// Faded, but the simulation's verdict has not necessarily arrived: wait for it until the shot's flight is over.
while (Time.time - _spawnTime < BindingLifetime) yield return null;
StartCoroutine(Kill());
}

View file

@ -19,6 +19,9 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
zone.ShotResolved.Where(o => o.ShotId == shotId)
.Subscribe(o => p.Resolve(o.Result == ShotResult.Hit || o.Result == ShotResult.Burst, o.HasBurstPoint ? At(o) : (Vector3?) null))
.AddTo(bindings);
// The binding outlives a fade-out until the shot's own arrival (the moment the simulation resolves it), plus a
// second of margin; a shot no longer pending has nothing left to resolve.
p.BindingLifetime = zone.TryGetShot(shotId, out var shot) ? max(0f, shot.ArrivalTime - zone.Time) + 1f : 0f;
p.Binding = bindings; // replaces, and so disposes, any binding the projectile already had
}