SharedGhostSystem.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using Content.Shared.Emoting;
  2. using Content.Shared.Hands;
  3. using Content.Shared.Interaction.Events;
  4. using Content.Shared.Item;
  5. using Content.Shared.Popups;
  6. using Robust.Shared.Serialization;
  7. namespace Content.Shared.Ghost
  8. {
  9. /// <summary>
  10. /// System for the <see cref="GhostComponent"/>.
  11. /// Prevents ghosts from interacting when <see cref="GhostComponent.CanGhostInteract"/> is false.
  12. /// </summary>
  13. public abstract class SharedGhostSystem : EntitySystem
  14. {
  15. [Dependency] protected readonly SharedPopupSystem Popup = default!;
  16. public override void Initialize()
  17. {
  18. base.Initialize();
  19. SubscribeLocalEvent<GhostComponent, UseAttemptEvent>(OnAttempt);
  20. SubscribeLocalEvent<GhostComponent, InteractionAttemptEvent>(OnAttemptInteract);
  21. SubscribeLocalEvent<GhostComponent, EmoteAttemptEvent>(OnAttempt);
  22. SubscribeLocalEvent<GhostComponent, DropAttemptEvent>(OnAttempt);
  23. SubscribeLocalEvent<GhostComponent, PickupAttemptEvent>(OnAttempt);
  24. }
  25. private void OnAttemptInteract(Entity<GhostComponent> ent, ref InteractionAttemptEvent args)
  26. {
  27. if (!ent.Comp.CanGhostInteract)
  28. args.Cancelled = true;
  29. }
  30. private void OnAttempt(EntityUid uid, GhostComponent component, CancellableEntityEventArgs args)
  31. {
  32. if (!component.CanGhostInteract)
  33. args.Cancel();
  34. }
  35. public void SetTimeOfDeath(EntityUid uid, TimeSpan value, GhostComponent? component)
  36. {
  37. if (!Resolve(uid, ref component))
  38. return;
  39. component.TimeOfDeath = value;
  40. }
  41. public void SetCanReturnToBody(EntityUid uid, bool value, GhostComponent? component = null)
  42. {
  43. if (!Resolve(uid, ref component))
  44. return;
  45. component.CanReturnToBody = value;
  46. }
  47. public void SetCanReturnToBody(GhostComponent component, bool value)
  48. {
  49. component.CanReturnToBody = value;
  50. }
  51. }
  52. /// <summary>
  53. /// A client to server request to get places a ghost can warp to.
  54. /// Response is sent via <see cref="GhostWarpsResponseEvent"/>
  55. /// </summary>
  56. [Serializable, NetSerializable]
  57. public sealed class GhostWarpsRequestEvent : EntityEventArgs
  58. {
  59. }
  60. /// <summary>
  61. /// An individual place a ghost can warp to.
  62. /// This is used as part of <see cref="GhostWarpsResponseEvent"/>
  63. /// </summary>
  64. [Serializable, NetSerializable]
  65. public struct GhostWarp
  66. {
  67. public GhostWarp(NetEntity entity, string displayName, bool isWarpPoint)
  68. {
  69. Entity = entity;
  70. DisplayName = displayName;
  71. IsWarpPoint = isWarpPoint;
  72. }
  73. /// <summary>
  74. /// The entity representing the warp point.
  75. /// This is passed back to the server in <see cref="GhostWarpToTargetRequestEvent"/>
  76. /// </summary>
  77. public NetEntity Entity { get; }
  78. /// <summary>
  79. /// The display name to be surfaced in the ghost warps menu
  80. /// </summary>
  81. public string DisplayName { get; }
  82. /// <summary>
  83. /// Whether this warp represents a warp point or a player
  84. /// </summary>
  85. public bool IsWarpPoint { get; }
  86. }
  87. /// <summary>
  88. /// A server to client response for a <see cref="GhostWarpsRequestEvent"/>.
  89. /// Contains players, and locations a ghost can warp to
  90. /// </summary>
  91. [Serializable, NetSerializable]
  92. public sealed class GhostWarpsResponseEvent : EntityEventArgs
  93. {
  94. public GhostWarpsResponseEvent(List<GhostWarp> warps)
  95. {
  96. Warps = warps;
  97. }
  98. /// <summary>
  99. /// A list of warp points.
  100. /// </summary>
  101. public List<GhostWarp> Warps { get; }
  102. }
  103. /// <summary>
  104. /// A client to server request for their ghost to be warped to an entity
  105. /// </summary>
  106. [Serializable, NetSerializable]
  107. public sealed class GhostWarpToTargetRequestEvent : EntityEventArgs
  108. {
  109. public NetEntity Target { get; }
  110. public GhostWarpToTargetRequestEvent(NetEntity target)
  111. {
  112. Target = target;
  113. }
  114. }
  115. /// <summary>
  116. /// A client to server request for their ghost to be warped to the most followed entity.
  117. /// </summary>
  118. [Serializable, NetSerializable]
  119. public sealed class GhostnadoRequestEvent : EntityEventArgs;
  120. /// <summary>
  121. /// A client to server request for their ghost to return to body
  122. /// </summary>
  123. [Serializable, NetSerializable]
  124. public sealed class GhostReturnToBodyRequest : EntityEventArgs
  125. {
  126. }
  127. /// <summary>
  128. /// A client to server request for their ghost to return to lobby
  129. /// </summary>
  130. [Serializable, NetSerializable]
  131. public sealed class GhostReturnToLobbyRequest : EntityEventArgs
  132. {
  133. }
  134. /// <summary>
  135. /// A server to client update with the available ghost role count
  136. /// </summary>
  137. [Serializable, NetSerializable]
  138. public sealed class GhostUpdateGhostRoleCountEvent : EntityEventArgs
  139. {
  140. public int AvailableGhostRoles { get; }
  141. public GhostUpdateGhostRoleCountEvent(int availableGhostRoleCount)
  142. {
  143. AvailableGhostRoles = availableGhostRoleCount;
  144. }
  145. }
  146. }