2020-10-08 17:41:23 +02:00
|
|
|
|
#nullable enable
|
2021-02-25 11:41:11 +01:00
|
|
|
|
using System.Linq;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Content.Shared.Construction;
|
|
|
|
|
|
using JetBrains.Annotations;
|
2020-12-03 22:49:00 +01:00
|
|
|
|
using Robust.Shared.Containers;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Construction.Completions
|
|
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataDefinition]
|
2020-10-08 17:41:23 +02:00
|
|
|
|
public class EmptyContainer : IGraphAction
|
|
|
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("container")] public string Container { get; private set; } = string.Empty;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
|
|
|
|
|
public async Task PerformAction(IEntity entity, IEntity? user)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (entity.Deleted) return;
|
|
|
|
|
|
|
|
|
|
|
|
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
|
|
|
|
|
|
!containerManager.TryGetContainer(Container, out var container)) return;
|
|
|
|
|
|
|
2021-02-25 11:41:11 +01:00
|
|
|
|
// TODO: Use container helpers.
|
|
|
|
|
|
foreach (var contained in container.ContainedEntities.ToArray())
|
|
|
|
|
|
{
|
|
|
|
|
|
container.ForceRemove(contained);
|
|
|
|
|
|
contained.Transform.Coordinates = entity.Transform.Coordinates;
|
|
|
|
|
|
contained.Transform.AttachToGridOrMap();
|
|
|
|
|
|
}
|
2020-10-08 17:41:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|