1
0

SharedEntityStorageComponent.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System.Numerics;
  2. using Content.Shared.Physics;
  3. using Content.Shared.Whitelist;
  4. using Robust.Shared.Audio;
  5. using Robust.Shared.Containers;
  6. using Robust.Shared.GameStates;
  7. using Robust.Shared.Serialization;
  8. namespace Content.Shared.Storage.Components;
  9. [NetworkedComponent]
  10. public abstract partial class SharedEntityStorageComponent : Component
  11. {
  12. public readonly float MaxSize = 1.0f; // maximum width or height of an entity allowed inside the storage.
  13. public static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5);
  14. public TimeSpan NextInternalOpenAttempt;
  15. /// <summary>
  16. /// Collision masks that get removed when the storage gets opened.
  17. /// </summary>
  18. public readonly int MasksToRemove = (int) (
  19. CollisionGroup.MidImpassable |
  20. CollisionGroup.HighImpassable |
  21. CollisionGroup.LowImpassable);
  22. /// <summary>
  23. /// Collision masks that were removed from ANY layer when the storage was opened;
  24. /// </summary>
  25. [DataField]
  26. public int RemovedMasks;
  27. /// <summary>
  28. /// The total amount of items that can fit in one entitystorage
  29. /// </summary>
  30. [DataField, ViewVariables(VVAccess.ReadWrite)]
  31. public int Capacity = 30;
  32. /// <summary>
  33. /// Whether or not the entity still has collision when open
  34. /// </summary>
  35. [DataField, ViewVariables(VVAccess.ReadWrite)]
  36. public bool IsCollidableWhenOpen;
  37. /// <summary>
  38. /// If true, it opens the storage when the entity inside of it moves
  39. /// If false, it prevents the storage from opening when the entity inside of it moves.
  40. /// This is for objects that you want the player to move while inside, like large cardboard boxes, without opening the storage.
  41. /// </summary>
  42. [DataField, ViewVariables(VVAccess.ReadWrite)]
  43. public bool OpenOnMove = true;
  44. //The offset for where items are emptied/vacuumed for the EntityStorage.
  45. [DataField, ViewVariables(VVAccess.ReadWrite)]
  46. public Vector2 EnteringOffset = new(0, 0);
  47. //The collision groups checked, so that items are depositied or grabbed from inside walls.
  48. [DataField, ViewVariables(VVAccess.ReadWrite)]
  49. public CollisionGroup EnteringOffsetCollisionFlags = CollisionGroup.Impassable | CollisionGroup.MidImpassable;
  50. /// <summary>
  51. /// How close you have to be to the "entering" spot to be able to enter
  52. /// </summary>
  53. [DataField, ViewVariables(VVAccess.ReadWrite)]
  54. public float EnteringRange = 0.18f;
  55. /// <summary>
  56. /// Whether or not to show the contents when the storage is closed
  57. /// </summary>
  58. [DataField, ViewVariables(VVAccess.ReadWrite)]
  59. public bool ShowContents;
  60. /// <summary>
  61. /// Whether or not light is occluded by the storage
  62. /// </summary>
  63. [DataField, ViewVariables(VVAccess.ReadWrite)]
  64. public bool OccludesLight = true;
  65. /// <summary>
  66. /// Whether or not all the contents stored should be deleted with the entitystorage
  67. /// </summary>
  68. [DataField, ViewVariables(VVAccess.ReadWrite)]
  69. public bool DeleteContentsOnDestruction;
  70. /// <summary>
  71. /// Whether or not the container is sealed and traps air inside of it
  72. /// </summary>
  73. [DataField, ViewVariables(VVAccess.ReadWrite)]
  74. public bool Airtight = true;
  75. /// <summary>
  76. /// Whether or not the entitystorage is open or closed
  77. /// </summary>
  78. [DataField]
  79. public bool Open;
  80. /// <summary>
  81. /// The sound made when closed
  82. /// </summary>
  83. [DataField]
  84. public SoundSpecifier CloseSound = new SoundPathSpecifier("/Audio/Effects/closetclose.ogg");
  85. /// <summary>
  86. /// The sound made when open
  87. /// </summary>
  88. [DataField]
  89. public SoundSpecifier OpenSound = new SoundPathSpecifier("/Audio/Effects/closetopen.ogg");
  90. /// <summary>
  91. /// Whitelist for what entities are allowed to be inserted into this container. If this is not null, the
  92. /// standard requirement that the entity must be an item or mob is waived.
  93. /// </summary>
  94. [DataField]
  95. public EntityWhitelist? Whitelist;
  96. /// <summary>
  97. /// The contents of the storage
  98. /// </summary>
  99. [ViewVariables]
  100. public Container Contents = default!;
  101. }
  102. [Serializable, NetSerializable]
  103. public sealed class EntityStorageComponentState : ComponentState
  104. {
  105. public bool Open;
  106. public int Capacity;
  107. public bool IsCollidableWhenOpen;
  108. public bool OpenOnMove;
  109. public float EnteringRange;
  110. public TimeSpan NextInternalOpenAttempt;
  111. public EntityStorageComponentState(bool open, int capacity, bool isCollidableWhenOpen, bool openOnMove, float enteringRange, TimeSpan nextInternalOpenAttempt)
  112. {
  113. Open = open;
  114. Capacity = capacity;
  115. IsCollidableWhenOpen = isCollidableWhenOpen;
  116. OpenOnMove = openOnMove;
  117. EnteringRange = enteringRange;
  118. NextInternalOpenAttempt = nextInternalOpenAttempt;
  119. }
  120. }
  121. [ByRefEvent]
  122. public record struct InsertIntoEntityStorageAttemptEvent(EntityUid ItemToInsert, bool Cancelled = false);
  123. [ByRefEvent]
  124. public record struct StorageOpenAttemptEvent(EntityUid User, bool Silent, bool Cancelled = false);
  125. [ByRefEvent]
  126. public readonly record struct StorageBeforeOpenEvent;
  127. [ByRefEvent]
  128. public readonly record struct StorageAfterOpenEvent;
  129. [ByRefEvent]
  130. public record struct StorageCloseAttemptEvent(bool Cancelled = false);
  131. [ByRefEvent]
  132. public readonly record struct StorageBeforeCloseEvent(HashSet<EntityUid> Contents, HashSet<EntityUid> BypassChecks);
  133. [ByRefEvent]
  134. public readonly record struct StorageAfterCloseEvent;