2020-10-14 15:24:07 +02:00
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.ActionBlocker;
|
|
|
|
|
using Content.Shared.DragDrop;
|
|
|
|
|
using Content.Shared.Placeable;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2021-02-03 22:07:13 +00:00
|
|
|
using Robust.Shared.Map;
|
2019-11-13 17:37:46 -05:00
|
|
|
using Robust.Shared.Serialization;
|
2018-04-22 06:11:38 -05:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Storage
|
2018-04-22 06:11:38 -05:00
|
|
|
{
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2020-10-14 15:24:07 +02:00
|
|
|
public abstract class SharedStorageComponent : Component, IDraggable
|
2018-04-22 06:11:38 -05:00
|
|
|
{
|
2022-04-28 06:11:15 -06:00
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public sealed class StorageBoundUserInterfaceState : BoundUserInterfaceState
|
|
|
|
|
{
|
|
|
|
|
public readonly List<EntityUid> StoredEntities;
|
|
|
|
|
public readonly int StorageSizeUsed;
|
|
|
|
|
public readonly int StorageCapacityMax;
|
|
|
|
|
|
|
|
|
|
public StorageBoundUserInterfaceState(List<EntityUid> storedEntities, int storageSizeUsed, int storageCapacityMax)
|
|
|
|
|
{
|
|
|
|
|
StoredEntities = storedEntities;
|
|
|
|
|
StorageSizeUsed = storageSizeUsed;
|
|
|
|
|
StorageCapacityMax = storageCapacityMax;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public sealed class StorageInsertItemMessage : BoundUserInterfaceMessage
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public sealed class StorageRemoveItemMessage : BoundUserInterfaceMessage
|
|
|
|
|
{
|
|
|
|
|
public readonly EntityUid InteractedItemUID;
|
|
|
|
|
public StorageRemoveItemMessage(EntityUid interactedItemUID)
|
|
|
|
|
{
|
|
|
|
|
InteractedItemUID = interactedItemUID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public enum StorageUiKey
|
|
|
|
|
{
|
|
|
|
|
Key,
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
2021-12-04 12:59:44 +01:00
|
|
|
public abstract IReadOnlyList<EntityUid>? StoredEntities { get; }
|
2020-10-14 15:24:07 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes from the storage container and updates the stored value
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entity">The entity to remove</param>
|
|
|
|
|
/// <returns>True if no longer in storage, false otherwise</returns>
|
2021-12-04 12:59:44 +01:00
|
|
|
public abstract bool Remove(EntityUid entity);
|
2020-10-14 15:24:07 +02:00
|
|
|
|
2021-05-22 21:06:40 -07:00
|
|
|
bool IDraggable.CanDrop(CanDropEvent args)
|
2020-10-14 15:24:07 +02:00
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
return _entMan.TryGetComponent(args.Target, out PlaceableSurfaceComponent? placeable) &&
|
2020-10-14 15:24:07 +02:00
|
|
|
placeable.IsPlaceable;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-22 21:06:40 -07:00
|
|
|
bool IDraggable.Drop(DragDropEvent eventArgs)
|
2020-10-14 15:24:07 +02:00
|
|
|
{
|
2022-02-15 17:06:52 +13:00
|
|
|
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User, eventArgs.Target))
|
2020-10-14 15:24:07 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var storedEntities = StoredEntities?.ToArray();
|
|
|
|
|
|
|
|
|
|
if (storedEntities == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// empty everything out
|
|
|
|
|
foreach (var storedEntity in storedEntities)
|
|
|
|
|
{
|
|
|
|
|
if (Remove(storedEntity))
|
2021-12-08 17:32:32 +01:00
|
|
|
_entMan.GetComponent<TransformComponent>(storedEntity).WorldPosition = eventArgs.DropLocation.Position;
|
2020-10-14 15:24:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-03 22:07:13 +00:00
|
|
|
/// <summary>
|
2022-03-30 16:23:20 -07:00
|
|
|
/// Network event for displaying an animation of entities flying into a storage entity
|
2021-02-03 22:07:13 +00:00
|
|
|
/// </summary>
|
|
|
|
|
[Serializable, NetSerializable]
|
2022-03-30 16:23:20 -07:00
|
|
|
public sealed class AnimateInsertingEntitiesEvent : EntityEventArgs
|
2021-02-03 22:07:13 +00:00
|
|
|
{
|
2022-03-30 16:23:20 -07:00
|
|
|
public readonly EntityUid Storage;
|
2021-02-03 22:07:13 +00:00
|
|
|
public readonly List<EntityUid> StoredEntities;
|
|
|
|
|
public readonly List<EntityCoordinates> EntityPositions;
|
2022-03-30 16:23:20 -07:00
|
|
|
|
|
|
|
|
public AnimateInsertingEntitiesEvent(EntityUid storage, List<EntityUid> storedEntities, List<EntityCoordinates> entityPositions)
|
2021-02-03 22:07:13 +00:00
|
|
|
{
|
2022-03-30 16:23:20 -07:00
|
|
|
Storage = storage;
|
2021-02-03 22:07:13 +00:00
|
|
|
StoredEntities = storedEntities;
|
|
|
|
|
EntityPositions = entityPositions;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-05 18:52:06 +02:00
|
|
|
[NetSerializable]
|
|
|
|
|
[Serializable]
|
|
|
|
|
public enum StorageVisuals
|
|
|
|
|
{
|
2020-05-25 13:58:56 +02:00
|
|
|
Open,
|
2020-10-28 22:51:43 +00:00
|
|
|
CanWeld,
|
2020-05-25 13:58:56 +02:00
|
|
|
Welded,
|
2020-10-28 22:51:43 +00:00
|
|
|
CanLock,
|
2020-05-25 13:58:56 +02:00
|
|
|
Locked
|
2019-05-05 18:52:06 +02:00
|
|
|
}
|
2018-04-22 06:11:38 -05:00
|
|
|
}
|