From 34bfec199ae9ace75974bb3147a0cafc1e7fafed Mon Sep 17 00:00:00 2001 From: Morb0 <14136326+Morb0@users.noreply.github.com> Date: Wed, 15 May 2024 17:49:35 +0300 Subject: [PATCH] Add Secrets inventory loadout --- .../UI/LoadoutGroupContainer.xaml.cs | 11 +++++- .../Preferences/Loadouts/RoleLoadout.cs | 34 ++++++++++++++++- .../ISharedLoadoutsManager.cs | 11 ++++++ .../corvax/preferences/loadout-groups.ftl | 1 + .../Corvax/Loadouts/loadout_groups.yml | 7 ++++ .../Corvax/Loadouts/role_loadouts.yml | 1 + .../Prototypes/Loadouts/role_loadouts.yml | 38 +++++++++++++++++++ Secrets | 2 +- 8 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 Corvax/Content.Corvax.Interfaces.Shared/ISharedLoadoutsManager.cs diff --git a/Content.Client/Preferences/UI/LoadoutGroupContainer.xaml.cs b/Content.Client/Preferences/UI/LoadoutGroupContainer.xaml.cs index 8dc1c405394..a2c36dd8037 100644 --- a/Content.Client/Preferences/UI/LoadoutGroupContainer.xaml.cs +++ b/Content.Client/Preferences/UI/LoadoutGroupContainer.xaml.cs @@ -1,4 +1,5 @@ using System.Linq; +using Content.Corvax.Interfaces.Shared; using Content.Shared.Clothing; using Content.Shared.Preferences.Loadouts; using Robust.Client.AutoGenerated; @@ -66,7 +67,15 @@ public void RefreshLoadouts(RoleLoadout loadout, ICommonSession session, IDepend var selected = loadout.SelectedLoadouts[_groupProto.ID]; - foreach (var loadoutProto in _groupProto.Loadouts) + // Corvax-Loadouts-Start + var groupLoadouts = _groupProto.Loadouts; + if (collection.TryResolveType(out var loadoutsManager) && _groupProto.ID == "Inventory") + { + groupLoadouts = loadoutsManager.GetClientPrototypes().Select(id => (ProtoId)id).ToList(); + } + // Corvax-Loadouts-End + + foreach (var loadoutProto in groupLoadouts) // Corvax-Loadouts { if (!protoMan.TryIndex(loadoutProto, out var loadProto)) continue; diff --git a/Content.Shared/Preferences/Loadouts/RoleLoadout.cs b/Content.Shared/Preferences/Loadouts/RoleLoadout.cs index 3a4015985d0..ca5b69e0754 100644 --- a/Content.Shared/Preferences/Loadouts/RoleLoadout.cs +++ b/Content.Shared/Preferences/Loadouts/RoleLoadout.cs @@ -1,6 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using System.Linq; +using Content.Corvax.Interfaces.Shared; using Content.Shared.Random; using Robust.Shared.Collections; +using Robust.Shared.Network; using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; @@ -48,6 +51,7 @@ public void EnsureValid(ICommonSession session, IDependencyCollection collection { var groupRemove = new ValueList(); var protoManager = collection.Resolve(); + var netManager = collection.Resolve(); // Corvax-Loadouts if (!protoManager.TryIndex(Role, out var roleProto)) { @@ -67,6 +71,24 @@ public void EnsureValid(ICommonSession session, IDependencyCollection collection continue; } + // Corvax-Loadouts-Start + var groupProtoLoadouts = groupProto.Loadouts; + if (collection.TryResolveType(out var loadoutsManager) && group.Id == "Inventory") + { + var prototypes = new List(); + if (netManager.IsClient) + { + prototypes = loadoutsManager.GetClientPrototypes(); + } + else if (loadoutsManager.TryGetServerPrototypes(session.UserId, out var protos)) + { + prototypes = protos; + } + + groupProtoLoadouts = prototypes.Select(id => (ProtoId)id).ToList(); + } + // Corvax-Loadouts-End + var loadouts = groupLoadouts[..Math.Min(groupLoadouts.Count, groupProto.MaxLimit)]; // Validate first @@ -80,6 +102,14 @@ public void EnsureValid(ICommonSession session, IDependencyCollection collection continue; } + // Corvax-Loadouts-Start: Validate if loadout exist in group. It's can't be f real + if (!groupProtoLoadouts.Contains(loadout.Prototype)) + { + loadouts.RemoveAt(i); + continue; + } + // Corvax-Loadouts-End + // Validate the loadout can be applied (e.g. points). if (!IsValid(session, loadout.Prototype, collection, out _)) { @@ -95,9 +125,9 @@ public void EnsureValid(ICommonSession session, IDependencyCollection collection // If you put invalid ones first but that's your fault for not using sensible defaults if (loadouts.Count < groupProto.MinLimit) { - for (var i = 0; i < Math.Min(groupProto.MinLimit, groupProto.Loadouts.Count); i++) + for (var i = 0; i < Math.Min(groupProto.MinLimit, groupProtoLoadouts.Count); i++) // Corvax-Loadout: Use groupProtoLoadouts instead of groupProto.Loadouts { - if (!protoManager.TryIndex(groupProto.Loadouts[i], out var loadoutProto)) + if (!protoManager.TryIndex(groupProtoLoadouts[i], out var loadoutProto)) // Corvax-Loadout continue; var defaultLoadout = new Loadout() diff --git a/Corvax/Content.Corvax.Interfaces.Shared/ISharedLoadoutsManager.cs b/Corvax/Content.Corvax.Interfaces.Shared/ISharedLoadoutsManager.cs new file mode 100644 index 00000000000..9515c507d55 --- /dev/null +++ b/Corvax/Content.Corvax.Interfaces.Shared/ISharedLoadoutsManager.cs @@ -0,0 +1,11 @@ +using System.Diagnostics.CodeAnalysis; +using Robust.Shared.Network; + +namespace Content.Corvax.Interfaces.Shared; + +public interface ISharedLoadoutsManager +{ + public void Initialize(); + public bool TryGetServerPrototypes(NetUserId userId, [NotNullWhen(true)] out List? prototypes); + public List GetClientPrototypes(); +} diff --git a/Resources/Locale/ru-RU/corvax/preferences/loadout-groups.ftl b/Resources/Locale/ru-RU/corvax/preferences/loadout-groups.ftl index e275efb39fc..01314fe0cbc 100644 --- a/Resources/Locale/ru-RU/corvax/preferences/loadout-groups.ftl +++ b/Resources/Locale/ru-RU/corvax/preferences/loadout-groups.ftl @@ -1 +1,2 @@ +loadout-group-inventory = Мой инвентарь loadout-group-psychologist-backpack = Рюкзак психолога diff --git a/Resources/Prototypes/Corvax/Loadouts/loadout_groups.yml b/Resources/Prototypes/Corvax/Loadouts/loadout_groups.yml index fb05b44c362..95eab89bf34 100644 --- a/Resources/Prototypes/Corvax/Loadouts/loadout_groups.yml +++ b/Resources/Prototypes/Corvax/Loadouts/loadout_groups.yml @@ -1,3 +1,10 @@ +- type: loadoutGroup + id: Inventory + name: loadout-group-inventory + minLimit: 0 + maxLimit: 5 + loadouts: [] + - type: loadoutGroup id: PsychologistBackpack name: loadout-group-psychologist-backpack diff --git a/Resources/Prototypes/Corvax/Loadouts/role_loadouts.yml b/Resources/Prototypes/Corvax/Loadouts/role_loadouts.yml index 517d6bd437d..7b4befc286a 100644 --- a/Resources/Prototypes/Corvax/Loadouts/role_loadouts.yml +++ b/Resources/Prototypes/Corvax/Loadouts/role_loadouts.yml @@ -5,3 +5,4 @@ - LawyerJumpsuit - CommonBackpack - Trinkets + - Inventory # Corvax-Loadouts diff --git a/Resources/Prototypes/Loadouts/role_loadouts.yml b/Resources/Prototypes/Loadouts/role_loadouts.yml index 7fc338c3449..941b9e4d4b1 100644 --- a/Resources/Prototypes/Loadouts/role_loadouts.yml +++ b/Resources/Prototypes/Loadouts/role_loadouts.yml @@ -8,6 +8,7 @@ - CaptainBackpack - CaptainOuterClothing - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobHeadOfPersonnel @@ -19,6 +20,7 @@ - HoPOuterClothing - Glasses - Trinkets + - Inventory # Corvax-Loadouts # Civilian - type: roleLoadout @@ -32,6 +34,7 @@ - PassengerShoes - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobBartender @@ -42,6 +45,7 @@ - BartenderOuterClothing - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobServiceWorker @@ -50,6 +54,7 @@ - CommonBackpack - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobChef @@ -61,6 +66,7 @@ - ChefOuterClothing - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobLibrarian @@ -69,6 +75,7 @@ - CommonBackpack - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobLawyer @@ -78,6 +85,7 @@ - LawyerBackpack - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobChaplain @@ -90,6 +98,7 @@ - ChaplainOuterClothing - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobJanitor @@ -101,6 +110,7 @@ - JanitorOuterClothing - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobBotanist @@ -111,6 +121,7 @@ - BotanistOuterClothing - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobClown @@ -122,6 +133,7 @@ - ClownShoes - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobMime @@ -133,6 +145,7 @@ - MimeOuterClothing - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobMusician @@ -141,6 +154,7 @@ - MusicianOuterClothing - Glasses - Trinkets + - Inventory # Corvax-Loadouts # Cargo - type: roleLoadout @@ -154,6 +168,7 @@ - QuartermasterShoes - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobCargoTechnician @@ -165,6 +180,7 @@ - CargoTechnicianShoes - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobSalvageSpecialist @@ -174,6 +190,7 @@ - SalvageSpecialistShoes - Glasses - Trinkets + - Inventory # Corvax-Loadouts # Engineering - type: roleLoadout @@ -186,6 +203,7 @@ - ChiefEngineerOuterClothing - ChiefEngineerShoes - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobTechnicalAssistant @@ -193,6 +211,7 @@ - TechnicalAssistantJumpsuit - StationEngineerBackpack - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobStationEngineer @@ -204,6 +223,7 @@ - StationEngineerShoes - StationEngineerID - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobAtmosphericTechnician @@ -213,6 +233,7 @@ - AtmosphericTechnicianOuterClothing - AtmosphericTechnicianShoes - Trinkets + - Inventory # Corvax-Loadouts # Science - type: roleLoadout @@ -227,6 +248,7 @@ - ResearchDirectorShoes - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobScientist @@ -241,6 +263,7 @@ - ScientistPDA - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobResearchAssistant @@ -249,6 +272,7 @@ - ScientistBackpack - Glasses - Trinkets + - Inventory # Corvax-Loadouts # Security - type: roleLoadout @@ -262,6 +286,7 @@ - HeadofSecurityOuterClothing - SecurityShoes - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobWarden @@ -273,6 +298,7 @@ - WardenOuterClothing - SecurityShoes - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobSecurityOfficer @@ -285,6 +311,7 @@ - SecurityPDA - SecurityBelt - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobDetective @@ -296,6 +323,7 @@ - DetectiveOuterClothing - SecurityShoes - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobSecurityCadet @@ -303,6 +331,7 @@ - SecurityCadetJumpsuit - SecurityBackpack - Trinkets + - Inventory # Corvax-Loadouts # Medical - type: roleLoadout @@ -318,6 +347,7 @@ - ChiefMedicalOfficerShoes - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobMedicalDoctor @@ -332,6 +362,7 @@ - MedicalDoctorPDA - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobMedicalIntern @@ -340,6 +371,7 @@ - MedicalBackpack - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobChemist @@ -351,6 +383,7 @@ - ChemistOuterClothing - MedicalShoes - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobParamedic @@ -364,6 +397,7 @@ - ParamedicShoes - Glasses - Trinkets + - Inventory # Corvax-Loadouts # Wildcards - type: roleLoadout @@ -372,6 +406,7 @@ - CommonBackpack - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobReporter @@ -380,6 +415,7 @@ - CommonBackpack - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobPsychologist @@ -387,6 +423,7 @@ - PsychologistBackpack # Corvax-MRP - Glasses - Trinkets + - Inventory # Corvax-Loadouts - type: roleLoadout id: JobBoxer @@ -396,3 +433,4 @@ - CommonBackpack - Glasses - Trinkets + - Inventory # Corvax-Loadouts diff --git a/Secrets b/Secrets index eca67902c22..fe71e8bfe65 160000 --- a/Secrets +++ b/Secrets @@ -1 +1 @@ -Subproject commit eca67902c227da4163d619ffb1a382b8a1815d51 +Subproject commit fe71e8bfe65973a0361bda118477d471de85844f