From 13cef85a6e7d0f5873d1f66358ef742356541582 Mon Sep 17 00:00:00 2001 From: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com> Date: Sat, 13 Apr 2024 20:17:17 -0700 Subject: [PATCH] Fix rockets and lasers looking like they have nothing loaded (#26933) --- .../Systems/GunSystem.MagazineVisuals.cs | 2 +- .../Systems/SharedGunSystem.Magazine.cs | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Content.Client/Weapons/Ranged/Systems/GunSystem.MagazineVisuals.cs b/Content.Client/Weapons/Ranged/Systems/GunSystem.MagazineVisuals.cs index a81e8ae887..2d670d1e77 100644 --- a/Content.Client/Weapons/Ranged/Systems/GunSystem.MagazineVisuals.cs +++ b/Content.Client/Weapons/Ranged/Systems/GunSystem.MagazineVisuals.cs @@ -40,7 +40,7 @@ public sealed partial class GunSystem if (sprite == null) return; - if (args.AppearanceData.TryGetValue(AmmoVisuals.MagLoaded, out var magloaded) && + if (!args.AppearanceData.TryGetValue(AmmoVisuals.MagLoaded, out var magloaded) || magloaded is true) { if (!args.AppearanceData.TryGetValue(AmmoVisuals.AmmoMax, out var capacity)) diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs index 57db1d2b9c..9eb290ab65 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs @@ -1,7 +1,6 @@ using Content.Shared.Examine; using Content.Shared.Interaction.Events; using Content.Shared.Verbs; -using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Events; using Robust.Shared.Containers; @@ -13,6 +12,7 @@ public abstract partial class SharedGunSystem protected virtual void InitializeMagazine() { + SubscribeLocalEvent(OnMagazineMapInit); SubscribeLocalEvent(OnMagazineTakeAmmo); SubscribeLocalEvent(OnMagazineAmmoCount); SubscribeLocalEvent>(OnMagazineVerb); @@ -22,6 +22,11 @@ public abstract partial class SharedGunSystem SubscribeLocalEvent(OnMagazineExamine); } + private void OnMagazineMapInit(Entity ent, ref MapInitEvent args) + { + MagazineSlotChanged(ent); + } + private void OnMagazineExamine(EntityUid uid, MagazineAmmoProviderComponent component, ExaminedEvent args) { if (!args.IsInDetailsRange) @@ -62,16 +67,21 @@ public abstract partial class SharedGunSystem if (MagazineSlot != args.Container.ID) return; - UpdateAmmoCount(uid); - if (!TryComp(uid, out var appearance)) + MagazineSlotChanged((uid, component)); + } + + private void MagazineSlotChanged(Entity ent) + { + UpdateAmmoCount(ent); + if (!TryComp(ent, out var appearance)) return; - var magEnt = GetMagazineEntity(uid); - Appearance.SetData(uid, AmmoVisuals.MagLoaded, magEnt != null, appearance); + var magEnt = GetMagazineEntity(ent); + Appearance.SetData(ent, AmmoVisuals.MagLoaded, magEnt != null, appearance); if (magEnt != null) { - UpdateMagazineAppearance(uid, component, magEnt.Value); + UpdateMagazineAppearance(ent, ent, magEnt.Value); } } -- 2.51.2