diff --git a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs index e070a4e28da..5236a6eba0a 100644 --- a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs +++ b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs @@ -22,7 +22,7 @@ public sealed partial class JobRequirementsManager : ISharedPlaytimeManager [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IPrototypeManager _prototypes = default!; - private readonly Dictionary _roles = new(); + public readonly Dictionary PlayTimes = new(); private readonly List _roleBans = new(); private ISawmill _sawmill = default!; @@ -46,7 +46,7 @@ private void ClientOnRunLevelChanged(object? sender, RunLevelChangedEventArgs e) if (e.NewLevel == ClientRunLevel.Initialize) { // Reset on disconnect, just in case. - _roles.Clear(); + PlayTimes.Clear(); } } @@ -64,12 +64,12 @@ private void RxRoleBans(MsgRoleBans message) private void RxPlayTime(MsgPlayTime message) { - _roles.Clear(); + PlayTimes.Clear(); // NOTE: do not assign _roles = message.Trackers due to implicit data sharing in integration tests. foreach (var (tracker, time) in message.Trackers) { - _roles[tracker] = time; + PlayTimes[tracker] = time; } /*var sawmill = Logger.GetSawmill("play_time"); @@ -107,7 +107,7 @@ public bool CheckRoleTime(HashSet? requirements, [NotNullWhen(fa var reasons = new List(); foreach (var requirement in requirements) { - if (JobRequirements.TryRequirementMet(requirement, _roles, out var jobReason, _entManager, _prototypes, _whitelisted, localePrefix)) + if (JobRequirements.TryRequirementMet(requirement, PlayTimes, out var jobReason, _entManager, _prototypes, _whitelisted, localePrefix)) continue; reasons.Add(jobReason.ToMarkup()); @@ -119,25 +119,30 @@ public bool CheckRoleTime(HashSet? requirements, [NotNullWhen(fa public TimeSpan FetchOverallPlaytime() { - return _roles.TryGetValue("Overall", out var overallPlaytime) ? overallPlaytime : TimeSpan.Zero; + return PlayTimes.TryGetValue("Overall", out var overallPlaytime) ? overallPlaytime : TimeSpan.Zero; } - public IEnumerable> FetchPlaytimeByRoles() + public Dictionary FetchPlaytimeByRoles() { var jobsToMap = _prototypes.EnumeratePrototypes(); + var ret = new Dictionary(); foreach (var job in jobsToMap) - { - if (_roles.TryGetValue(job.PlayTimeTracker, out var locJobName)) - { - yield return new KeyValuePair(job.Name, locJobName); - } - } + if (PlayTimes.TryGetValue(job.PlayTimeTracker, out var locJobName)) + ret.Add(job.Name, locJobName); + + return ret; } - public IReadOnlyDictionary GetPlayTimes(ICommonSession session) + public Dictionary GetPlayTimes() { - return session != _playerManager.LocalSession ? new Dictionary() : _roles; + var dict = new Dictionary(); + + dict.Add(PlayTimeTrackingShared.TrackerOverall, FetchOverallPlaytime()); + foreach (var role in FetchPlaytimeByRoles()) + dict.Add(role.Key, role.Value); + + return dict; } } diff --git a/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingManager.cs b/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingManager.cs index e4688566c96..02d57803154 100644 --- a/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingManager.cs +++ b/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingManager.cs @@ -209,7 +209,7 @@ private static void FlushSingleTracker(PlayTimeData data, TimeSpan time) } } - public IReadOnlyDictionary GetPlayTimes(ICommonSession session) + public Dictionary GetPlayTimes(ICommonSession session) { return GetTrackerTimes(session); } diff --git a/Content.Shared/Customization/Systems/CharacterRequirements.cs b/Content.Shared/Customization/Systems/CharacterRequirements.cs index b7200c60e85..134dca8e487 100644 --- a/Content.Shared/Customization/Systems/CharacterRequirements.cs +++ b/Content.Shared/Customization/Systems/CharacterRequirements.cs @@ -310,7 +310,7 @@ public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCha reason = Inverted ? null : FormattedMessage.FromMarkup(Loc.GetString("character-timer-department-too-high", - ("time", playtime.Minutes - Max.Minutes), + ("time", playtime.TotalMinutes - Max.TotalMinutes), ("department", Loc.GetString($"department-{department.ID}")), ("departmentColor", department.Color))); return false; @@ -322,7 +322,7 @@ public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCha reason = Inverted ? null : FormattedMessage.FromMarkup(Loc.GetString("character-timer-department-insufficient", - ("time", Min.Minutes - playtime.Minutes), + ("time", Min.TotalMinutes - playtime.TotalMinutes), ("department", Loc.GetString($"department-{department.ID}")), ("departmentColor", department.Color))); return false; @@ -367,7 +367,7 @@ public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCha reason = Inverted ? null : FormattedMessage.FromMarkup(Loc.GetString("character-timer-overall-too-high", - ("time", overallTime.Minutes - Max.Minutes))); + ("time", overallTime.TotalMinutes - Max.TotalMinutes))); return false; } @@ -377,7 +377,7 @@ public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCha reason = Inverted ? null : FormattedMessage.FromMarkup(Loc.GetString("character-timer-overall-insufficient", - ("time", Min.Minutes - overallTime.Minutes))); + ("time", Min.TotalMinutes - overallTime.TotalMinutes))); return false; } @@ -424,6 +424,7 @@ public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCha // Get the JobPrototype of the Tracker var trackerJob = jobSystem.GetJobPrototype(Tracker); + var jobStr = prototypeManager.Index(trackerJob).LocalizedName; // Get the primary department of the Tracker if (!jobSystem.TryGetPrimaryDepartment(trackerJob, out var department) && @@ -444,8 +445,8 @@ public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCha reason = Inverted ? null : FormattedMessage.FromMarkup(Loc.GetString("character-timer-role-too-high", - ("time", time.Minutes - Max.Minutes), - ("job", trackerJob), + ("time", time.TotalMinutes - Max.TotalMinutes), + ("job", jobStr), ("departmentColor", department.Color))); return false; } @@ -456,8 +457,8 @@ public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCha reason = Inverted ? null : FormattedMessage.FromMarkup(Loc.GetString("character-timer-role-insufficient", - ("time", Min.Minutes - time.Minutes), - ("job", trackerJob), + ("time", Min.TotalMinutes - time.TotalMinutes), + ("job", jobStr), ("departmentColor", department.Color))); return false; } diff --git a/Content.Shared/Players/PlayTimeTracking/ISharedPlaytimeManager.cs b/Content.Shared/Players/PlayTimeTracking/ISharedPlaytimeManager.cs index ac074fe7cbd..03fd040d0ca 100644 --- a/Content.Shared/Players/PlayTimeTracking/ISharedPlaytimeManager.cs +++ b/Content.Shared/Players/PlayTimeTracking/ISharedPlaytimeManager.cs @@ -1,11 +1,3 @@ -using Robust.Shared.Player; - namespace Content.Shared.Players.PlayTimeTracking; -public interface ISharedPlaytimeManager -{ - /// - /// Gets the playtimes for the session or an empty dictionary if none found. - /// - IReadOnlyDictionary GetPlayTimes(ICommonSession session); -} +public interface ISharedPlaytimeManager;