Dumpable component to use a doafter to empty storage into a disposal unit, placeable surface, or the ground (#7792)

This commit is contained in:
Rane
2022-05-03 23:00:22 -04:00
committed by GitHub
parent 40ae7cc285
commit cfd00e74ca
11 changed files with 240 additions and 72 deletions

View File

@@ -0,0 +1,23 @@
using System.Threading;
namespace Content.Shared.Storage.Components
{
/// <summary>
/// Lets you dump this container on the ground using a verb,
/// or when interacting with it on a disposal unit or placeable surface.
/// </summary>
[RegisterComponent]
public sealed class DumpableComponent : Component
{
/// <summary>
/// How long each item adds to the doafter.
/// </summary>
[DataField("delayPerItem")]
public TimeSpan DelayPerItem = TimeSpan.FromSeconds(0.2);
/// <summary>
/// Cancellation token for the doafter.
/// <summary>
public CancellationTokenSource? CancelToken;
}
}

View File

@@ -9,7 +9,7 @@ using Robust.Shared.Serialization;
namespace Content.Shared.Storage
{
[NetworkedComponent()]
public abstract class SharedStorageComponent : Component, IDraggable
public abstract class SharedStorageComponent : Component
{
[Serializable, NetSerializable]
public sealed class StorageBoundUserInterfaceState : BoundUserInterfaceState
@@ -56,32 +56,6 @@ namespace Content.Shared.Storage
/// <param name="entity">The entity to remove</param>
/// <returns>True if no longer in storage, false otherwise</returns>
public abstract bool Remove(EntityUid entity);
bool IDraggable.CanDrop(CanDropEvent args)
{
return _entMan.TryGetComponent(args.Target, out PlaceableSurfaceComponent? placeable) &&
placeable.IsPlaceable;
}
bool IDraggable.Drop(DragDropEvent eventArgs)
{
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User, eventArgs.Target))
return false;
var storedEntities = StoredEntities?.ToArray();
if (storedEntities == null)
return false;
// empty everything out
foreach (var storedEntity in storedEntities)
{
if (Remove(storedEntity))
_entMan.GetComponent<TransformComponent>(storedEntity).WorldPosition = eventArgs.DropLocation.Position;
}
return true;
}
}
/// <summary>