2020-10-14 15:24:07 +02:00
|
|
|
using System;
|
2018-04-22 06:11:38 -05:00
|
|
|
using System.Collections.Generic;
|
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;
|
2021-06-19 10:03:24 +02:00
|
|
|
using Content.Shared.Interaction.Events;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Placeable;
|
2019-11-13 17:37:46 -05:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2021-12-03 14:17:01 +01:00
|
|
|
using Robust.Shared.IoC;
|
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
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class StorageComponentState : ComponentState
|
2020-10-14 15:24:07 +02:00
|
|
|
{
|
|
|
|
|
public readonly EntityUid[] StoredEntities;
|
|
|
|
|
|
2021-07-12 01:32:10 -07:00
|
|
|
public StorageComponentState(EntityUid[] storedEntities)
|
2020-10-14 15:24:07 +02:00
|
|
|
{
|
|
|
|
|
StoredEntities = storedEntities;
|
|
|
|
|
}
|
2018-04-22 06:11:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the client component about what entities this storage is holding
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable, NetSerializable]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class StorageHeldItemsMessage : ComponentMessage
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2018-04-22 06:11:38 -05:00
|
|
|
{
|
|
|
|
|
public readonly int StorageSizeMax;
|
|
|
|
|
public readonly int StorageSizeUsed;
|
2020-10-14 15:24:07 +02:00
|
|
|
public readonly EntityUid[] StoredEntities;
|
2018-04-22 06:11:38 -05:00
|
|
|
|
2020-10-14 15:24:07 +02:00
|
|
|
public StorageHeldItemsMessage(EntityUid[] storedEntities, int storageUsed, int storageMaxSize)
|
2018-04-22 06:11:38 -05:00
|
|
|
{
|
|
|
|
|
Directed = true;
|
2020-10-14 15:24:07 +02:00
|
|
|
StorageSizeMax = storageMaxSize;
|
|
|
|
|
StorageSizeUsed = storageUsed;
|
|
|
|
|
StoredEntities = storedEntities;
|
2018-04-22 06:11:38 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-17 01:19:35 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Component message for adding an entity to the storage entity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable, NetSerializable]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class InsertEntityMessage : ComponentMessage
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2020-02-17 01:19:35 +02:00
|
|
|
{
|
|
|
|
|
public InsertEntityMessage()
|
|
|
|
|
{
|
|
|
|
|
Directed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-03 22:07:13 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Component message for displaying an animation of entities flying into a storage entity
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable, NetSerializable]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class AnimateInsertingEntitiesMessage : ComponentMessage
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2021-02-03 22:07:13 +00:00
|
|
|
{
|
|
|
|
|
public readonly List<EntityUid> StoredEntities;
|
|
|
|
|
public readonly List<EntityCoordinates> EntityPositions;
|
|
|
|
|
public AnimateInsertingEntitiesMessage(List<EntityUid> storedEntities, List<EntityCoordinates> entityPositions)
|
|
|
|
|
{
|
|
|
|
|
Directed = true;
|
|
|
|
|
StoredEntities = storedEntities;
|
|
|
|
|
EntityPositions = entityPositions;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 06:11:38 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Component message for removing a contained entity from the storage entity
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable, NetSerializable]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class RemoveEntityMessage : ComponentMessage
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2018-04-22 06:11:38 -05:00
|
|
|
{
|
|
|
|
|
public EntityUid EntityUid;
|
|
|
|
|
|
|
|
|
|
public RemoveEntityMessage(EntityUid entityuid)
|
|
|
|
|
{
|
|
|
|
|
Directed = true;
|
|
|
|
|
EntityUid = entityuid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Component message for opening the storage UI
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable, NetSerializable]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class OpenStorageUIMessage : ComponentMessage
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2018-04-22 06:11:38 -05:00
|
|
|
{
|
|
|
|
|
public OpenStorageUIMessage()
|
|
|
|
|
{
|
|
|
|
|
Directed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-20 16:49:13 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Component message for closing the storage UI.
|
|
|
|
|
/// E.g when the player moves too far away from the container.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable, NetSerializable]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class CloseStorageUIMessage : ComponentMessage
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2018-06-20 16:49:13 -04:00
|
|
|
{
|
|
|
|
|
public CloseStorageUIMessage()
|
|
|
|
|
{
|
|
|
|
|
Directed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
}
|