From 72b0fd25b56850670f33dd351a5a2a647a530d48 Mon Sep 17 00:00:00 2001 From: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> Date: Tue, 23 Jul 2024 07:18:46 -0700 Subject: [PATCH] Fix Loadout and Trait Job Playtime Requirements (#584) # Changelog :cl: - fix: Job playtime requirements for loadouts and traits show correctly --- .../JobRequirementsManager.cs | 21 ++++++++++++------- .../UI/HumanoidProfileEditor.xaml.cs | 12 +++++++---- .../PlayTimeTrackingManager.cs | 2 +- .../Systems/CharacterRequirements.cs | 17 ++++++++------- .../ISharedPlaytimeManager.cs | 10 +-------- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs index e070a4e28da..df73f5ff3f4 100644 --- a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs +++ b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs @@ -122,22 +122,27 @@ public TimeSpan FetchOverallPlaytime() return _roles.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); - } - } + 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.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs index 7ced95cacbf..771d928ebf9 100644 --- a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs @@ -5,6 +5,7 @@ using Content.Client.Lobby; using Content.Client.Message; using Content.Client.Players.PlayTimeTracking; +using Content.Client.Roles; using Content.Client.UserInterface.Systems.Guidebook; using Content.Shared.CCVar; using Content.Shared.Clothing.Loadouts.Prototypes; @@ -16,9 +17,11 @@ using Content.Shared.Humanoid.Prototypes; using Content.Shared.Preferences; using Content.Shared.Roles; +using Content.Shared.Roles.Jobs; using Content.Shared.Traits; using Robust.Client.AutoGenerated; using Robust.Client.Graphics; +using Robust.Client.Player; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; @@ -26,6 +29,7 @@ using Robust.Shared.Configuration; using Robust.Shared.Enums; using Robust.Shared.Physics; +using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Utility; using Direction = Robust.Shared.Maths.Direction; @@ -1412,7 +1416,7 @@ private void UpdateTraits(bool showUnusable) trait.Requirements, highJob?.Proto ?? new JobPrototype(), Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(), - new Dictionary(), //TODO Make this use real playtimes + _requirements.GetPlayTimes(), _entityManager, _prototypeManager, _configurationManager, @@ -1427,7 +1431,7 @@ out _ trait.Requirements, highJob?.Proto ?? new JobPrototype(), Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(), - new Dictionary(), + _requirements.GetPlayTimes(), _entityManager, _prototypeManager, _configurationManager, @@ -1671,7 +1675,7 @@ private void UpdateLoadouts(bool showUnusable) loadout.Requirements, highJob?.Proto ?? new JobPrototype(), Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(), - new Dictionary(), //TODO Make this use real playtimes + _requirements.GetPlayTimes(), _entityManager, _prototypeManager, _configurationManager, @@ -1686,7 +1690,7 @@ out _ loadout.Requirements, highJob?.Proto ?? new JobPrototype(), Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(), - new Dictionary(), + _requirements.GetPlayTimes(), _entityManager, _prototypeManager, _configurationManager, 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;