JobPrototype.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 name of this job as displayed to players.
  34. /// </summary>
  35. [DataField("description")]
  36. public string? Description { get; private set; }
  37. [ViewVariables(VVAccess.ReadOnly)]
  38. public string? LocalizedDescription => Description is null ? null : Loc.GetString(Description);
  39. /// <summary>
  40. /// Requirements for the job.
  41. /// </summary>
  42. [DataField, Access(typeof(SharedRoleSystem), Other = AccessPermissions.None)]
  43. public HashSet<JobRequirement>? Requirements;
  44. /// <summary>
  45. /// When true - the station will have anouncement about arrival of this player.
  46. /// </summary>
  47. [DataField("joinNotifyCrew")]
  48. public bool JoinNotifyCrew { get; private set; } = false;
  49. /// <summary>
  50. /// When true - the player will recieve a message about importancy of their job.
  51. /// </summary>
  52. [DataField("requireAdminNotify")]
  53. public bool RequireAdminNotify { get; private set; } = false;
  54. /// <summary>
  55. /// Should this job appear in preferences menu?
  56. /// </summary>
  57. [DataField("setPreference")]
  58. public bool SetPreference { get; private set; } = true;
  59. /// <summary>
  60. /// Should the selected traits be applied for this job?
  61. /// </summary>
  62. [DataField]
  63. public bool ApplyTraits { get; private set; } = true;
  64. /// <summary>
  65. /// Whether this job should show in the ID Card Console.
  66. /// If set to null, it will default to SetPreference's value.
  67. /// </summary>
  68. [DataField]
  69. public bool? OverrideConsoleVisibility { get; private set; } = null;
  70. [DataField("canBeAntag")]
  71. public bool CanBeAntag { get; private set; } = true;
  72. /// <summary>
  73. /// The "weight" or importance of this job. If this number is large, the job system will assign this job
  74. /// before assigning other jobs.
  75. /// </summary>
  76. [DataField("weight")]
  77. public int Weight { get; private set; }
  78. /// <summary>
  79. /// How to sort this job relative to other jobs in the UI.
  80. /// Jobs with a higher value with sort before jobs with a lower value.
  81. /// If not set, <see cref="Weight"/> is used as a fallback.
  82. /// </summary>
  83. [DataField]
  84. public int? DisplayWeight { get; private set; }
  85. public int RealDisplayWeight => DisplayWeight ?? Weight;
  86. /// <summary>
  87. /// A numerical score for how much easier this job is for antagonists.
  88. /// For traitors, reduces starting TC by this amount. Other gamemodes can use it for whatever they find fitting.
  89. /// </summary>
  90. [DataField("antagAdvantage")]
  91. public int AntagAdvantage = 0;
  92. [DataField]
  93. public ProtoId<StartingGearPrototype>? StartingGear { get; private set; }
  94. /// <summary>
  95. /// Use this to spawn in as a non-humanoid (borg, test subject, etc.)
  96. /// Starting gear will be ignored.
  97. /// If you want to just add special attributes to a humanoid, use AddComponentSpecial instead.
  98. /// </summary>
  99. [DataField("jobEntity", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
  100. public string? JobEntity = null;
  101. /// <summary>
  102. /// Entity to use as a preview in the lobby/character editor.
  103. /// Same restrictions as <see cref="JobEntity"/> apply.
  104. /// </summary>
  105. [DataField]
  106. public EntProtoId? JobPreviewEntity = null;
  107. [DataField]
  108. public ProtoId<JobIconPrototype> Icon { get; private set; } = "JobIconUnknown";
  109. [DataField("special", serverOnly: true)]
  110. public JobSpecial[] Special { get; private set; } = Array.Empty<JobSpecial>();
  111. [DataField("access")]
  112. public IReadOnlyCollection<ProtoId<AccessLevelPrototype>> Access { get; private set; } = Array.Empty<ProtoId<AccessLevelPrototype>>();
  113. [DataField("accessGroups")]
  114. public IReadOnlyCollection<ProtoId<AccessGroupPrototype>> AccessGroups { get; private set; } = Array.Empty<ProtoId<AccessGroupPrototype>>();
  115. [DataField("extendedAccess")]
  116. public IReadOnlyCollection<ProtoId<AccessLevelPrototype>> ExtendedAccess { get; private set; } = Array.Empty<ProtoId<AccessLevelPrototype>>();
  117. [DataField("extendedAccessGroups")]
  118. public IReadOnlyCollection<ProtoId<AccessGroupPrototype>> ExtendedAccessGroups { get; private set; } = Array.Empty<ProtoId<AccessGroupPrototype>>();
  119. [DataField]
  120. public bool Whitelisted;
  121. /// <summary>
  122. /// Optional list of guides associated with this role. If the guides are opened, the first entry in this list
  123. /// will be used to select the currently selected guidebook.
  124. /// </summary>
  125. [DataField]
  126. public List<ProtoId<GuideEntryPrototype>>? Guides;
  127. }
  128. /// <summary>
  129. /// Sorts <see cref="JobPrototype"/>s appropriately for display in the UI,
  130. /// respecting their <see cref="JobPrototype.Weight"/>.
  131. /// </summary>
  132. public sealed class JobUIComparer : IComparer<JobPrototype>
  133. {
  134. public static readonly JobUIComparer Instance = new();
  135. public int Compare(JobPrototype? x, JobPrototype? y)
  136. {
  137. if (ReferenceEquals(x, y))
  138. return 0;
  139. if (ReferenceEquals(null, y))
  140. return 1;
  141. if (ReferenceEquals(null, x))
  142. return -1;
  143. var cmp = -x.RealDisplayWeight.CompareTo(y.RealDisplayWeight);
  144. if (cmp != 0)
  145. return cmp;
  146. return string.Compare(x.ID, y.ID, StringComparison.Ordinal);
  147. }
  148. }
  149. }