From d494c97b6c537972dfa2978a9883cf1d20c936d5 Mon Sep 17 00:00:00 2001 From: Remuchi <72476615+Remuchi@users.noreply.github.com> Date: Fri, 3 Jan 2025 04:11:12 +0700 Subject: [PATCH] [Fix] Fixed Loadouts Spawning in Backpacks when Spawning via Cryopods (#1406) --- .../Loadouts/Systems/SharedLoadoutSystem.cs | 15 ++------------- .../Systems/CharacterRequirementsSystem.cs | 4 ++-- Content.Shared/Inventory/InventorySystem.Equip.cs | 8 ++++---- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Content.Shared/Clothing/Loadouts/Systems/SharedLoadoutSystem.cs b/Content.Shared/Clothing/Loadouts/Systems/SharedLoadoutSystem.cs index 97e92d9228a..e759c904af2 100644 --- a/Content.Shared/Clothing/Loadouts/Systems/SharedLoadoutSystem.cs +++ b/Content.Shared/Clothing/Loadouts/Systems/SharedLoadoutSystem.cs @@ -2,20 +2,16 @@ using Content.Shared.Clothing.Components; using Content.Shared.Clothing.Loadouts.Prototypes; using Content.Shared.Customization.Systems; -using Content.Shared.GameTicking; using Content.Shared.Inventory; using Content.Shared.Paint; using Content.Shared.Preferences; using Content.Shared.Roles; using Content.Shared.Station; -using Content.Shared.Traits.Assorted.Components; using Robust.Shared.Configuration; -using Robust.Shared.Network; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; - namespace Content.Shared.Clothing.Loadouts.Systems; public sealed class SharedLoadoutSystem : EntitySystem @@ -27,8 +23,6 @@ public sealed class SharedLoadoutSystem : EntitySystem [Dependency] private readonly IConfigurationManager _configuration = default!; [Dependency] private readonly CharacterRequirementsSystem _characterRequirements = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; - [Dependency] private readonly INetManager _net = default!; - [Dependency] private readonly SharedTransformSystem _sharedTransformSystem = default!; public override void Initialize() @@ -48,7 +42,6 @@ private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent a _station.EquipStartingGear(uid, proto); } - public (List, List<(EntityUid, LoadoutPreference, int)>) ApplyCharacterLoadout( EntityUid uid, ProtoId job, @@ -91,14 +84,12 @@ private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent a if (!_prototype.TryIndex(loadout.LoadoutName, out var loadoutProto)) continue; - if (!_characterRequirements.CheckRequirementsValid( loadoutProto.Requirements, job, profile, playTimes, whitelisted, loadoutProto, EntityManager, _prototype, _configuration, out _)) continue; - // Spawn the loadout items var spawned = EntityManager.SpawnEntities( _sharedTransformSystem.GetMapCoordinates(uid), @@ -113,7 +104,7 @@ private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent a // Equip it if (EntityManager.TryGetComponent(item, out var clothingComp) - && _characterRequirements.CanEntityWearItem(uid, item) + && _characterRequirements.CanEntityWearItem(uid, item, true) && _inventory.TryGetSlots(uid, out var slotDefinitions)) { var deleted = false; @@ -149,7 +140,6 @@ private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent a _appearance.SetData(item, PaintVisuals.Painted, !data); } - // Equip the loadout if (!_inventory.TryEquip(uid, item, slot, true, !string.IsNullOrEmpty(slot), true)) failedLoadouts.Add(item); @@ -164,7 +154,6 @@ private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent a } } - [Serializable, NetSerializable, ImplicitDataDefinitionForInheritors] public abstract partial class Loadout { @@ -201,5 +190,5 @@ public LoadoutPreference( string? customDescription = null, string? customColorTint = null, bool? customHeirloom = null - ) : base(loadoutName, customName, customDescription, customColorTint, customHeirloom) { } + ) : base(loadoutName, customName, customDescription, customColorTint, customHeirloom) { } } diff --git a/Content.Shared/Customization/Systems/CharacterRequirementsSystem.cs b/Content.Shared/Customization/Systems/CharacterRequirementsSystem.cs index 24e7b81e242..586fc139a02 100644 --- a/Content.Shared/Customization/Systems/CharacterRequirementsSystem.cs +++ b/Content.Shared/Customization/Systems/CharacterRequirementsSystem.cs @@ -88,10 +88,10 @@ public string GetRequirementsMarkup(List reasons) /// Returns true if the given dummy can equip the given item. /// Does not care if items are already in equippable slots, and ignores pockets. /// - public bool CanEntityWearItem(EntityUid dummy, EntityUid clothing) + public bool CanEntityWearItem(EntityUid dummy, EntityUid clothing, bool bypassAccessCheck = false) { return _inventory.TryGetSlots(dummy, out var slots) && slots.Where(slot => !slot.SlotFlags.HasFlag(SlotFlags.POCKET)) - .Any(slot => _inventory.CanEquip(dummy, clothing, slot.Name, out _)); + .Any(slot => _inventory.CanEquip(dummy, clothing, slot.Name, out _, bypassAccessCheck: bypassAccessCheck)); } } diff --git a/Content.Shared/Inventory/InventorySystem.Equip.cs b/Content.Shared/Inventory/InventorySystem.Equip.cs index f4567eeae18..9e45547beed 100644 --- a/Content.Shared/Inventory/InventorySystem.Equip.cs +++ b/Content.Shared/Inventory/InventorySystem.Equip.cs @@ -228,11 +228,11 @@ public bool CanAccess(EntityUid actor, EntityUid target, EntityUid itemUid) public bool CanEquip(EntityUid uid, EntityUid itemUid, string slot, [NotNullWhen(false)] out string? reason, SlotDefinition? slotDefinition = null, InventoryComponent? inventory = null, - ClothingComponent? clothing = null, ItemComponent? item = null) => - CanEquip(uid, uid, itemUid, slot, out reason, slotDefinition, inventory, clothing, item); + ClothingComponent? clothing = null, ItemComponent? item = null, bool bypassAccessCheck = false) => + CanEquip(uid, uid, itemUid, slot, out reason, slotDefinition, inventory, clothing, item, bypassAccessCheck); public bool CanEquip(EntityUid actor, EntityUid target, EntityUid itemUid, string slot, [NotNullWhen(false)] out string? reason, SlotDefinition? slotDefinition = null, - InventoryComponent? inventory = null, ClothingComponent? clothing = null, ItemComponent? item = null) + InventoryComponent? inventory = null, ClothingComponent? clothing = null, ItemComponent? item = null, bool bypassAccessCheck = false) { reason = "inventory-component-can-equip-cannot"; if (!Resolve(target, ref inventory, false)) @@ -265,7 +265,7 @@ public bool CanEquip(EntityUid actor, EntityUid target, EntityUid itemUid, strin return false; } - if (!CanAccess(actor, target, itemUid)) + if (!bypassAccessCheck && !CanAccess(actor, target, itemUid)) { reason = "interaction-system-user-interaction-cannot-reach"; return false;