Skip to content

Commit

Permalink
[Fix] Fixed Loadouts Spawning in Backpacks when Spawning via Cryopods (
Browse files Browse the repository at this point in the history
  • Loading branch information
Remuchi authored Jan 2, 2025
1 parent 6744d6f commit d494c97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
15 changes: 2 additions & 13 deletions Content.Shared/Clothing/Loadouts/Systems/SharedLoadoutSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -48,7 +42,6 @@ private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent a
_station.EquipStartingGear(uid, proto);
}


public (List<EntityUid>, List<(EntityUid, LoadoutPreference, int)>) ApplyCharacterLoadout(
EntityUid uid,
ProtoId<JobPrototype> job,
Expand Down Expand Up @@ -91,14 +84,12 @@ private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent a
if (!_prototype.TryIndex<LoadoutPrototype>(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),
Expand All @@ -113,7 +104,7 @@ private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent a

// Equip it
if (EntityManager.TryGetComponent<ClothingComponent>(item, out var clothingComp)
&& _characterRequirements.CanEntityWearItem(uid, item)
&& _characterRequirements.CanEntityWearItem(uid, item, true)
&& _inventory.TryGetSlots(uid, out var slotDefinitions))
{
var deleted = false;
Expand Down Expand Up @@ -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);
Expand All @@ -164,7 +154,6 @@ private void OnMapInit(EntityUid uid, LoadoutComponent component, MapInitEvent a
}
}


[Serializable, NetSerializable, ImplicitDataDefinitionForInheritors]
public abstract partial class Loadout
{
Expand Down Expand Up @@ -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) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public string GetRequirementsMarkup(List<string> 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.
/// </summary>
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));
}
}
8 changes: 4 additions & 4 deletions Content.Shared/Inventory/InventorySystem.Equip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d494c97

Please sign in to comment.