1
0

SharedDisposalUnitComponent.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using Robust.Shared.Audio;
  2. using Content.Shared.Whitelist;
  3. using Robust.Shared.Containers;
  4. using Robust.Shared.GameStates;
  5. using Robust.Shared.Serialization;
  6. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
  7. namespace Content.Shared.Disposal.Components;
  8. [NetworkedComponent]
  9. public abstract partial class SharedDisposalUnitComponent : Component
  10. {
  11. public const string ContainerId = "disposals";
  12. /// <summary>
  13. /// Sounds played upon the unit flushing.
  14. /// </summary>
  15. [ViewVariables(VVAccess.ReadWrite), DataField("soundFlush")]
  16. public SoundSpecifier? FlushSound = new SoundPathSpecifier("/Audio/Machines/disposalflush.ogg");
  17. /// <summary>
  18. /// Blacklists (prevents) entities listed from being placed inside.
  19. /// </summary>
  20. [DataField]
  21. public EntityWhitelist? Blacklist;
  22. /// <summary>
  23. /// Whitelists (allows) entities listed from being placed inside.
  24. /// </summary>
  25. [DataField]
  26. public EntityWhitelist? Whitelist;
  27. /// <summary>
  28. /// Sound played when an object is inserted into the disposal unit.
  29. /// </summary>
  30. [ViewVariables(VVAccess.ReadWrite), DataField("soundInsert")]
  31. public SoundSpecifier? InsertSound = new SoundPathSpecifier("/Audio/Effects/trashbag1.ogg");
  32. /// <summary>
  33. /// State for this disposals unit.
  34. /// </summary>
  35. [DataField]
  36. public DisposalsPressureState State;
  37. // TODO: Just make this use vaulting.
  38. /// <summary>
  39. /// We'll track whatever just left disposals so we know what collision we need to ignore until they stop intersecting our BB.
  40. /// </summary>
  41. [ViewVariables, DataField]
  42. public List<EntityUid> RecentlyEjected = new();
  43. /// <summary>
  44. /// Next time the disposal unit will be pressurized.
  45. /// </summary>
  46. [DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
  47. public TimeSpan NextPressurized = TimeSpan.Zero;
  48. /// <summary>
  49. /// How long it takes to flush a disposals unit manually.
  50. /// </summary>
  51. [DataField("flushTime")]
  52. public TimeSpan ManualFlushTime = TimeSpan.FromSeconds(2);
  53. /// <summary>
  54. /// How long it takes from the start of a flush animation to return the sprite to normal.
  55. /// </summary>
  56. [DataField]
  57. public TimeSpan FlushDelay = TimeSpan.FromSeconds(3);
  58. /// <summary>
  59. /// Removes the pressure requirement for flushing.
  60. /// </summary>
  61. [DataField, ViewVariables(VVAccess.ReadWrite)]
  62. public bool DisablePressure;
  63. /// <summary>
  64. /// Last time that an entity tried to exit this disposal unit.
  65. /// </summary>
  66. [ViewVariables]
  67. public TimeSpan LastExitAttempt;
  68. [DataField]
  69. public bool AutomaticEngage = true;
  70. [ViewVariables(VVAccess.ReadWrite)]
  71. [DataField]
  72. public TimeSpan AutomaticEngageTime = TimeSpan.FromSeconds(30);
  73. /// <summary>
  74. /// Delay from trying to enter disposals ourselves.
  75. /// </summary>
  76. [ViewVariables(VVAccess.ReadWrite)]
  77. [DataField]
  78. public float EntryDelay = 0.5f;
  79. /// <summary>
  80. /// Delay from trying to shove someone else into disposals.
  81. /// </summary>
  82. [ViewVariables(VVAccess.ReadWrite)]
  83. public float DraggedEntryDelay = 2.0f;
  84. /// <summary>
  85. /// Container of entities inside this disposal unit.
  86. /// </summary>
  87. [ViewVariables] public Container Container = default!;
  88. // TODO: Network power shit instead fam.
  89. [ViewVariables, DataField]
  90. public bool Powered;
  91. /// <summary>
  92. /// Was the disposals unit engaged for a manual flush.
  93. /// </summary>
  94. [ViewVariables(VVAccess.ReadWrite), DataField]
  95. public bool Engaged;
  96. /// <summary>
  97. /// Next time this unit will flush. Is the lesser of <see cref="FlushDelay"/> and <see cref="AutomaticEngageTime"/>
  98. /// </summary>
  99. [ViewVariables, DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
  100. public TimeSpan? NextFlush;
  101. [Serializable, NetSerializable]
  102. public enum Visuals : byte
  103. {
  104. VisualState,
  105. Handle,
  106. Light
  107. }
  108. [Serializable, NetSerializable]
  109. public enum VisualState : byte
  110. {
  111. UnAnchored,
  112. Anchored,
  113. OverlayFlushing,
  114. OverlayCharging
  115. }
  116. [Serializable, NetSerializable]
  117. public enum HandleState : byte
  118. {
  119. Normal,
  120. Engaged
  121. }
  122. [Serializable, NetSerializable]
  123. [Flags]
  124. public enum LightStates : byte
  125. {
  126. Off = 0,
  127. Charging = 1 << 0,
  128. Full = 1 << 1,
  129. Ready = 1 << 2
  130. }
  131. [Serializable, NetSerializable]
  132. public enum UiButton : byte
  133. {
  134. Eject,
  135. Engage,
  136. Power
  137. }
  138. [Serializable, NetSerializable]
  139. public sealed class DisposalUnitBoundUserInterfaceState : BoundUserInterfaceState, IEquatable<DisposalUnitBoundUserInterfaceState>
  140. {
  141. public readonly string UnitName;
  142. public readonly string UnitState;
  143. public readonly TimeSpan FullPressureTime;
  144. public readonly bool Powered;
  145. public readonly bool Engaged;
  146. public DisposalUnitBoundUserInterfaceState(string unitName, string unitState, TimeSpan fullPressureTime, bool powered,
  147. bool engaged)
  148. {
  149. UnitName = unitName;
  150. UnitState = unitState;
  151. FullPressureTime = fullPressureTime;
  152. Powered = powered;
  153. Engaged = engaged;
  154. }
  155. public bool Equals(DisposalUnitBoundUserInterfaceState? other)
  156. {
  157. if (ReferenceEquals(null, other)) return false;
  158. if (ReferenceEquals(this, other)) return true;
  159. return UnitName == other.UnitName &&
  160. UnitState == other.UnitState &&
  161. Powered == other.Powered &&
  162. Engaged == other.Engaged &&
  163. FullPressureTime.Equals(other.FullPressureTime);
  164. }
  165. }
  166. /// <summary>
  167. /// Message data sent from client to server when a disposal unit ui button is pressed.
  168. /// </summary>
  169. [Serializable, NetSerializable]
  170. public sealed class UiButtonPressedMessage : BoundUserInterfaceMessage
  171. {
  172. public readonly UiButton Button;
  173. public UiButtonPressedMessage(UiButton button)
  174. {
  175. Button = button;
  176. }
  177. }
  178. [Serializable, NetSerializable]
  179. public enum DisposalUnitUiKey : byte
  180. {
  181. Key
  182. }
  183. }
  184. [Serializable, NetSerializable]
  185. public enum DisposalsPressureState : byte
  186. {
  187. Ready,
  188. /// <summary>
  189. /// Has been flushed recently within FlushDelay.
  190. /// </summary>
  191. Flushed,
  192. /// <summary>
  193. /// FlushDelay has elapsed and now we're transitioning back to Ready.
  194. /// </summary>
  195. Pressurizing
  196. }