From bffc8768c1a8d8a5d8d1e8076bf6efdf81f6d664 Mon Sep 17 00:00:00 2001 From: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com> Date: Thu, 25 Jul 2024 05:08:05 +0300 Subject: [PATCH] Prevent Instant Unequip of Clothing (#594) # Description Prevents players from picking up their own equipped clothing (via the "put in hand" verb or otherwise) and thus bypassing the unequip delay completely. Does so by cancelling the GettingPickedUpAttemptEvent on equipped clothing. This does not prevent unequipping the clothing normally, i.e. by interacting with it in the inventory, or stripping clothing from others. # Changelog No cl no fun - most people don't even know this was an option. --- .../Clothing/EntitySystems/ClothingSystem.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Content.Shared/Clothing/EntitySystems/ClothingSystem.cs b/Content.Shared/Clothing/EntitySystems/ClothingSystem.cs index add47be5411..087e2ecedab 100644 --- a/Content.Shared/Clothing/EntitySystems/ClothingSystem.cs +++ b/Content.Shared/Clothing/EntitySystems/ClothingSystem.cs @@ -9,6 +9,7 @@ using Content.Shared.Tag; using Robust.Shared.GameStates; using System.Linq; +using Robust.Shared.Containers; namespace Content.Shared.Clothing.EntitySystems; @@ -19,6 +20,7 @@ public abstract class ClothingSystem : EntitySystem [Dependency] private readonly TagSystem _tagSystem = default!; [Dependency] private readonly InventorySystem _invSystem = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; + [Dependency] private readonly SharedContainerSystem _containerSys = default!; [ValidatePrototypeId] private const string HairTag = "HidesHair"; @@ -36,6 +38,7 @@ public override void Initialize() SubscribeLocalEvent(OnGotEquipped); SubscribeLocalEvent(OnGotUnequipped); SubscribeLocalEvent(OnMaskToggled); + SubscribeLocalEvent(OnPickedUp); SubscribeLocalEvent(OnEquipDoAfter); SubscribeLocalEvent(OnUnequipDoAfter); @@ -165,6 +168,18 @@ private void OnMaskToggled(Entity ent, ref ItemMaskToggledEve ToggleVisualLayer(args.Wearer, HumanoidVisualLayers.Snout, NoseTag); } + private void OnPickedUp(Entity ent, ref GettingPickedUpAttemptEvent args) + { + // If this clothing is equipped by the performer of this action, and the clothing has an unequip delay, stop the attempt + if (ent.Comp.UnequipDelay <= TimeSpan.Zero + || !_invSystem.TryGetContainingSlot(ent.Owner, out var slot) + || !_containerSys.TryGetContainingContainer(ent, out var container) + || container.Owner != args.User) + return; + + args.Cancel(); + } + private void OnEquipDoAfter(Entity ent, ref ClothingEquipDoAfterEvent args) { if (args.Handled || args.Cancelled || args.Target is not { } target)