Consumable host: an effect lives exactly its Duration, not Duration plus one tick

Expiry fires when the remaining duration reaches zero (<= 0), so behaviours execute on
Duration/dt ticks and not one more. AConsumableRunsForExactlyItsDurationInTicks pins it
with 0.25 s ticks. Builds; verified in the next run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-09 23:48:02 +02:00
commit d519d99b1e
2 changed files with 17 additions and 1 deletions

View file

@ -1457,7 +1457,7 @@ public abstract class Entity
for (var i = 0; i < _activeConsumables.Count; i++)
{
_activeConsumables[i].Update(delta);
if (_activeConsumables[i].RemainingDuration < 0)
if (_activeConsumables[i].RemainingDuration <= 0)
{
// Cut 2 Gate 1 fix (docs/stats-and-power-cut.md): an expired consumable dropped out of this
// list without ever telling the resolver, leaving its generation/cache/modifier entries

View file

@ -169,6 +169,22 @@ public sealed class ConsumableTests : IDisposable
Assert.Equal(10f, rig.Engine.Evaluate(rig.Thrust), 3);
}
// An effect runs for exactly its Duration: Duration 1 with 0.25 s ticks (exact in floats) executes its
// behaviours on four ticks and is gone when the fourth ends, not on a fifth.
[Fact]
public void AConsumableRunsForExactlyItsDurationInTicks()
{
var rig = Build();
using var _ = rig.Cache;
rig.Ship.ActivateConsumable(rig.Mint());
Tick(rig, 3, .25f);
Assert.NotNull(rig.Ship.FindActiveConsumable(rig.Consumable));
Assert.Equal(20f, rig.Engine.Evaluate(rig.Thrust), 3);
Tick(rig, 1, .25f); // the fourth tick spends the last of the Duration
Assert.Null(rig.Ship.FindActiveConsumable(rig.Consumable));
Assert.Equal(10f, rig.Engine.Evaluate(rig.Thrust), 3);
}
// CS-R1, the stackable side: a stackable design activates again while its first effect runs, and every
// multiplier on the stat multiplies.
[Fact]