From 9384b92a820b7bf3a2563ad218f7203b9e5228e6 Mon Sep 17 00:00:00 2001 From: DEATHB4DEFEAT Date: Sun, 24 Mar 2024 19:19:10 -0700 Subject: [PATCH] loadouts --- .../Lobby/UI/LobbyCharacterPreviewPanel.cs | 12 + .../JobRequirementsManager.cs | 16 +- .../Preferences/UI/CharacterSetupGui.xaml.cs | 3 +- .../Preferences/UI/HumanoidProfileEditor.xaml | 15 + .../UI/HumanoidProfileEditor.xaml.cs | 359 ++++++- .../Tests/Preferences/ServerDbSqliteTests.cs | 5 +- .../PostgresServerDbContextModelSnapshot.cs | 23 + .../SqliteServerDbContextModelSnapshot.cs | 22 + Content.Server.Database/Model.cs | 18 +- .../Clothing/Systems/LoadoutSystem.cs | 49 + Content.Server/Database/ServerDbBase.cs | 12 +- Content.Shared/CCVar/CCVars.cs | 12 + Content.Shared/Clothing/LoadoutSystem.cs | 35 - .../Prototypes/LoadoutCategoryPrototype.cs | 13 + .../Loadouts/Prototypes/LoadoutPrototype.cs | 44 + .../Loadouts/Systems/LoadoutRequirements.cs | 375 +++++++ .../Loadouts/Systems/LoadoutSystem.cs | 149 +++ .../Preferences/HumanoidCharacterProfile.cs | 960 ++++++++++-------- Content.Shared/Roles/JobRequirements.cs | 16 +- 19 files changed, 1629 insertions(+), 509 deletions(-) create mode 100644 Content.Server/Clothing/Systems/LoadoutSystem.cs delete mode 100644 Content.Shared/Clothing/LoadoutSystem.cs create mode 100644 Content.Shared/Clothing/Loadouts/Prototypes/LoadoutCategoryPrototype.cs create mode 100644 Content.Shared/Clothing/Loadouts/Prototypes/LoadoutPrototype.cs create mode 100644 Content.Shared/Clothing/Loadouts/Systems/LoadoutRequirements.cs create mode 100644 Content.Shared/Clothing/Loadouts/Systems/LoadoutSystem.cs diff --git a/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs b/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs index f9481caa3bb..1825c74a250 100644 --- a/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs +++ b/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs @@ -5,6 +5,9 @@ using Content.Client.Inventory; using Content.Client.Preferences; using Content.Client.UserInterface.Controls; +using Content.Shared.Clothing; +using Content.Shared.Clothing.Loadouts; +using Content.Shared.Clothing.Loadouts.Systems; using Content.Shared.GameTicking; using Content.Shared.Humanoid.Prototypes; using Content.Shared.Inventory; @@ -126,6 +129,7 @@ public void UpdateUI() _summaryLabel.Text = selectedCharacter.Summary; _entityManager.System().LoadProfile(_previewDummy.Value, selectedCharacter); GiveDummyJobClothes(_previewDummy.Value, selectedCharacter); + GiveDummyLoadoutItems(_previewDummy.Value, selectedCharacter); } } } @@ -162,5 +166,13 @@ public static void GiveDummyJobClothes(EntityUid dummy, HumanoidCharacterProfile } } } + + public static void GiveDummyLoadoutItems(EntityUid dummy, HumanoidCharacterProfile profile) + { + var highPriorityJobId = profile.JobPriorities.FirstOrDefault(j => j.Value == JobPriority.High).Key; + var highPriorityJob = IoCManager.Resolve().Index(highPriorityJobId ?? SharedGameTicker.FallbackOverflowJob); + + EntitySystem.Get().ApplyCharacterLoadout(dummy, highPriorityJob, profile); + } } } diff --git a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs index 3b1e65c34e1..e3d368a69b8 100644 --- a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs +++ b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs @@ -21,7 +21,7 @@ public sealed partial class JobRequirementsManager [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!; @@ -45,7 +45,7 @@ private void ClientOnRunLevelChanged(object? sender, RunLevelChangedEventArgs e) if (e.NewLevel == ClientRunLevel.Initialize) { // Reset on disconnect, just in case. - _roles.Clear(); + PlayTimes.Clear(); } } @@ -63,12 +63,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"); @@ -102,7 +102,7 @@ public bool IsAllowed(JobPrototype job, [NotNullWhen(false)] out FormattedMessag return CheckRoleTime(job.Requirements, out reason); } - public bool CheckRoleTime(HashSet? requirements, [NotNullWhen(false)] out FormattedMessage? reason) + public bool CheckRoleTime(HashSet? requirements, [NotNullWhen(false)] out FormattedMessage? reason, string? localePrefix = null) { reason = null; @@ -112,7 +112,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)) + if (JobRequirements.TryRequirementMet(requirement, PlayTimes, out var jobReason, _entManager, _prototypes, _whitelisted, localePrefix)) continue; reasons.Add(jobReason.ToMarkup()); @@ -124,7 +124,7 @@ 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() @@ -133,7 +133,7 @@ public IEnumerable> FetchPlaytimeByRoles() foreach (var job in jobsToMap) { - if (_roles.TryGetValue(job.PlayTimeTracker, out var locJobName)) + if (PlayTimes.TryGetValue(job.PlayTimeTracker, out var locJobName)) { yield return new KeyValuePair(job.Name, locJobName); } diff --git a/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs b/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs index f1052086de6..dba96d74b6c 100644 --- a/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs +++ b/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs @@ -181,6 +181,7 @@ public CharacterPickerButton( if (humanoid != null) { LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy, humanoid); + LobbyCharacterPreviewPanel.GiveDummyLoadoutItems(_previewDummy, humanoid); } var isSelectedCharacter = profile == preferencesManager.Preferences?.SelectedCharacter; @@ -229,10 +230,8 @@ public CharacterPickerButton( }; deleteButton.OnPressed += _ => { - deleteButton.Visible = false; confirmDeleteButton.Visible = true; - }; var internalHBox = new BoxContainer diff --git a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml index d0dd02a58ad..9a70d678310 100644 --- a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml +++ b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml @@ -85,6 +85,12 @@