From 24ef92de1824d19b4118dfdcf17836b4437870cf Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Wed, 15 Mar 2023 13:14:18 +1300 Subject: [PATCH] Fix `EmptyContainer` construction action (#14406) --- .../Completions/EmptyAllContainers.cs | 22 ++++++++++++++++--- .../Completions/EmptyContainer.cs | 21 +++++++++++++++--- .../EntitySystems/SecretStashSystem.cs | 2 +- Content.Shared/Cuffs/SharedCuffableSystem.cs | 2 +- .../EntitySystems/EncryptionKeySystem.cs | 2 +- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Content.Server/Construction/Completions/EmptyAllContainers.cs b/Content.Server/Construction/Completions/EmptyAllContainers.cs index 9cf5c9f83c..8d3b4f90ec 100644 --- a/Content.Server/Construction/Completions/EmptyAllContainers.cs +++ b/Content.Server/Construction/Completions/EmptyAllContainers.cs @@ -1,4 +1,6 @@ -using Content.Shared.Construction; +using Content.Server.Hands.Components; +using Content.Server.Hands.Systems; +using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Server.Containers; using Robust.Shared.Containers; @@ -9,16 +11,30 @@ namespace Content.Server.Construction.Completions [DataDefinition] public sealed class EmptyAllContainers : IGraphAction { + /// + /// Whether or not the user should attempt to pick up the removed entities. + /// + [DataField("pickup")] + public bool Pickup = false; + public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager) { if (!entityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)) return; - var transform = entityManager.GetComponent(uid); var containerSys = entityManager.EntitySysManager.GetEntitySystem(); + var handSys = entityManager.EntitySysManager.GetEntitySystem(); + + HandsComponent? hands = null; + var pickup = Pickup && entityManager.TryGetComponent(userUid, out hands); + foreach (var container in containerManager.GetAllContainers()) { - containerSys.EmptyContainer(container, true, transform.Coordinates); + foreach (var ent in containerSys.EmptyContainer(container, true, reparent: !pickup)) + { + if (pickup) + handSys.PickupOrDrop(userUid, ent, handsComp: hands); + } } } } diff --git a/Content.Server/Construction/Completions/EmptyContainer.cs b/Content.Server/Construction/Completions/EmptyContainer.cs index 88c3b807bd..2a319a7fa8 100644 --- a/Content.Server/Construction/Completions/EmptyContainer.cs +++ b/Content.Server/Construction/Completions/EmptyContainer.cs @@ -1,4 +1,5 @@ -using System.Linq; +using Content.Server.Hands.Components; +using Content.Server.Hands.Systems; using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Server.Containers; @@ -12,14 +13,28 @@ namespace Content.Server.Construction.Completions { [DataField("container")] public string Container { get; private set; } = string.Empty; + /// + /// Whether or not the user should attempt to pick up the removed entities. + /// + [DataField("pickup")] + public bool Pickup = false; + public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager) { if (!entityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) || !containerManager.TryGetContainer(Container, out var container)) return; var containerSys = entityManager.EntitySysManager.GetEntitySystem(); - var transform = entityManager.GetComponent(uid); - containerSys.EmptyContainer(container, true, transform.Coordinates, true); + var handSys = entityManager.EntitySysManager.GetEntitySystem(); + + HandsComponent? hands = null; + var pickup = Pickup && entityManager.TryGetComponent(userUid, out hands); + + foreach (var ent in containerSys.EmptyContainer(container, true, reparent: !pickup)) + { + if (pickup) + handSys.PickupOrDrop(userUid, ent, handsComp: hands); + } } } } diff --git a/Content.Server/Storage/EntitySystems/SecretStashSystem.cs b/Content.Server/Storage/EntitySystems/SecretStashSystem.cs index 93aeca9f37..2237527c35 100644 --- a/Content.Server/Storage/EntitySystems/SecretStashSystem.cs +++ b/Content.Server/Storage/EntitySystems/SecretStashSystem.cs @@ -28,7 +28,7 @@ namespace Content.Server.Storage.EntitySystems private void OnDestroyed(EntityUid uid, SecretStashComponent component, DestructionEventArgs args) { - _containerSystem.EmptyContainer(component.ItemContainer, attachToGridOrMap: true); + _containerSystem.EmptyContainer(component.ItemContainer); } /// diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index 7c685281a5..c1212f9993 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -131,7 +131,7 @@ namespace Content.Shared.Cuffs private void OnRejuvenate(EntityUid uid, CuffableComponent component, RejuvenateEvent args) { - _container.EmptyContainer(component.Container, true, attachToGridOrMap: true); + _container.EmptyContainer(component.Container, true); } private void OnCuffsRemovedFromContainer(EntityUid uid, CuffableComponent component, EntRemovedFromContainerMessage args) diff --git a/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs b/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs index 96e7863c86..1ecf2a9794 100644 --- a/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs +++ b/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs @@ -48,7 +48,7 @@ public sealed class EncryptionKeySystem : EntitySystem private void OnKeyRemoval(EntityUid uid, EncryptionKeyHolderComponent component, EncryptionRemovalFinishedEvent args) { var contained = component.KeyContainer.ContainedEntities.ToArray(); - _container.EmptyContainer(component.KeyContainer, entMan: EntityManager); + _container.EmptyContainer(component.KeyContainer, reparent: false); foreach (var ent in contained) { _hands.PickupOrDrop(args.User, ent);