JobPrototype.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using Content.Shared.Access;
  2. using Content.Shared.Guidebook;
  3. using Content.Shared.Players.PlayTimeTracking;
  4. using Content.Shared.StatusIcon;
  5. using Robust.Shared.Prototypes;
  6. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  7. namespace Content.Shared.Roles
  8. {
  9. /// <summary>
  10. /// Describes information for a single job on the station.
  11. /// </summary>
  12. [Prototype]
  13. public sealed partial class JobPrototype : IPrototype
  14. {
  15. [ViewVariables]
  16. [IdDataField]
  17. public string ID { get; private set; } = default!;
  18. [DataField("playTimeTracker", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<PlayTimeTrackerPrototype>))]
  19. public string PlayTimeTracker { get; private set; } = string.Empty;
  20. /// <summary>
  21. /// Who is the supervisor for this job.
  22. /// </summary>
  23. [DataField("supervisors")]
  24. public string Supervisors { get; private set; } = "nobody";
  25. /// <summary>
  26. /// The name of this job as displayed to players.
  27. /// </summary>
  28. [DataField("name")]
  29. public string Name { get; private set; } = string.Empty;
  30. [ViewVariables(VVAccess.ReadOnly)]
  31. public string LocalizedName => Loc.GetString(Name);
  32. /// <summary>
  33. /// The "original" name of the role, untranslated.
  34. /// This would be, for example, a medic for the french faction being called Médecin
  35. /// </summary>
  36. [DataField("originalName")]
  37. public string OriginalName { get; private set; } = string.Empty;
  38. /// <summary>
  39. /// The faction this job belongs to. Used to look for spawnpoints.
  40. /// </summary>
  41. [DataField("faction")]
  42. public string Faction { get; private set; } = string.Empty;
  43. /// <summary>
  44. /// The name of this job as displayed to players.
  45. /// </summary>
  46. [DataField("description")]
  47. public string? Description { get; private set; }
  48. [ViewVariables(VVAccess.ReadOnly)]
  49. public string? LocalizedDescription => Description is null ? null : Loc.GetString(Description);
  50. /// <summary>
  51. /// Requirements for the job.
  52. /// </summary>
  53. [DataField, Access(typeof(SharedRoleSystem), Other = AccessPermissions.None)]
  54. public HashSet<JobRequirement>? Requirements;
  55. /// <summary>
  56. /// When true - the station will have anouncement about arrival of this player.
  57. /// </summary>
  58. [DataField("joinNotifyCrew")]
  59. public bool JoinNotifyCrew { get; private set; } = false;
  60. /// <summary>
  61. /// When true - the player will recieve a message about importancy of their job.
  62. /// </summary>
  63. [DataField("requireAdminNotify")]
  64. public bool RequireAdminNotify { get; private set; } = false;
  65. /// <summary>
  66. /// Should this job appear in preferences menu?
  67. /// </summary>
  68. [DataField("setPreference")]
  69. public bool SetPreference { get; private set; } = true;
  70. /// <summary>
  71. /// Should the selected traits be applied for this job?
  72. /// </summary>
  73. [DataField]
  74. public bool ApplyTraits { get; private set; } = true;
  75. /// <summary>
  76. /// Whether this job should show in the ID Card Console.
  77. /// If set to null, it will default to SetPreference's value.
  78. /// </summary>
  79. [DataField]
  80. public bool? OverrideConsoleVisibility { get; private set; } = null;
  81. [DataField("canBeAntag")]
  82. public bool CanBeAntag { get; private set; } = true;
  83. /// <summary>
  84. /// The "weight" or importance of this job. If this number is large, the job system will assign this job
  85. /// before assigning other jobs.
  86. /// </summary>
  87. [DataField("weight")]
  88. public int Weight { get; private set; }
  89. /// <summary>
  90. /// How to sort this job relative to other jobs in the UI.
  91. /// Jobs with a higher value with sort before jobs with a lower value.
  92. /// If not set, <see cref="Weight"/> is used as a fallback.
  93. /// </summary>
  94. [DataField]
  95. public int? DisplayWeight { get; private set; }
  96. public int RealDisplayWeight => DisplayWeight ?? Weight;
  97. /// <summary>
  98. /// A numerical score for how much easier this job is for antagonists.
  99. /// For traitors, reduces starting TC by this amount. Other gamemodes can use it for whatever they find fitting.
  100. /// </summary>
  101. [DataField("antagAdvantage")]
  102. public int AntagAdvantage = 0;
  103. [DataField]
  104. public ProtoId<StartingGearPrototype>? StartingGear { get; private set; }
  105. [DataField]
  106. public List<ProtoId<StartingGearPrototype>>? RandomStartingGears { get; private set; } = new();
  107. /// <summary>
  108. /// Use this to spawn in as a non-humanoid (borg, test subject, etc.)
  109. /// Starting gear will be ignored.
  110. /// If you want to just add special attributes to a humanoid, use AddComponentSpecial instead.
  111. /// </summary>
  112. [DataField("jobEntity", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
  113. public string? JobEntity = null;
  114. /// <summary>
  115. /// Entity to use as a preview in the lobby/character editor.
  116. /// Same restrictions as <see cref="JobEntity"/> apply.
  117. /// </summary>
  118. [DataField]
  119. public EntProtoId? JobPreviewEntity = null;
  120. [DataField]
  121. public ProtoId<JobIconPrototype> Icon { get; private set; } = "JobIconUnknown";
  122. [DataField("special", serverOnly: true)]
  123. public JobSpecial[] Special { get; private set; } = Array.Empty<JobSpecial>();
  124. [DataField("access")]
  125. public IReadOnlyCollection<ProtoId<AccessLevelPrototype>> Access { get; private set; } = Array.Empty<ProtoId<AccessLevelPrototype>>();
  126. [DataField("accessGroups")]
  127. public IReadOnlyCollection<ProtoId<AccessGroupPrototype>> AccessGroups { get; private set; } = Array.Empty<ProtoId<AccessGroupPrototype>>();
  128. [DataField("extendedAccess")]
  129. public IReadOnlyCollection<ProtoId<AccessLevelPrototype>> ExtendedAccess { get; private set; } = Array.Empty<ProtoId<AccessLevelPrototype>>();
  130. [DataField("extendedAccessGroups")]
  131. public IReadOnlyCollection<ProtoId<AccessGroupPrototype>> ExtendedAccessGroups { get; private set; } = Array.Empty<ProtoId<AccessGroupPrototype>>();
  132. [DataField]
  133. public bool Whitelisted;
  134. /// <summary>
  135. /// Optional list of guides associated with this role. If the guides are opened, the first entry in this list
  136. /// will be used to select the currently selected guidebook.
  137. /// </summary>
  138. [DataField]
  139. public List<ProtoId<GuideEntryPrototype>>? Guides;
  140. }
  141. /// <summary>
  142. /// Sorts <see cref="JobPrototype"/>s appropriately for display in the UI,
  143. /// respecting their <see cref="JobPrototype.Weight"/>.
  144. /// </summary>
  145. public sealed class JobUIComparer : IComparer<JobPrototype>
  146. {
  147. public static readonly JobUIComparer Instance = new();
  148. public int Compare(JobPrototype? x, JobPrototype? y)
  149. {
  150. if (ReferenceEquals(x, y))
  151. return 0;
  152. if (ReferenceEquals(null, y))
  153. return 1;
  154. if (ReferenceEquals(null, x))
  155. return -1;
  156. var cmp = -x.RealDisplayWeight.CompareTo(y.RealDisplayWeight);
  157. if (cmp != 0)
  158. return cmp;
  159. return string.Compare(x.ID, y.ID, StringComparison.Ordinal);
  160. }
  161. }
  162. }