Add support clothing equip/unequip doafters (#24389)

* add clothing equip/unequip doafters

* boowomp
This commit is contained in:
Nemanja
2024-01-28 05:48:42 -05:00
committed by GitHub
parent 19a05e11d0
commit 804c76f8c9
4 changed files with 133 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.DoAfter;
using Content.Shared.Inventory;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
@@ -66,6 +67,12 @@ public sealed partial class ClothingComponent : Component
public ClothingMask UnisexMask = ClothingMask.UniformFull;
public string? InSlot;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public TimeSpan EquipDelay = TimeSpan.Zero;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public TimeSpan UnequipDelay = TimeSpan.Zero;
}
[Serializable, NetSerializable]
@@ -85,3 +92,30 @@ public enum ClothingMask : byte
UniformFull,
UniformTop
}
[Serializable, NetSerializable]
public sealed partial class ClothingEquipDoAfterEvent : DoAfterEvent
{
public string Slot;
public ClothingEquipDoAfterEvent(string slot)
{
Slot = slot;
}
public override DoAfterEvent Clone() => this;
}
[Serializable, NetSerializable]
public sealed partial class ClothingUnequipDoAfterEvent : DoAfterEvent
{
public string Slot;
public ClothingUnequipDoAfterEvent(string slot)
{
Slot = slot;
}
public override DoAfterEvent Clone() => this;
}

View File

@@ -7,7 +7,6 @@ using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.Tag;
using Content.Shared.Timing;
using Robust.Shared.GameStates;
namespace Content.Shared.Clothing.EntitySystems;
@@ -33,7 +32,11 @@ public abstract class ClothingSystem : EntitySystem
SubscribeLocalEvent<ClothingComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<ClothingComponent, GotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<ClothingComponent, ItemMaskToggledEvent>(OnMaskToggled);
SubscribeLocalEvent<ClothingComponent, ClothingEquipDoAfterEvent>(OnEquipDoAfter);
SubscribeLocalEvent<ClothingComponent, ClothingUnequipDoAfterEvent>(OnUnequipDoAfter);
}
private void OnUseInHand(Entity<ClothingComponent> ent, ref UseInHandEvent args)
{
if (args.Handled || !ent.Comp.QuickEquip)
@@ -64,17 +67,17 @@ public abstract class ClothingSystem : EntitySystem
if (TryComp(slotEntity, out ClothingComponent? item) && !item.QuickEquip)
continue;
if (!_invSystem.TryUnequip(userEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt))
if (!_invSystem.TryUnequip(userEnt, slotDef.Name, true, inventory: userEnt, checkDoafter: true))
continue;
if (!_invSystem.TryEquip(userEnt, toEquipEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt))
if (!_invSystem.TryEquip(userEnt, toEquipEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt, checkDoafter: true))
continue;
_handsSystem.PickupOrDrop(userEnt, slotEntity.Value, handsComp: userEnt);
}
else
{
if (!_invSystem.TryEquip(userEnt, toEquipEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt))
if (!_invSystem.TryEquip(userEnt, toEquipEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt, checkDoafter: true))
continue;
}
@@ -113,6 +116,22 @@ public abstract class ClothingSystem : EntitySystem
SetEquippedPrefix(ent, args.IsToggled ? "toggled" : null, ent);
}
private void OnEquipDoAfter(Entity<ClothingComponent> ent, ref ClothingEquipDoAfterEvent args)
{
if (args.Handled || args.Cancelled || args.Target is not { } target)
return;
args.Handled = _invSystem.TryEquip(args.User, target, ent, args.Slot, clothing: ent.Comp, predicted: true, checkDoafter: false);
}
private void OnUnequipDoAfter(Entity<ClothingComponent> ent, ref ClothingUnequipDoAfterEvent args)
{
if (args.Handled || args.Cancelled || args.Target is not { } target)
return;
args.Handled = _invSystem.TryUnequip(args.User, target, args.Slot, clothing: ent.Comp, predicted: true, checkDoafter: false);
if (args.Handled)
_handsSystem.TryPickup(args.User, ent);
}
#region Public API
public void SetEquippedPrefix(EntityUid uid, string? prefix, ClothingComponent? clothing = null)