1
0

EmptyAllContainers.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Content.Server.Hands.Systems;
  2. using Content.Shared.Construction;
  3. using Content.Shared.Hands.Components;
  4. using JetBrains.Annotations;
  5. using Robust.Server.Containers;
  6. using Robust.Server.GameObjects;
  7. using Robust.Shared.Containers;
  8. using Robust.Shared.GameObjects;
  9. using Robust.Shared.Map;
  10. namespace Content.Server.Construction.Completions
  11. {
  12. [UsedImplicitly]
  13. [DataDefinition]
  14. public sealed partial class EmptyAllContainers : IGraphAction
  15. {
  16. /// <summary>
  17. /// Whether or not the user should attempt to pick up the removed entities.
  18. /// </summary>
  19. [DataField]
  20. public bool Pickup = false;
  21. /// <summary>
  22. /// Whether or not to empty the container at the user's location.
  23. /// </summary>
  24. [DataField]
  25. public bool EmptyAtUser = false;
  26. public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
  27. {
  28. if (!entityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager))
  29. return;
  30. var containerSys = entityManager.EntitySysManager.GetEntitySystem<ContainerSystem>();
  31. var handSys = entityManager.EntitySysManager.GetEntitySystem<HandsSystem>();
  32. var transformSys = entityManager.EntitySysManager.GetEntitySystem<TransformSystem>();
  33. HandsComponent? hands = null;
  34. var pickup = Pickup && entityManager.TryGetComponent(userUid, out hands);
  35. foreach (var container in containerManager.GetAllContainers())
  36. {
  37. foreach (var ent in containerSys.EmptyContainer(container, true, reparent: !pickup))
  38. {
  39. if (EmptyAtUser && userUid is not null)
  40. transformSys.DropNextTo(ent, (EntityUid) userUid);
  41. if (pickup)
  42. handSys.PickupOrDrop(userUid, ent, handsComp: hands);
  43. }
  44. }
  45. }
  46. }
  47. }