Skip to content

Commit

Permalink
Fix: Plushies no longer delete items when recycled (#32838)
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
beck-thompson authored and Errant-4 committed Oct 18, 2024
1 parent e04e3a6 commit 633e67f
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Content.Shared/Storage/EntitySystems/SecretStashSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -35,6 +37,7 @@ public override void Initialize()
base.Initialize();
SubscribeLocalEvent<SecretStashComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SecretStashComponent, DestructionEventArgs>(OnDestroyed);
SubscribeLocalEvent<SecretStashComponent, GotReclaimedEvent>(OnReclaimed);
SubscribeLocalEvent<SecretStashComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(ToolOpenableSystem) });
SubscribeLocalEvent<SecretStashComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<SecretStashComponent, GetVerbsEvent<InteractionVerb>>(OnGetVerb);
Expand All @@ -47,12 +50,12 @@ private void OnInit(Entity<SecretStashComponent> entity, ref ComponentInit args)

private void OnDestroyed(Entity<SecretStashComponent> 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<SecretStashComponent> entity, ref GotReclaimedEvent args)
{
DropContentsAndAlert(entity, args.ReclaimerCoordinates);
}

private void OnInteractUsing(Entity<SecretStashComponent> entity, ref InteractUsingEvent args)
Expand Down Expand Up @@ -211,5 +214,18 @@ private bool HasItemInside(Entity<SecretStashComponent> entity)
return entity.Comp.ItemContainer.ContainedEntity != null;
}

/// <summary>
/// Drop the item stored in the stash and alert all nearby players with a popup.
/// </summary>
private void DropContentsAndAlert(Entity<SecretStashComponent> 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
}

0 comments on commit 633e67f

Please sign in to comment.