BuckleComponent.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System.Diagnostics.CodeAnalysis;
  2. using Content.Shared.Alert;
  3. using Content.Shared.Interaction;
  4. using Robust.Shared.GameStates;
  5. using Robust.Shared.Serialization;
  6. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
  7. namespace Content.Shared.Buckle.Components;
  8. /// <summary>
  9. /// This component allows an entity to be buckled to an entity with a <see cref="StrapComponent"/>.
  10. /// </summary>
  11. [RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
  12. [Access(typeof(SharedBuckleSystem))]
  13. public sealed partial class BuckleComponent : Component
  14. {
  15. /// <summary>
  16. /// The range from which this entity can buckle to a <see cref="StrapComponent"/>.
  17. /// Separated from normal interaction range to fix the "someone buckled to a strap
  18. /// across a table two tiles away" problem.
  19. /// </summary>
  20. [DataField]
  21. public float Range = SharedInteractionSystem.InteractionRange;
  22. /// <summary>
  23. /// True if the entity is buckled, false otherwise.
  24. /// </summary>
  25. [MemberNotNullWhen(true, nameof(BuckledTo))]
  26. public bool Buckled => BuckledTo != null;
  27. /// <summary>
  28. /// Whether or not collisions should be possible with the entity we are strapped to
  29. /// </summary>
  30. [DataField, AutoNetworkedField]
  31. public bool DontCollide;
  32. /// <summary>
  33. /// Whether or not we should be allowed to pull the entity we are strapped to
  34. /// </summary>
  35. [DataField]
  36. public bool PullStrap;
  37. /// <summary>
  38. /// The amount of time that must pass for this entity to
  39. /// be able to unbuckle after recently buckling.
  40. /// </summary>
  41. [DataField]
  42. public TimeSpan Delay = TimeSpan.FromSeconds(0.25f);
  43. /// <summary>
  44. /// The time that this entity buckled at.
  45. /// </summary>
  46. [DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField, AutoNetworkedField]
  47. public TimeSpan? BuckleTime;
  48. /// <summary>
  49. /// The strap that this component is buckled to.
  50. /// </summary>
  51. [DataField, AutoNetworkedField]
  52. public EntityUid? BuckledTo;
  53. /// <summary>
  54. /// The amount of space that this entity occupies in a
  55. /// <see cref="StrapComponent"/>.
  56. /// </summary>
  57. [DataField]
  58. public int Size = 100;
  59. /// <summary>
  60. /// Used for client rendering
  61. /// </summary>
  62. [ViewVariables] public int? OriginalDrawDepth;
  63. }
  64. public sealed partial class UnbuckleAlertEvent : BaseAlertEvent;
  65. /// <summary>
  66. /// Event raised directed at a strap entity before some entity gets buckled to it.
  67. /// </summary>
  68. [ByRefEvent]
  69. public record struct StrapAttemptEvent(
  70. Entity<StrapComponent> Strap,
  71. Entity<BuckleComponent> Buckle,
  72. EntityUid? User,
  73. bool Popup)
  74. {
  75. public bool Cancelled;
  76. }
  77. /// <summary>
  78. /// Event raised directed at a buckle entity before it gets buckled to some strap entity.
  79. /// </summary>
  80. [ByRefEvent]
  81. public record struct BuckleAttemptEvent(
  82. Entity<StrapComponent> Strap,
  83. Entity<BuckleComponent> Buckle,
  84. EntityUid? User,
  85. bool Popup)
  86. {
  87. public bool Cancelled;
  88. }
  89. /// <summary>
  90. /// Event raised directed at a strap entity before some entity gets unbuckled from it.
  91. /// </summary>
  92. [ByRefEvent]
  93. public record struct UnstrapAttemptEvent(
  94. Entity<StrapComponent> Strap,
  95. Entity<BuckleComponent> Buckle,
  96. EntityUid? User,
  97. bool Popup)
  98. {
  99. public bool Cancelled;
  100. }
  101. /// <summary>
  102. /// Event raised directed at a buckle entity before it gets unbuckled.
  103. /// </summary>
  104. [ByRefEvent]
  105. public record struct UnbuckleAttemptEvent(
  106. Entity<StrapComponent> Strap,
  107. Entity<BuckleComponent> Buckle,
  108. EntityUid? User,
  109. bool Popup)
  110. {
  111. public bool Cancelled;
  112. }
  113. /// <summary>
  114. /// Event raised directed at a strap entity after something has been buckled to it.
  115. /// </summary>
  116. [ByRefEvent]
  117. public readonly record struct StrappedEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
  118. /// <summary>
  119. /// Event raised directed at a buckle entity after it has been buckled.
  120. /// </summary>
  121. [ByRefEvent]
  122. public readonly record struct BuckledEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
  123. /// <summary>
  124. /// Event raised directed at a strap entity after something has been unbuckled from it.
  125. /// </summary>
  126. [ByRefEvent]
  127. public readonly record struct UnstrappedEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
  128. /// <summary>
  129. /// Event raised directed at a buckle entity after it has been unbuckled from some strap entity.
  130. /// </summary>
  131. [ByRefEvent]
  132. public readonly record struct UnbuckledEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
  133. [Serializable, NetSerializable]
  134. public enum BuckleVisuals
  135. {
  136. Buckled
  137. }