Files
wylab-station-14/Content.Shared/Storage/Components/EntityStorageComponent.cs
2025-12-02 18:33:40 +00:00

186 lines
6.2 KiB
C#

using System.Numerics;
using Content.Shared.Atmos;
using Content.Shared.Physics;
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
namespace Content.Shared.Storage.Components;
/// <summary>
/// A storage component that stores nearby entities in a container when this object is opened or closed.
/// This does not have an UI like grid storage, but just makes them disappear inside.
/// Used for lockers, crates etc.
/// </summary>
[RegisterComponent, NetworkedComponent]
[AutoGenerateComponentState, AutoGenerateComponentPause] // TODO: Field deltas
public sealed partial class EntityStorageComponent : Component, IGasMixtureHolder
{
/// <summary>
/// Maximum width or height of an entity allowed inside the storage.
/// </summary>
[DataField, AutoNetworkedField]
public float MaxSize = 1.0f;
/// <summary>
/// The delay between opening attempts when stuck inside an entity storage.
/// </summary>
[DataField, AutoNetworkedField]
public TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5);
/// <summary>
/// The next time a player stuck inside the entity storage can attempt to open it from inside.
/// </summary>
[DataField, AutoNetworkedField, AutoPausedField]
public TimeSpan NextInternalOpenAttempt;
/// <summary>
/// Collision masks that get removed when the storage gets opened.
/// </summary>
[DataField]
public int MasksToRemove = (int)(
CollisionGroup.MidImpassable |
CollisionGroup.HighImpassable |
CollisionGroup.LowImpassable);
/// <summary>
/// Collision masks that were removed from ANY layer when the storage was opened;
/// </summary>
[DataField]
public int RemovedMasks;
/// <summary>
/// The total amount of items that can fit in one entitystorage.
/// </summary>
[DataField, AutoNetworkedField]
public int Capacity = 30;
/// <summary>
/// Whether or not the entity still has collision when open.
/// </summary>
[DataField, AutoNetworkedField]
public bool IsCollidableWhenOpen;
/// <summary>
/// If true, it opens the storage when the entity inside of it moves
/// If false, it prevents the storage from opening when the entity inside of it moves.
/// This is for objects that you want the player to move while inside, like large cardboard boxes, without opening the storage.
/// </summary>
[DataField, AutoNetworkedField]
public bool OpenOnMove = true;
//The offset for where items are emptied/vacuumed for the EntityStorage.
[DataField]
public Vector2 EnteringOffset = new(0, 0);
//The collision groups checked, so that items are depositied or grabbed from inside walls.
[DataField]
public CollisionGroup EnteringOffsetCollisionFlags = CollisionGroup.Impassable | CollisionGroup.MidImpassable;
/// <summary>
/// How close you have to be to the "entering" spot to be able to enter.
/// </summary>
[DataField, AutoNetworkedField]
public float EnteringRange = 0.18f;
/// <summary>
/// Whether or not to show the contents when the storage is closed.
/// </summary>
[DataField]
public bool ShowContents;
/// <summary>
/// Whether or not light is occluded by the storage.
/// </summary>
[DataField]
public bool OccludesLight = true;
/// <summary>
/// Whether or not all the contents stored should be deleted with the entitystorage.
/// </summary>
[DataField]
public bool DeleteContentsOnDestruction;
/// <summary>
/// Whether or not the container is sealed and traps air inside of it.
/// </summary>
[DataField]
public bool Airtight = true;
/// <summary>
/// Whether or not the entitystorage is open or closed.
/// </summary>
[DataField, AutoNetworkedField]
public bool Open;
/// <summary>
/// The sound made when closed.
/// </summary>
[DataField]
public SoundSpecifier CloseSound = new SoundPathSpecifier("/Audio/Effects/closetclose.ogg");
/// <summary>
/// The sound made when opened.
/// </summary>
[DataField]
public SoundSpecifier OpenSound = new SoundPathSpecifier("/Audio/Effects/closetopen.ogg");
/// <summary>
/// Whitelist for what entities are allowed to be inserted into this container. If this is not null, the
/// standard requirement that the entity must be an item or mob is waived.
/// </summary>
[DataField]
public EntityWhitelist? Whitelist;
/// <summary>
/// The contents of the storage.
/// </summary>
[ViewVariables]
public Container Contents = default!;
/// <summary>
/// Gas currently contained in this entity storage.
/// None while open. Grabs gas from the atmosphere when closed, and exposes any entities inside to it.
/// </summary>
[DataField]
public GasMixture Air { get; set; } = new(200);
}
/// <summary>
/// Raised on the entity being inserted whenever checking if an entity can be inserted into an entity storage.
/// </summary>
[ByRefEvent]
public record struct InsertIntoEntityStorageAttemptEvent(BaseContainer Container, EntityUid ItemToInsert, bool Cancelled = false);
/// <summary>
/// Raised on the entity storage whenever checking if an entity can be inserted into it.
/// </summary>
[ByRefEvent]
public record struct EntityStorageInsertedIntoAttemptEvent(BaseContainer Container, EntityUid ItemToInsert, bool Cancelled = false);
/// <summary>
/// Raised on the Container's owner whenever an entity storage tries to dump its
/// contents while within a container.
/// </summary>
[ByRefEvent]
public record struct EntityStorageIntoContainerAttemptEvent(BaseContainer Container, bool Cancelled = false);
[ByRefEvent]
public record struct StorageOpenAttemptEvent(EntityUid User, bool Silent, bool Cancelled = false);
[ByRefEvent]
public readonly record struct StorageBeforeOpenEvent;
[ByRefEvent]
public readonly record struct StorageAfterOpenEvent;
[ByRefEvent]
public record struct StorageCloseAttemptEvent(EntityUid? User, bool Cancelled = false);
[ByRefEvent]
public readonly record struct StorageBeforeCloseEvent(HashSet<EntityUid> Contents, HashSet<EntityUid> BypassChecks);
[ByRefEvent]
public readonly record struct StorageAfterCloseEvent;