1
0

StationJobsComponent.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System.Linq;
  2. using Content.Server.Station.Systems;
  3. using Content.Shared.Roles;
  4. using JetBrains.Annotations;
  5. using Robust.Shared.Network;
  6. using Robust.Shared.Prototypes;
  7. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
  8. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
  9. namespace Content.Server.Station.Components;
  10. /// <summary>
  11. /// Stores information about a station's job selection.
  12. /// </summary>
  13. [RegisterComponent, Access(typeof(StationJobsSystem)), PublicAPI]
  14. public sealed partial class StationJobsComponent : Component
  15. {
  16. /// <summary>
  17. /// Total *mid-round* jobs at station start.
  18. /// This is inferred automatically from <see cref="SetupAvailableJobs"/>.
  19. /// </summary>
  20. [ViewVariables] public int MidRoundTotalJobs;
  21. /// <summary>
  22. /// Current total jobs.
  23. /// </summary>
  24. [DataField] public int TotalJobs;
  25. /// <summary>
  26. /// Station is running on extended access.
  27. /// </summary>
  28. [DataField] public bool ExtendedAccess;
  29. /// <summary>
  30. /// If there are less than or equal this amount of players in the game at round start,
  31. /// people get extended access levels from job prototypes.
  32. /// </summary>
  33. /// <remarks>
  34. /// Set to -1 to disable extended access.
  35. /// </remarks>
  36. [DataField]
  37. public int ExtendedAccessThreshold { get; set; } = 15;
  38. /// <summary>
  39. /// The percentage of jobs remaining.
  40. /// </summary>
  41. /// <remarks>
  42. /// Null if MidRoundTotalJobs is zero. This is a NaN free API.
  43. /// </remarks>
  44. [ViewVariables]
  45. public float? PercentJobsRemaining => MidRoundTotalJobs > 0 ? TotalJobs / (float) MidRoundTotalJobs : null;
  46. /// <summary>
  47. /// The current list of jobs of available jobs. Null implies that is no limit.
  48. /// </summary>
  49. /// <remarks>
  50. /// This should not be mutated or used directly unless you really know what you're doing, go through StationJobsSystem.
  51. /// </remarks>
  52. [DataField]
  53. public Dictionary<ProtoId<JobPrototype>, int?> JobList = new();
  54. /// <summary>
  55. /// Overflow jobs that round-start can spawn infinitely many of.
  56. /// This is inferred automatically from <see cref="SetupAvailableJobs"/>.
  57. /// </summary>
  58. [ViewVariables]
  59. public IReadOnlySet<ProtoId<JobPrototype>> OverflowJobs = default!;
  60. /// <summary>
  61. /// A dictionary relating a NetUserId to the jobs they have on station.
  62. /// An OOC way to track where job slots have gone.
  63. /// </summary>
  64. [DataField]
  65. public Dictionary<NetUserId, List<ProtoId<JobPrototype>>> PlayerJobs = new();
  66. /// <summary>
  67. /// Mapping of jobs to an int[2] array that specifies jobs available at round start, and midround.
  68. /// Negative values implies that there is no limit.
  69. /// </summary>
  70. [DataField("availableJobs", required: true)]
  71. public Dictionary<ProtoId<JobPrototype>, int[]> SetupAvailableJobs = default!;
  72. }