Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Instant Unequip of Clothing #594

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading