Oops, All Captains! (#14943)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.GameTicking.Rules;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.GameTicking;
|
||||
@@ -25,6 +26,7 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
[Dependency] private readonly GameTicker _gameTicker = default!;
|
||||
[Dependency] private readonly StationSystem _stationSystem = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly AllCaptainsRuleSystem _allCaptainsRule = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
@@ -33,6 +35,8 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
SubscribeLocalEvent<StationJobsComponent, StationRenamedEvent>(OnStationRenamed);
|
||||
SubscribeLocalEvent<StationJobsComponent, ComponentShutdown>(OnStationDeletion);
|
||||
SubscribeLocalEvent<PlayerJoinedLobbyEvent>(OnPlayerJoinedLobby);
|
||||
SubscribeLocalEvent<GameRuleStartedEvent>(OnGameRuleStarted);
|
||||
SubscribeLocalEvent<GameRuleEndedEvent>(OnGameRuleEnded);
|
||||
_configurationManager.OnValueChanged(CCVars.GameDisallowLateJoins, _ => UpdateJobsAvailable(), true);
|
||||
}
|
||||
|
||||
@@ -136,6 +140,9 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
|
||||
var jobList = stationJobs.JobList;
|
||||
|
||||
if (_allCaptainsRule != null && _allCaptainsRule.RuleStarted)
|
||||
jobList = _allCaptainsRule.GetJobs(station).JobList;
|
||||
|
||||
// This should:
|
||||
// - Return true when zero slots are added/removed.
|
||||
// - Return true when you add.
|
||||
@@ -214,6 +221,11 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
|
||||
var jobList = stationJobs.JobList;
|
||||
|
||||
// If all captains mode, override job list with the allcaptains job list -- prevents modifying the "real" job list
|
||||
// in case mode changes later.
|
||||
if (_allCaptainsRule != null && _allCaptainsRule.RuleStarted)
|
||||
jobList = _allCaptainsRule.GetJobs(station).JobList;
|
||||
|
||||
switch (jobList.ContainsKey(jobPrototypeId))
|
||||
{
|
||||
case false:
|
||||
@@ -313,7 +325,11 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
if (!Resolve(station, ref stationJobs))
|
||||
throw new ArgumentException("Tried to use a non-station entity as a station!", nameof(station));
|
||||
|
||||
if (stationJobs.JobList.TryGetValue(jobPrototypeId, out var job))
|
||||
var jobList = stationJobs.JobList;
|
||||
if (_allCaptainsRule != null && _allCaptainsRule.RuleStarted)
|
||||
jobList = _allCaptainsRule.GetJobs(station).JobList;
|
||||
|
||||
if (jobList.TryGetValue(jobPrototypeId, out var job))
|
||||
{
|
||||
slots = job;
|
||||
return true;
|
||||
@@ -337,6 +353,9 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
if (!Resolve(station, ref stationJobs))
|
||||
throw new ArgumentException("Tried to use a non-station entity as a station!", nameof(station));
|
||||
|
||||
if (_allCaptainsRule != null && _allCaptainsRule.RuleStarted)
|
||||
return _allCaptainsRule.GetJobs(station).JobList.Where(x => x.Value != 0).Select(x => x.Key).ToHashSet();
|
||||
|
||||
return stationJobs.JobList.Where(x => x.Value != 0).Select(x => x.Key).ToHashSet();
|
||||
}
|
||||
|
||||
@@ -352,6 +371,9 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
if (!Resolve(station, ref stationJobs))
|
||||
throw new ArgumentException("Tried to use a non-station entity as a station!", nameof(station));
|
||||
|
||||
if (_allCaptainsRule != null && _allCaptainsRule.RuleStarted)
|
||||
return _allCaptainsRule.GetJobs(station).OverflowJobs.ToHashSet();
|
||||
|
||||
return stationJobs.OverflowJobs.ToHashSet();
|
||||
}
|
||||
|
||||
@@ -367,6 +389,9 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
if (!Resolve(station, ref stationJobs))
|
||||
throw new ArgumentException("Tried to use a non-station entity as a station!", nameof(station));
|
||||
|
||||
if (_allCaptainsRule != null && _allCaptainsRule.RuleStarted)
|
||||
return _allCaptainsRule.GetJobs(station).JobList;
|
||||
|
||||
return stationJobs.JobList;
|
||||
}
|
||||
|
||||
@@ -382,6 +407,9 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
if (!Resolve(station, ref stationJobs))
|
||||
throw new ArgumentException("Tried to use a non-station entity as a station!", nameof(station));
|
||||
|
||||
if (_allCaptainsRule != null && _allCaptainsRule.RuleStarted)
|
||||
return _allCaptainsRule.GetJobs(station).RoundStartJobList;
|
||||
|
||||
return stationJobs.RoundStartJobList;
|
||||
}
|
||||
|
||||
@@ -467,6 +495,8 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
foreach (var station in _stationSystem.Stations)
|
||||
{
|
||||
var list = Comp<StationJobsComponent>(station).JobList.ToDictionary(x => x.Key, x => x.Value);
|
||||
if (_allCaptainsRule != null && _allCaptainsRule.RuleStarted)
|
||||
list = _allCaptainsRule.GetJobs(station).JobList.ToDictionary(x => x.Key, x => x.Value);
|
||||
jobs.Add(station, list);
|
||||
stationNames.Add(station, Name(station));
|
||||
}
|
||||
@@ -491,5 +521,17 @@ public sealed partial class StationJobsSystem : EntitySystem
|
||||
UpdateJobsAvailable();
|
||||
}
|
||||
|
||||
private void OnGameRuleStarted(GameRuleStartedEvent msg)
|
||||
{
|
||||
if (msg.Rule.ID == "AllCaptains")
|
||||
UpdateJobsAvailable();
|
||||
}
|
||||
|
||||
private void OnGameRuleEnded(GameRuleEndedEvent msg)
|
||||
{
|
||||
if (msg.Rule.ID == "AllCaptains")
|
||||
UpdateJobsAvailable();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user