From 633e67f318e187253cead90f160de74b19d87b15 Mon Sep 17 00:00:00 2001 From: beck-thompson <107373427+beck-thompson@users.noreply.github.com> Date: Fri, 18 Oct 2024 05:58:07 -0700 Subject: [PATCH] Fix: Plushies no longer delete items when recycled (#32838) fix --- .../EntitySystems/SecretStashSystem.cs | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Content.Shared/Storage/EntitySystems/SecretStashSystem.cs b/Content.Shared/Storage/EntitySystems/SecretStashSystem.cs index 08a69c345f0919..af9b768e98be0e 100644 --- a/Content.Shared/Storage/EntitySystems/SecretStashSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SecretStashSystem.cs @@ -14,6 +14,8 @@ using Content.Shared.IdentityManagement; using Content.Shared.Tools.EntitySystems; using Content.Shared.Whitelist; +using Content.Shared.Materials; +using Robust.Shared.Map; namespace Content.Shared.Storage.EntitySystems; @@ -35,6 +37,7 @@ public override void Initialize() base.Initialize(); SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnDestroyed); + SubscribeLocalEvent(OnReclaimed); SubscribeLocalEvent(OnInteractUsing, after: new[] { typeof(ToolOpenableSystem) }); SubscribeLocalEvent(OnInteractHand); SubscribeLocalEvent>(OnGetVerb); @@ -47,12 +50,12 @@ private void OnInit(Entity entity, ref ComponentInit args) private void OnDestroyed(Entity entity, ref DestructionEventArgs args) { - var storedInside = _containerSystem.EmptyContainer(entity.Comp.ItemContainer); - if (storedInside != null && storedInside.Count >= 1) - { - var popup = Loc.GetString("comp-secret-stash-on-destroyed-popup", ("stashname", GetStashName(entity))); - _popupSystem.PopupEntity(popup, storedInside[0], PopupType.MediumCaution); - } + DropContentsAndAlert(entity); + } + + private void OnReclaimed(Entity entity, ref GotReclaimedEvent args) + { + DropContentsAndAlert(entity, args.ReclaimerCoordinates); } private void OnInteractUsing(Entity entity, ref InteractUsingEvent args) @@ -211,5 +214,18 @@ private bool HasItemInside(Entity entity) return entity.Comp.ItemContainer.ContainedEntity != null; } + /// + /// Drop the item stored in the stash and alert all nearby players with a popup. + /// + private void DropContentsAndAlert(Entity entity, EntityCoordinates? cords = null) + { + var storedInside = _containerSystem.EmptyContainer(entity.Comp.ItemContainer, true, cords); + if (storedInside != null && storedInside.Count >= 1) + { + var popup = Loc.GetString("comp-secret-stash-on-destroyed-popup", ("stashname", GetStashName(entity))); + _popupSystem.PopupPredicted(popup, storedInside[0], null, PopupType.MediumCaution); + } + } + #endregion }