Skip to content

Commit

Permalink
Fix cartridge despawn
Browse files Browse the repository at this point in the history
Move timed despawn to SetCartridgeSpent() instead of EjectCartridge(),
because EjectCartridge() is called in several other code paths that
don't involve the cartridge being spent.

For example, ejecting all cartridges from a revolver mark the cartridges
for despawning even though they were never fired. Guns whose cartridges
disappear while loaded appear to "jam".
  • Loading branch information
Partmedia committed Nov 16, 2024
1 parent f2b77fd commit 6d9072b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ protected void SetCartridgeSpent(EntityUid uid, CartridgeAmmoComponent cartridge

cartridge.Spent = spent;
Appearance.SetData(uid, AmmoVisuals.Spent, spent);

// Reduce entity spam from cartridges for N14.
if (spent)
{
var despawn = EnsureComp<TimedDespawnComponent>(uid);
despawn.Lifetime = 15f * 60; // 15 minutes
}
}

/// <summary>
Expand Down Expand Up @@ -458,10 +465,6 @@ protected void EjectCartridge(
{
Audio.PlayPvs(cartridge.EjectSound, entity, AudioParams.Default.WithVariation(SharedContentAudioSystem.DefaultVariation).WithVolume(-1f));
}

// Reduce entity spam from cartridges for N14.
var despawn = EnsureComp<TimedDespawnComponent>(entity);
despawn.Lifetime = 15f * 60; // 15 minutes
}

protected IShootable EnsureShootable(EntityUid uid)
Expand Down

0 comments on commit 6d9072b

Please sign in to comment.