From f38bef562c903f78ab29144609e26e9d77551069 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Thu, 27 Oct 2022 01:46:13 +1100 Subject: [PATCH] Fix gun ItemStatus (#12225) --- .../Ranged/Systems/GunSystem.ChamberMagazine.cs | 11 +++++++---- .../Systems/SharedGunSystem.ChamberMagazine.cs | 3 +-- .../Ranged/Systems/SharedGunSystem.Magazine.cs | 12 +++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Content.Client/Weapons/Ranged/Systems/GunSystem.ChamberMagazine.cs b/Content.Client/Weapons/Ranged/Systems/GunSystem.ChamberMagazine.cs index 76cf47cb0c..13e64d5393 100644 --- a/Content.Client/Weapons/Ranged/Systems/GunSystem.ChamberMagazine.cs +++ b/Content.Client/Weapons/Ranged/Systems/GunSystem.ChamberMagazine.cs @@ -1,4 +1,5 @@ using Content.Shared.Examine; +using Content.Shared.Weapons.Ranged; using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Events; using Robust.Shared.Containers; @@ -12,16 +13,18 @@ public sealed partial class GunSystem base.InitializeChamberMagazine(); SubscribeLocalEvent(OnChamberMagazineCounter); SubscribeLocalEvent(OnChamberMagazineAmmoUpdate); - SubscribeLocalEvent(OnChamberEntRemove); } - private void OnChamberEntRemove(EntityUid uid, ChamberMagazineAmmoProviderComponent component, EntRemovedFromContainerMessage args) + protected override void OnMagazineSlotChange(EntityUid uid, MagazineAmmoProviderComponent component, ContainerModifiedMessage args) { - if (args.Container.ID != ChamberSlot) return; + base.OnMagazineSlotChange(uid, component, args); + + if (ChamberSlot != args.Container.ID || args is not EntRemovedFromContainerMessage removedArgs) + return; // This is dirty af. Prediction moment. // We may be predicting spawning entities and the engine just removes them from the container so we'll just delete them. - if (args.Entity.IsClientSide()) + if (removedArgs.Entity.IsClientSide()) QueueDel(args.Entity); // AFAIK the only main alternative is having some client-specific handling via a bool or otherwise for the state. diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs index d2adb3b4b2..d8fcddc4ed 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs @@ -1,7 +1,5 @@ using System.Diagnostics.CodeAnalysis; -using Content.Shared.Containers.ItemSlots; using Content.Shared.Examine; -using Content.Shared.Interaction; using Content.Shared.Interaction.Events; using Content.Shared.Verbs; using Content.Shared.Weapons.Ranged.Components; @@ -19,6 +17,7 @@ public abstract partial class SharedGunSystem SubscribeLocalEvent(OnChamberMagazineTakeAmmo); SubscribeLocalEvent>(OnMagazineVerb); SubscribeLocalEvent(OnMagazineSlotChange); + SubscribeLocalEvent(OnMagazineSlotChange); SubscribeLocalEvent(OnMagazineUse); SubscribeLocalEvent(OnChamberMagazineExamine); } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs index 588f7bd2b7..093f4ce1e7 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs @@ -1,6 +1,4 @@ -using Content.Shared.Containers.ItemSlots; using Content.Shared.Examine; -using Content.Shared.Interaction; using Content.Shared.Interaction.Events; using Content.Shared.Verbs; using Content.Shared.Weapons.Ranged.Components; @@ -18,6 +16,7 @@ public abstract partial class SharedGunSystem SubscribeLocalEvent(OnMagazineTakeAmmo); SubscribeLocalEvent>(OnMagazineVerb); SubscribeLocalEvent(OnMagazineSlotChange); + SubscribeLocalEvent(OnMagazineSlotChange); SubscribeLocalEvent(OnMagazineUse); SubscribeLocalEvent(OnMagazineExamine); } @@ -37,7 +36,7 @@ public abstract partial class SharedGunSystem if (magEnt == null) return; - RaiseLocalEvent(magEnt.Value, args, false); + RaiseLocalEvent(magEnt.Value, args); UpdateAmmoCount(uid); UpdateMagazineAppearance(component, magEnt.Value); } @@ -50,13 +49,16 @@ public abstract partial class SharedGunSystem if (magEnt != null) { - RaiseLocalEvent(magEnt.Value, args, false); + RaiseLocalEvent(magEnt.Value, args); UpdateMagazineAppearance(component, magEnt.Value); } } - private void OnMagazineSlotChange(EntityUid uid, MagazineAmmoProviderComponent component, EntInsertedIntoContainerMessage args) + protected virtual void OnMagazineSlotChange(EntityUid uid, MagazineAmmoProviderComponent component, ContainerModifiedMessage args) { + if (MagazineSlot != args.Container.ID) + return; + UpdateAmmoCount(uid); if (!TryComp(uid, out var appearance)) return;