diff --git a/Content.Client/Weapons/Ranged/Systems/GunSystem.Ballistic.cs b/Content.Client/Weapons/Ranged/Systems/GunSystem.Ballistic.cs index bb1754f06c..6c203f7676 100644 --- a/Content.Client/Weapons/Ranged/Systems/GunSystem.Ballistic.cs +++ b/Content.Client/Weapons/Ranged/Systems/GunSystem.Ballistic.cs @@ -34,13 +34,13 @@ public sealed partial class GunSystem component.Entities.RemoveAt(component.Entities.Count - 1); component.Container.Remove(existing); - EnsureComp(existing); + EnsureShootable(existing); } else if (component.UnspawnedCount > 0) { component.UnspawnedCount--; ent = Spawn(component.FillProto, coordinates); - EnsureComp(ent.Value); + EnsureShootable(ent.Value); } if (ent != null && ent.Value.IsClientSide()) diff --git a/Content.Client/Weapons/Ranged/Systems/GunSystem.cs b/Content.Client/Weapons/Ranged/Systems/GunSystem.cs index 2d8f5fdbfa..4ecd72561f 100644 --- a/Content.Client/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Client/Weapons/Ranged/Systems/GunSystem.cs @@ -191,7 +191,7 @@ public sealed partial class GunSystem : SharedGunSystem if (ent!.Value.IsClientSide()) Del(ent.Value); else - RemComp(ent.Value); + RemoveShootable(ent.Value); continue; } @@ -225,7 +225,7 @@ public sealed partial class GunSystem : SharedGunSystem if (ent!.Value.IsClientSide()) Del(ent.Value); else - RemComp(ent.Value); + RemoveShootable(ent.Value); break; case HitscanPrototype: Audio.PlayPredicted(gun.SoundGunshot, gunUid, user); diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.Ballistic.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.Ballistic.cs index 3a28c7cdb1..ef3127e39b 100644 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.Ballistic.cs +++ b/Content.Server/Weapons/Ranged/Systems/GunSystem.Ballistic.cs @@ -17,13 +17,13 @@ public sealed partial class GunSystem component.Entities.RemoveAt(component.Entities.Count - 1); component.Container.Remove(existing); - EnsureComp(existing); + EnsureShootable(existing); } else if (component.UnspawnedCount > 0) { component.UnspawnedCount--; ent = Spawn(component.FillProto, coordinates); - EnsureComp(ent.Value); + EnsureShootable(ent.Value); } if (ent != null) diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs index 4a35e64c6c..2bb1dc8245 100644 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs @@ -283,7 +283,7 @@ public sealed partial class GunSystem : SharedGunSystem // Do a throw if (!HasComp(uid)) { - RemComp(uid); + RemoveShootable(uid); // TODO: Someone can probably yeet this a billion miles so need to pre-validate input somewhere up the call stack. ThrowingSystem.TryThrow(uid, mapDirection, gun.ProjectileSpeed, user); return; diff --git a/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs b/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs index eb1328da4a..62af124252 100644 --- a/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs @@ -20,7 +20,7 @@ public partial class AmmoComponent : Component, IShootable /// /// Spawns another prototype to be shot instead of itself. /// -[RegisterComponent, NetworkedComponent, ComponentReference(typeof(AmmoComponent)), AutoGenerateComponentState] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class CartridgeAmmoComponent : AmmoComponent { [ViewVariables(VVAccess.ReadWrite), DataField("proto", required: true, customTypeSerializer: typeof(PrototypeIdSerializer))] diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs index b0f8ae15d6..a6a31bc992 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs @@ -216,7 +216,7 @@ public abstract partial class SharedGunSystem { entity = component.Entities[^1]; - args.Ammo.Add((entity, EnsureComp(entity))); + args.Ammo.Add((entity, EnsureShootable(entity))); component.Entities.RemoveAt(component.Entities.Count - 1); component.Container.Remove(entity); } @@ -224,7 +224,7 @@ public abstract partial class SharedGunSystem { component.UnspawnedCount--; entity = Spawn(component.FillProto, args.Coordinates); - args.Ammo.Add((entity, EnsureComp(entity))); + args.Ammo.Add((entity, EnsureShootable(entity))); } } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.BasicEntity.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.BasicEntity.cs index 14aeefb916..731e7a526d 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.BasicEntity.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.BasicEntity.cs @@ -37,7 +37,7 @@ public abstract partial class SharedGunSystem } var ent = Spawn(component.Proto, args.Coordinates); - args.Ammo.Add((ent, EnsureComp(ent))); + args.Ammo.Add((ent, EnsureShootable(ent))); } _recharge.Reset(uid); diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Battery.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Battery.cs index 5ce43e246b..ecbd19d517 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Battery.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Battery.cs @@ -98,7 +98,7 @@ public abstract partial class SharedGunSystem { case ProjectileBatteryAmmoProviderComponent proj: var ent = Spawn(proj.Prototype, coordinates); - return (ent, EnsureComp(ent)); + return (ent, EnsureShootable(ent)); case HitscanBatteryAmmoProviderComponent hitscan: return (null, ProtoManager.Index(hitscan.Prototype)); default: diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs index 31fbde44f4..bd65ef5cf6 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs @@ -352,7 +352,7 @@ public abstract partial class SharedGunSystem { if (TryTakeChamberEntity(uid, out chamberEnt)) { - args.Ammo.Add((chamberEnt.Value, EnsureComp(chamberEnt.Value))); + args.Ammo.Add((chamberEnt.Value, EnsureShootable(chamberEnt.Value))); } // No ammo returned. else @@ -406,7 +406,7 @@ public abstract partial class SharedGunSystem { // Shooting code won't eject it if it's still contained. chamberEnt = slot.ContainedEntity; - args.Ammo.Add((chamberEnt.Value, EnsureComp(chamberEnt.Value))); + args.Ammo.Add((chamberEnt.Value, EnsureShootable(chamberEnt.Value))); } } } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Container.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Container.cs index 999d5379a2..d9a7cb53c1 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Container.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Container.cs @@ -30,7 +30,7 @@ public partial class SharedGunSystem if (_netManager.IsServer) container.Remove(ent); - args.Ammo.Add((ent, EnsureComp(ent))); + args.Ammo.Add((ent, EnsureShootable(ent))); } } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs index 45c133a4a5..f66950711e 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs @@ -342,13 +342,13 @@ public partial class SharedGunSystem component.Chambers[index] = false; SetCartridgeSpent(ent, cartridge, true); var spawned = Spawn(cartridge.Prototype, args.Coordinates); - args.Ammo.Add((spawned, EnsureComp(spawned))); + args.Ammo.Add((spawned, EnsureShootable(spawned))); Del(ent); continue; } component.Chambers[i] = null; - args.Ammo.Add((ent, EnsureComp(ent))); + args.Ammo.Add((ent, EnsureShootable(ent))); } } else if (component.AmmoSlots[index] != null) @@ -362,13 +362,13 @@ public partial class SharedGunSystem SetCartridgeSpent(ent.Value, cartridge, true); var spawned = Spawn(cartridge.Prototype, args.Coordinates); - args.Ammo.Add((spawned, EnsureComp(spawned))); + args.Ammo.Add((spawned, EnsureShootable(spawned))); continue; } component.AmmoContainer.Remove(ent.Value); component.AmmoSlots[index] = null; - args.Ammo.Add((ent.Value, EnsureComp(ent.Value))); + args.Ammo.Add((ent.Value, EnsureShootable(ent.Value))); TransformSystem.SetCoordinates(ent.Value, args.Coordinates); } } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Solution.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Solution.cs index d04b3fad30..268b2a7473 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Solution.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Solution.cs @@ -45,7 +45,7 @@ public partial class SharedGunSystem protected virtual (EntityUid Entity, IShootable) GetSolutionShot(EntityUid uid, SolutionAmmoProviderComponent component, EntityCoordinates position) { var ent = Spawn(component.Prototype, position); - return (ent, EnsureComp(ent)); + return (ent, EnsureShootable(ent)); } protected void UpdateSolutionAppearance(EntityUid uid, SolutionAmmoProviderComponent component) diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs index 1e6a5c50e9..797a2f472d 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs @@ -350,7 +350,7 @@ public abstract partial class SharedGunSystem : EntitySystem EntityUid? user = null, bool throwItems = false) { - var shootable = EnsureComp(ammo); + var shootable = EnsureShootable(ammo); Shoot(gunUid, gun, new List<(EntityUid? Entity, IShootable Shootable)>(1) { (ammo, shootable) }, fromCoordinates, toCoordinates, out userImpulse, user, throwItems); } @@ -411,6 +411,20 @@ public abstract partial class SharedGunSystem : EntitySystem } } + protected IShootable EnsureShootable(EntityUid uid) + { + if (TryComp(uid, out var cartridge)) + return cartridge; + + return EnsureComp(uid); + } + + protected void RemoveShootable(EntityUid uid) + { + RemCompDeferred(uid); + RemCompDeferred(uid); + } + protected void MuzzleFlash(EntityUid gun, AmmoComponent component, EntityUid? user = null) { var sprite = component.MuzzleFlash;