MindComponent.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using Content.Shared.GameTicking;
  2. using Content.Shared.Mind.Components;
  3. using Robust.Shared.GameStates;
  4. using Robust.Shared.Network;
  5. using Robust.Shared.Player;
  6. using Robust.Shared.Prototypes;
  7. namespace Content.Shared.Mind;
  8. /// <summary>
  9. /// This component stores information about a player/mob mind. The component will be attached to a mind-entity
  10. /// which is stored in null-space. The entity that is currently "possessed" by the mind will have a
  11. /// <see cref="MindContainerComponent"/>.
  12. /// </summary>
  13. /// <remarks>
  14. /// Roles are attached as components on the mind-entity entity.
  15. /// Think of it like this: if a player is supposed to have their memories,
  16. /// their mind follows along.
  17. ///
  18. /// Things such as respawning do not follow, because you're a new character.
  19. /// Getting borged, cloned, turned into a catbeast, etc... will keep it following you.
  20. ///
  21. /// Minds are stored in null-space, and are thus generally not set to players unless that player is the owner
  22. /// of the mind. As a result it should be safe to network "secret" information like roles & objectives
  23. /// </remarks>
  24. [RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
  25. public sealed partial class MindComponent : Component
  26. {
  27. [DataField, AutoNetworkedField]
  28. public List<EntityUid> Objectives = new();
  29. /// <summary>
  30. /// The session ID of the player owning this mind.
  31. /// </summary>
  32. [DataField, AutoNetworkedField, Access(typeof(SharedMindSystem))]
  33. public NetUserId? UserId { get; set; }
  34. /// <summary>
  35. /// The session ID of the original owner, if any.
  36. /// May end up used for round-end information (as the owner may have abandoned Mind since)
  37. /// </summary>
  38. [DataField, AutoNetworkedField, Access(typeof(SharedMindSystem))]
  39. public NetUserId? OriginalOwnerUserId { get; set; }
  40. /// <summary>
  41. /// The first entity that this mind controlled. Used for round end information.
  42. /// Might be relevant if the player has ghosted since.
  43. /// </summary>
  44. [AutoNetworkedField]
  45. public NetEntity? OriginalOwnedEntity; // TODO WeakEntityReference make this a Datafield again
  46. // This is a net entity, because this field currently does not get set to null when this entity is deleted.
  47. // This is a lazy way to ensure that people check that the entity still exists.
  48. // TODO MIND Fix this properly by adding an OriginalMindContainerComponent or something like that.
  49. [ViewVariables]
  50. public bool IsVisitingEntity => VisitingEntity != null;
  51. [DataField, AutoNetworkedField, Access(typeof(SharedMindSystem))]
  52. public EntityUid? VisitingEntity { get; set; }
  53. [ViewVariables]
  54. public EntityUid? CurrentEntity => VisitingEntity ?? OwnedEntity;
  55. [DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
  56. public string? CharacterName { get; set; }
  57. /// <summary>
  58. /// The time of death for this Mind.
  59. /// Can be null - will be null if the Mind is not considered "dead".
  60. /// </summary>
  61. [DataField]
  62. public TimeSpan? TimeOfDeath { get; set; }
  63. /// <summary>
  64. /// The entity currently owned by this mind.
  65. /// Can be null.
  66. /// </summary>
  67. [DataField, AutoNetworkedField, Access(typeof(SharedMindSystem))]
  68. public EntityUid? OwnedEntity { get; set; }
  69. /// <summary>
  70. /// An enumerable over all the objective entities this mind has.
  71. /// </summary>
  72. [ViewVariables, Obsolete("Use Objectives field")]
  73. public IEnumerable<EntityUid> AllObjectives => Objectives;
  74. /// <summary>
  75. /// Prevents user from ghosting out
  76. /// </summary>
  77. [DataField]
  78. public bool PreventGhosting { get; set; }
  79. /// <summary>
  80. /// Prevents user from suiciding
  81. /// </summary>
  82. [DataField]
  83. public bool PreventSuicide { get; set; }
  84. /// <summary>
  85. /// Mind Role Entities belonging to this Mind
  86. /// </summary>
  87. [DataField, AutoNetworkedField]
  88. public List<EntityUid> MindRoles = new List<EntityUid>();
  89. /// <summary>
  90. /// The mind's current antagonist/special role, or lack thereof;
  91. /// </summary>
  92. [DataField, AutoNetworkedField]
  93. public ProtoId<RoleTypePrototype> RoleType = "Neutral";
  94. /// <summary>
  95. /// The session of the player owning this mind.
  96. /// Can be null, in which case the player is currently not logged in.
  97. /// </summary>
  98. [ViewVariables, Access(typeof(SharedMindSystem), typeof(SharedGameTicker))]
  99. // TODO remove this after moving IPlayerManager functions to shared
  100. public ICommonSession? Session { get; set; }
  101. }