Fix EmptyContainer construction action (#14406)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user