Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Loadout and Trait Job Playtime Requirements #584

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,27 @@ public TimeSpan FetchOverallPlaytime()
return _roles.TryGetValue("Overall", out var overallPlaytime) ? overallPlaytime : TimeSpan.Zero;
}

public IEnumerable<KeyValuePair<string, TimeSpan>> FetchPlaytimeByRoles()
public Dictionary<string, TimeSpan> FetchPlaytimeByRoles()
{
var jobsToMap = _prototypes.EnumeratePrototypes<JobPrototype>();
var ret = new Dictionary<string, TimeSpan>();

foreach (var job in jobsToMap)
{
if (_roles.TryGetValue(job.PlayTimeTracker, out var locJobName))
{
yield return new KeyValuePair<string, TimeSpan>(job.Name, locJobName);
}
}
ret.Add(job.Name, locJobName);

return ret;
}


public IReadOnlyDictionary<string, TimeSpan> GetPlayTimes(ICommonSession session)
public Dictionary<string, TimeSpan> GetPlayTimes()
{
return session != _playerManager.LocalSession ? new Dictionary<string, TimeSpan>() : _roles;
var dict = new Dictionary<string, TimeSpan>();

dict.Add(PlayTimeTrackingShared.TrackerOverall, FetchOverallPlaytime());
foreach (var role in FetchPlaytimeByRoles())
dict.Add(role.Key, role.Value);

return dict;
}
}
12 changes: 8 additions & 4 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,16 +17,19 @@
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;
using Robust.Client.Utility;
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;
Expand Down Expand Up @@ -1412,7 +1416,7 @@ private void UpdateTraits(bool showUnusable)
trait.Requirements,
highJob?.Proto ?? new JobPrototype(),
Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(),
new Dictionary<string, TimeSpan>(), //TODO Make this use real playtimes
_requirements.GetPlayTimes(),
_entityManager,
_prototypeManager,
_configurationManager,
Expand All @@ -1427,7 +1431,7 @@ out _
trait.Requirements,
highJob?.Proto ?? new JobPrototype(),
Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(),
new Dictionary<string, TimeSpan>(),
_requirements.GetPlayTimes(),
_entityManager,
_prototypeManager,
_configurationManager,
Expand Down Expand Up @@ -1671,7 +1675,7 @@ private void UpdateLoadouts(bool showUnusable)
loadout.Requirements,
highJob?.Proto ?? new JobPrototype(),
Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(),
new Dictionary<string, TimeSpan>(), //TODO Make this use real playtimes
_requirements.GetPlayTimes(),
_entityManager,
_prototypeManager,
_configurationManager,
Expand All @@ -1686,7 +1690,7 @@ out _
loadout.Requirements,
highJob?.Proto ?? new JobPrototype(),
Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(),
new Dictionary<string, TimeSpan>(),
_requirements.GetPlayTimes(),
_entityManager,
_prototypeManager,
_configurationManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private static void FlushSingleTracker(PlayTimeData data, TimeSpan time)
}
}

public IReadOnlyDictionary<string, TimeSpan> GetPlayTimes(ICommonSession session)
public Dictionary<string, TimeSpan> GetPlayTimes(ICommonSession session)
{
return GetTrackerTimes(session);
}
Expand Down
17 changes: 9 additions & 8 deletions Content.Shared/Customization/Systems/CharacterRequirements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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<JobPrototype>(trackerJob).LocalizedName;

// Get the primary department of the Tracker
if (!jobSystem.TryGetPrimaryDepartment(trackerJob, out var department) &&
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
using Robust.Shared.Player;

namespace Content.Shared.Players.PlayTimeTracking;

public interface ISharedPlaytimeManager
{
/// <summary>
/// Gets the playtimes for the session or an empty dictionary if none found.
/// </summary>
IReadOnlyDictionary<string, TimeSpan> GetPlayTimes(ICommonSession session);
}
public interface ISharedPlaytimeManager;
Loading