]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix `EmptyContainer` construction action (#14406)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Wed, 15 Mar 2023 00:14:18 +0000 (13:14 +1300)
committerGitHub <noreply@github.com>
Wed, 15 Mar 2023 00:14:18 +0000 (11:14 +1100)
Content.Server/Construction/Completions/EmptyAllContainers.cs
Content.Server/Construction/Completions/EmptyContainer.cs
Content.Server/Storage/EntitySystems/SecretStashSystem.cs
Content.Shared/Cuffs/SharedCuffableSystem.cs
Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs

index 9cf5c9f83cd727382d923ba9a009e34456cba338..8d3b4f90ecaf6bad48ccb6e9aabb587d0017f8c5 100644 (file)
@@ -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
     {
+        /// <summary>
+        ///     Whether or not the user should attempt to pick up the removed entities.
+        /// </summary>
+        [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<TransformComponent>(uid);
             var containerSys = entityManager.EntitySysManager.GetEntitySystem<ContainerSystem>();
+            var handSys = entityManager.EntitySysManager.GetEntitySystem<HandsSystem>();
+
+            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);
+                }
             }
         }
     }
index 88c3b807bd995fce2214d0ca289b8c14c1709b32..2a319a7fa81c192b91b01ade4b09e91538efac3e 100644 (file)
@@ -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;
 
+        /// <summary>
+        ///     Whether or not the user should attempt to pick up the removed entities.
+        /// </summary>
+        [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<ContainerSystem>();
-            var transform = entityManager.GetComponent<TransformComponent>(uid);
-            containerSys.EmptyContainer(container, true, transform.Coordinates, true);
+            var handSys = entityManager.EntitySysManager.GetEntitySystem<HandsSystem>();
+
+            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);
+            }
         }
     }
 }
index 93aeca9f374994ee0d281c94957345961990cb6f..2237527c35267b94f9f8f7246abc659ff0857f28 100644 (file)
@@ -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);
         }
 
         /// <summary>
index 7c685281a5d2bde572d88dadafe1c0b2e0bc26f6..c1212f9993a4e50071f773cfa37aba3e0ebaaf31 100644 (file)
@@ -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)
index 96e7863c868aeb084325d0646b81f8946eb0d1eb..1ecf2a97949bd2d27aaba37e3c7ae6c1d9796a38 100644 (file)
@@ -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);