Skip to content

Commit

Permalink
Prevent Instant Unequip of Clothing (#594)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
Mnemotechnician authored Jul 25, 2024
1 parent 78f0a79 commit bffc876
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Content.Shared/Clothing/EntitySystems/ClothingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Content.Shared.Tag;
using Robust.Shared.GameStates;
using System.Linq;
using Robust.Shared.Containers;

namespace Content.Shared.Clothing.EntitySystems;

Expand All @@ -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<TagPrototype>]
private const string HairTag = "HidesHair";
Expand All @@ -36,6 +38,7 @@ public override void Initialize()
SubscribeLocalEvent<ClothingComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<ClothingComponent, GotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<ClothingComponent, ItemMaskToggledEvent>(OnMaskToggled);
SubscribeLocalEvent<ClothingComponent, GettingPickedUpAttemptEvent>(OnPickedUp);

SubscribeLocalEvent<ClothingComponent, ClothingEquipDoAfterEvent>(OnEquipDoAfter);
SubscribeLocalEvent<ClothingComponent, ClothingUnequipDoAfterEvent>(OnUnequipDoAfter);
Expand Down Expand Up @@ -165,6 +168,18 @@ private void OnMaskToggled(Entity<ClothingComponent> ent, ref ItemMaskToggledEve
ToggleVisualLayer(args.Wearer, HumanoidVisualLayers.Snout, NoseTag);
}

private void OnPickedUp(Entity<ClothingComponent> 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<ClothingComponent> ent, ref ClothingEquipDoAfterEvent args)
{
if (args.Handled || args.Cancelled || args.Target is not { } target)
Expand Down

0 comments on commit bffc876

Please sign in to comment.