TelephoneComponent.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using Content.Shared.Chat;
  2. using Content.Shared.Speech;
  3. using Robust.Shared.Audio;
  4. using Robust.Shared.GameStates;
  5. using Robust.Shared.Serialization;
  6. namespace Content.Shared.Telephone;
  7. [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
  8. [Access(typeof(SharedTelephoneSystem))]
  9. public sealed partial class TelephoneComponent : Component
  10. {
  11. /// <summary>
  12. /// Sets how long the telephone will ring before it automatically hangs up
  13. /// </summary>
  14. [DataField]
  15. public float RingingTimeout = 30;
  16. /// <summary>
  17. /// Sets how long the telephone can remain idle in-call before it automatically hangs up
  18. /// </summary>
  19. [DataField]
  20. public float IdlingTimeout = 60;
  21. /// <summary>
  22. /// Sets how long the telephone will stay in the hanging up state before return to idle
  23. /// </summary>
  24. [DataField]
  25. public float HangingUpTimeout = 2;
  26. /// <summary>
  27. /// Tone played while the phone is ringing
  28. /// </summary>
  29. [DataField]
  30. public SoundSpecifier? RingTone = null;
  31. /// <summary>
  32. /// Sets the number of seconds before the next ring tone is played
  33. /// </summary>
  34. [DataField]
  35. public float RingInterval = 2f;
  36. /// <summary>
  37. /// The time at which the next tone will be played
  38. /// </summary>
  39. [DataField]
  40. public TimeSpan NextRingToneTime;
  41. /// <summary>
  42. /// The volume at which relayed messages are played
  43. /// </summary>
  44. [DataField]
  45. public TelephoneVolume SpeakerVolume = TelephoneVolume.Whisper;
  46. /// <summary>
  47. /// The maximum range at which the telephone initiate a call with another
  48. /// </summary>
  49. [DataField]
  50. public TelephoneRange TransmissionRange = TelephoneRange.Grid;
  51. /// <summary>
  52. /// This telephone will ignore devices that share the same grid as it
  53. /// </summary>
  54. /// <remarks>
  55. /// This bool will be ignored if the <see cref="TransmissionRange"/> is
  56. /// set to <see cref="TelephoneRange.Grid"/>
  57. /// </remarks>
  58. [DataField]
  59. public bool IgnoreTelephonesOnSameGrid = false;
  60. /// <summary>
  61. /// The telephone can only connect with other telephones which have a
  62. /// <see cref="TransmissionRange"/> present in this list
  63. /// </summary>
  64. [DataField]
  65. public List<TelephoneRange> CompatibleRanges = new List<TelephoneRange>() { TelephoneRange.Grid };
  66. /// <summary>
  67. /// The range at which the telephone picks up voices
  68. /// </summary>
  69. [DataField]
  70. public float ListeningRange = 2;
  71. /// <summary>
  72. /// Specifies whether this telephone require power to fucntion
  73. /// </summary>
  74. [DataField]
  75. public bool RequiresPower = true;
  76. /// <summary>
  77. /// This telephone should not appear on public telephone directories
  78. /// </summary>
  79. [DataField]
  80. public bool UnlistedNumber = false;
  81. /// <summary>
  82. /// Speech is relayed through this entity instead of the telephone
  83. /// </summary>
  84. [ViewVariables(VVAccess.ReadOnly)]
  85. public Entity<SpeechComponent>? Speaker = null;
  86. /// <summary>
  87. /// Telephone number for this device
  88. /// </summary>
  89. /// <remarks>
  90. /// For future use - a system for generating and handling telephone numbers has not been implemented yet
  91. /// </remarks>
  92. [ViewVariables]
  93. public int TelephoneNumber = -1;
  94. /// <summary>
  95. /// Linked telephone
  96. /// </summary>
  97. [ViewVariables]
  98. public HashSet<Entity<TelephoneComponent>> LinkedTelephones = new();
  99. /// <summary>
  100. /// Defines the current state the telephone is in
  101. /// </summary>
  102. [ViewVariables, AutoNetworkedField]
  103. public TelephoneState CurrentState = TelephoneState.Idle;
  104. /// <summary>
  105. /// The game tick the current state started
  106. /// </summary>
  107. [ViewVariables]
  108. public TimeSpan StateStartTime;
  109. /// <summary>
  110. /// Sets whether the telphone can pick up nearby speech
  111. /// </summary>
  112. [ViewVariables]
  113. public bool Muted = false;
  114. /// <summary>
  115. /// The presumed name and/or job of the last person to call this telephone
  116. /// and the name of the device that they used to do so
  117. /// </summary>
  118. [ViewVariables, AutoNetworkedField]
  119. public (string?, string?, string?) LastCallerId;
  120. }
  121. #region: Telephone events
  122. /// <summary>
  123. /// Raised when one telephone is attempting to call another
  124. /// </summary>
  125. [ByRefEvent]
  126. public record struct TelephoneCallAttemptEvent(Entity<TelephoneComponent> Source, Entity<TelephoneComponent> Receiver, EntityUid? User)
  127. {
  128. public bool Cancelled = false;
  129. }
  130. /// <summary>
  131. /// Raised when a telephone's state changes
  132. /// </summary>
  133. [ByRefEvent]
  134. public record struct TelephoneStateChangeEvent(TelephoneState OldState, TelephoneState NewState);
  135. /// <summary>
  136. /// Raised when communication between one telephone and another begins
  137. /// </summary>
  138. [ByRefEvent]
  139. public record struct TelephoneCallCommencedEvent(Entity<TelephoneComponent> Receiver);
  140. /// <summary>
  141. /// Raised when a telephone hangs up
  142. /// </summary>
  143. [ByRefEvent]
  144. public record struct TelephoneCallEndedEvent();
  145. /// <summary>
  146. /// Raised when a chat message is sent by a telephone to another
  147. /// </summary>
  148. [ByRefEvent]
  149. public readonly record struct TelephoneMessageSentEvent(string Message, MsgChatMessage ChatMsg, EntityUid MessageSource);
  150. /// <summary>
  151. /// Raised when a chat message is received by a telephone from another
  152. /// </summary>
  153. [ByRefEvent]
  154. public readonly record struct TelephoneMessageReceivedEvent(string Message, MsgChatMessage ChatMsg, EntityUid MessageSource, Entity<TelephoneComponent> TelephoneSource);
  155. #endregion
  156. /// <summary>
  157. /// Options for tailoring telephone calls
  158. /// </summary>
  159. [Serializable, NetSerializable]
  160. public struct TelephoneCallOptions
  161. {
  162. public bool IgnoreRange; // The source can always reach its target
  163. public bool ForceConnect; // The source immediately starts a call with the receiver, potentially interrupting a call that is already in progress
  164. public bool ForceJoin; // The source smoothly joins a call in progress, or starts a normal call with the receiver if there is none
  165. public bool MuteSource; // Chatter from the source is not transmitted - could be used for eavesdropping when combined with 'ForceJoin'
  166. public bool MuteReceiver; // Chatter from the receiver is not transmitted - useful for broadcasting messages to multiple receivers
  167. }
  168. [Serializable, NetSerializable]
  169. public enum TelephoneVisuals : byte
  170. {
  171. Key
  172. }
  173. [Serializable, NetSerializable]
  174. public enum TelephoneState : byte
  175. {
  176. Idle,
  177. Calling,
  178. Ringing,
  179. InCall,
  180. EndingCall
  181. }
  182. [Serializable, NetSerializable]
  183. public enum TelephoneVolume : byte
  184. {
  185. Whisper,
  186. Speak
  187. }
  188. [Serializable, NetSerializable]
  189. public enum TelephoneRange : byte
  190. {
  191. Grid, // Can only reach telephones that are on the same grid
  192. Map, // Can reach any telephone that is on the same map
  193. Unlimited, // Can reach any telephone, across any distance
  194. }