]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Don't use invalid defaults for loadouts (#28740)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sat, 15 Jun 2024 06:53:42 +0000 (16:53 +1000)
committerGitHub <noreply@github.com>
Sat, 15 Jun 2024 06:53:42 +0000 (16:53 +1000)
* Don't use invalid defaults for loadouts

At the time it made more sense but now with species specific stuff it's better to have nothing.

* Loadout SetDefault only applies valid loadouts

Content.Client/Lobby/LobbyUIController.cs
Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Content.Server/Station/Systems/StationSpawningSystem.cs
Content.Shared/Clothing/LoadoutSystem.cs
Content.Shared/Preferences/HumanoidCharacterProfile.cs
Content.Shared/Preferences/Loadouts/Effects/GroupLoadoutEffect.cs
Content.Shared/Preferences/Loadouts/Effects/JobRequirementLoadoutEffect.cs
Content.Shared/Preferences/Loadouts/Effects/LoadoutEffect.cs
Content.Shared/Preferences/Loadouts/Effects/PointsCostLoadoutEffect.cs
Content.Shared/Preferences/Loadouts/Effects/SpeciesLoadoutEffect.cs
Content.Shared/Preferences/Loadouts/RoleLoadout.cs

index aa66b7731d1541f9a12b60204e77493e460efc10..e4a13ed8c6b7e85d3c85ff09cfa3f61a524bc8d2 100644 (file)
@@ -294,7 +294,7 @@ public sealed class LobbyUIController : UIController, IOnStateEntered<LobbyState
 
         if (_prototypeManager.HasIndex<RoleLoadoutPrototype>(LoadoutSystem.GetJobPrototype(job.ID)))
         {
-            var loadout = profile.GetLoadoutOrDefault(LoadoutSystem.GetJobPrototype(job.ID), profile.Species, EntityManager, _prototypeManager);
+            var loadout = profile.GetLoadoutOrDefault(LoadoutSystem.GetJobPrototype(job.ID), _playerManager.LocalSession, profile.Species, EntityManager, _prototypeManager);
             GiveDummyLoadout(dummy, loadout);
         }
     }
@@ -414,7 +414,7 @@ public sealed class LobbyUIController : UIController, IOnStateEntered<LobbyState
 
             if (_prototypeManager.HasIndex<RoleLoadoutPrototype>(LoadoutSystem.GetJobPrototype(job.ID)))
             {
-                var loadout = humanoid.GetLoadoutOrDefault(LoadoutSystem.GetJobPrototype(job.ID), humanoid.Species, EntityManager, _prototypeManager);
+                var loadout = humanoid.GetLoadoutOrDefault(LoadoutSystem.GetJobPrototype(job.ID), _playerManager.LocalSession, humanoid.Species, EntityManager, _prototypeManager);
                 GiveDummyLoadout(dummyEnt, loadout);
             }
         }
index 18f986fc7ddfcee61428de40c099c772a1ba9942..e8e619ae6dc6e6ac0ea086bf89791c9c596845a4 100644 (file)
@@ -946,7 +946,7 @@ namespace Content.Client.Lobby.UI
                             if (loadout == null)
                             {
                                 loadout = new RoleLoadout(roleLoadoutProto.ID);
-                                loadout.SetDefault(_prototypeManager);
+                                loadout.SetDefault(Profile, _playerManager.LocalSession, _prototypeManager);
                             }
 
                             OpenLoadout(job, loadout, roleLoadoutProto);
index d30c9fc111d4e8ce81716c442ebe22d78e962c4a..e960a2bbbe2c7a6c7d044fe6d3723c89f1d31a5c 100644 (file)
@@ -26,6 +26,7 @@ using Content.Shared.StatusIcon;
 using JetBrains.Annotations;
 using Robust.Shared.Configuration;
 using Robust.Shared.Map;
+using Robust.Shared.Player;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
 using Robust.Shared.Utility;
@@ -39,18 +40,18 @@ namespace Content.Server.Station.Systems;
 [PublicAPI]
 public sealed class StationSpawningSystem : SharedStationSpawningSystem
 {
+    [Dependency] private readonly IConfigurationManager _configurationManager = default!;
     [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
-    [Dependency] private readonly IConfigurationManager _configurationManager = default!;
+    [Dependency] private readonly ActorSystem _actors = default!;
+    [Dependency] private readonly ArrivalsSystem _arrivalsSystem = default!;
+    [Dependency] private readonly ContainerSpawnPointSystem _containerSpawnPointSystem = default!;
     [Dependency] private readonly HumanoidAppearanceSystem _humanoidSystem = default!;
     [Dependency] private readonly IdCardSystem _cardSystem = default!;
-    [Dependency] private readonly PdaSystem _pdaSystem = default!;
-    [Dependency] private readonly SharedAccessSystem _accessSystem = default!;
     [Dependency] private readonly IdentitySystem _identity = default!;
     [Dependency] private readonly MetaDataSystem _metaSystem = default!;
-
-    [Dependency] private readonly ArrivalsSystem _arrivalsSystem = default!;
-    [Dependency] private readonly ContainerSpawnPointSystem _containerSpawnPointSystem = default!;
+    [Dependency] private readonly PdaSystem _pdaSystem = default!;
+    [Dependency] private readonly SharedAccessSystem _accessSystem = default!;
 
     private bool _randomizeCharacters;
 
@@ -198,7 +199,7 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
             if (loadout == null)
             {
                 loadout = new RoleLoadout(jobLoadout);
-                loadout.SetDefault(_prototypeManager);
+                loadout.SetDefault(profile, _actors.GetSession(entity), _prototypeManager);
             }
 
             EquipRoleLoadout(entity.Value, loadout, roleProto);
index 3136b4b4b330e9d6f99918852a760e5269fe4d92..f1b1dc36d907200442ecd2abd97bda9bee140260 100644 (file)
@@ -1,8 +1,11 @@
 using System.Linq;
 using Content.Shared.Clothing.Components;
+using Content.Shared.Humanoid;
+using Content.Shared.Preferences;
 using Content.Shared.Preferences.Loadouts;
 using Content.Shared.Roles;
 using Content.Shared.Station;
+using Robust.Shared.Player;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
 
@@ -15,6 +18,7 @@ public sealed class LoadoutSystem : EntitySystem
 {
     // Shared so we can predict it for placement manager.
 
+    [Dependency] private readonly ActorSystem _actors = default!;
     [Dependency] private readonly SharedStationSpawningSystem _station = default!;
     [Dependency] private readonly IPrototypeManager _protoMan = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
@@ -125,7 +129,17 @@ public sealed class LoadoutSystem : EntitySystem
         var id = _random.Pick(component.RoleLoadout);
         var proto = _protoMan.Index(id);
         var loadout = new RoleLoadout(id);
-        loadout.SetDefault(_protoMan, true);
+        loadout.SetDefault(GetProfile(uid), _actors.GetSession(uid), _protoMan, true);
         _station.EquipRoleLoadout(uid, loadout, proto);
     }
+
+    public HumanoidCharacterProfile GetProfile(EntityUid? uid)
+    {
+        if (TryComp(uid, out HumanoidAppearanceComponent? appearance))
+        {
+            return HumanoidCharacterProfile.DefaultWithSpecies(appearance.Species);
+        }
+
+        return HumanoidCharacterProfile.Random();
+    }
 }
index fd95848d2c6b76a194ef3d68c03e72988d42924e..22b4ed98150710b5fbd0842b7d80ff3760b463e1 100644 (file)
@@ -690,15 +690,15 @@ namespace Content.Shared.Preferences
             return profile;
         }
 
-        public RoleLoadout GetLoadoutOrDefault(string id, ProtoId<SpeciesPrototype>? species, IEntityManager entManager, IPrototypeManager protoManager)
+        public RoleLoadout GetLoadoutOrDefault(string id, ICommonSession? session, ProtoId<SpeciesPrototype>? species, IEntityManager entManager, IPrototypeManager protoManager)
         {
             if (!_loadouts.TryGetValue(id, out var loadout))
             {
                 loadout = new RoleLoadout(id);
-                loadout.SetDefault(protoManager, force: true);
+                loadout.SetDefault(this, session, protoManager, force: true);
             }
 
-            loadout.SetDefault(protoManager);
+            loadout.SetDefault(this, session, protoManager);
             return loadout;
         }
 
index 258d9a4dbb232f70645790c0932fbb3e93197569..47e3bea77197161429ee752baa8d93bb89ecff23 100644 (file)
@@ -13,7 +13,7 @@ public sealed partial class GroupLoadoutEffect : LoadoutEffect
     [DataField(required: true)]
     public ProtoId<LoadoutEffectGroupPrototype> Proto;
 
-    public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession session, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
+    public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession? session, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
     {
         var effectsProto = collection.Resolve<IPrototypeManager>().Index(Proto);
 
index 54576d3a53a96abf62c973c82afde02768574028..4a40e2c65e64aff4462a0eca147b98483e43408a 100644 (file)
@@ -15,8 +15,14 @@ public sealed partial class JobRequirementLoadoutEffect : LoadoutEffect
     [DataField(required: true)]
     public JobRequirement Requirement = default!;
 
-    public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession session, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
+    public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession? session, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
     {
+        if (session == null)
+        {
+            reason = FormattedMessage.Empty;
+            return true;
+        }
+
         var manager = collection.Resolve<ISharedPlaytimeManager>();
         var playtimes = manager.GetPlayTimes(session);
         return JobRequirements.TryRequirementMet(Requirement, playtimes, out reason,
index f35b14e2e0da338e613914517b55d891382e99ba..a9cbfc5fd5ea1afbc5d1bceef30b38e8f9221852 100644 (file)
@@ -13,7 +13,7 @@ public abstract partial class LoadoutEffect
     public abstract bool Validate(
         HumanoidCharacterProfile profile,
         RoleLoadout loadout,
-        ICommonSession session,
+        ICommonSession? session,
         IDependencyCollection collection,
         [NotNullWhen(false)] out FormattedMessage? reason);
 
index 842b4cfc03614b6fc062c89cf4c16a882a184aa0..734dc25ba418d8d95e24b20e51f568618884e646 100644 (file)
@@ -13,7 +13,7 @@ public sealed partial class PointsCostLoadoutEffect : LoadoutEffect
     public override bool Validate(
         HumanoidCharacterProfile profile,
         RoleLoadout loadout,
-        ICommonSession session,
+        ICommonSession? session,
         IDependencyCollection collection,
         [NotNullWhen(false)] out FormattedMessage? reason)
     {
index 8f886dd2ab89c9e13361dc6613bb1f6238626eb0..4ec46a8348350441ef618fc62bb5d81200de37b3 100644 (file)
@@ -11,7 +11,7 @@ public sealed partial class SpeciesLoadoutEffect : LoadoutEffect
     [DataField(required: true)]
     public List<ProtoId<SpeciesPrototype>> Species = new();
 
-    public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession session, IDependencyCollection collection,
+    public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession? session, IDependencyCollection collection,
         [NotNullWhen(false)] out FormattedMessage? reason)
     {
         if (Species.Contains(profile.Species))
index d2fc8df5591060f0e3ac927309e55ef456c93264..d02929cd96571c27d3f792e915e3ba25d767cc28 100644 (file)
@@ -166,12 +166,15 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
     /// <summary>
     /// Resets the selected loadouts to default if no data is present.
     /// </summary>
-    /// <param name="force">Clear existing data first</param>
-    public void SetDefault(IPrototypeManager protoManager, bool force = false)
+    public void SetDefault(HumanoidCharacterProfile? profile, ICommonSession? session, IPrototypeManager protoManager, bool force = false)
     {
+        if (profile == null)
+            return;
+
         if (force)
             SelectedLoadouts.Clear();
 
+        var collection = IoCManager.Instance!;
         var roleProto = protoManager.Index(Role);
 
         for (var i = roleProto.Groups.Count - 1; i >= 0; i--)
@@ -184,14 +187,28 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
             if (SelectedLoadouts.ContainsKey(group))
                 continue;
 
-            SelectedLoadouts[group] = new List<Loadout>();
+            var loadouts = new List<Loadout>();
+            SelectedLoadouts[group] = loadouts;
 
             if (groupProto.MinLimit > 0)
             {
                 // Apply any loadouts we can.
                 for (var j = 0; j < Math.Min(groupProto.MinLimit, groupProto.Loadouts.Count); j++)
                 {
-                    AddLoadout(group, groupProto.Loadouts[j], protoManager);
+                    if (!protoManager.TryIndex(groupProto.Loadouts[j], out var loadoutProto))
+                        continue;
+
+                    var defaultLoadout = new Loadout()
+                    {
+                        Prototype = loadoutProto.ID,
+                    };
+
+                    // Not valid so don't default to it anyway.
+                    if (!IsValid(profile, session, defaultLoadout.Prototype, collection, out _))
+                        continue;
+
+                    loadouts.Add(defaultLoadout);
+                    Apply(loadoutProto);
                 }
             }
         }
@@ -200,7 +217,7 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
     /// <summary>
     /// Returns whether a loadout is valid or not.
     /// </summary>
-    public bool IsValid(HumanoidCharacterProfile profile, ICommonSession session, ProtoId<LoadoutPrototype> loadout, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
+    public bool IsValid(HumanoidCharacterProfile profile, ICommonSession? session, ProtoId<LoadoutPrototype> loadout, IDependencyCollection collection, [NotNullWhen(false)] out FormattedMessage? reason)
     {
         reason = null;