UseDelay + ItemCooldown merge (#22502)
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Interaction.Events;
|
||||
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;
|
||||
@@ -13,6 +17,8 @@ public abstract class ClothingSystem : EntitySystem
|
||||
[Dependency] private readonly SharedItemSystem _itemSys = default!;
|
||||
[Dependency] private readonly SharedHumanoidAppearanceSystem _humanoidSystem = default!;
|
||||
[Dependency] private readonly TagSystem _tagSystem = default!;
|
||||
[Dependency] private readonly InventorySystem _invSystem = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
|
||||
[ValidatePrototypeId<TagPrototype>]
|
||||
private const string HairTag = "HidesHair";
|
||||
@@ -21,12 +27,60 @@ public abstract class ClothingSystem : EntitySystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ClothingComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<ClothingComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<ClothingComponent, ComponentHandleState>(OnHandleState);
|
||||
SubscribeLocalEvent<ClothingComponent, GotEquippedEvent>(OnGotEquipped);
|
||||
SubscribeLocalEvent<ClothingComponent, GotUnequippedEvent>(OnGotUnequipped);
|
||||
SubscribeLocalEvent<ClothingComponent, ItemMaskToggledEvent>(OnMaskToggled);
|
||||
}
|
||||
private void OnUseInHand(Entity<ClothingComponent> ent, ref UseInHandEvent args)
|
||||
{
|
||||
if (args.Handled || !ent.Comp.QuickEquip)
|
||||
return;
|
||||
|
||||
var user = args.User;
|
||||
if (!TryComp(user, out InventoryComponent? inv) ||
|
||||
!TryComp(user, out HandsComponent? hands))
|
||||
return;
|
||||
|
||||
QuickEquip(ent, (user, inv, hands));
|
||||
args.Handled = true;
|
||||
args.ApplyDelay = false;
|
||||
}
|
||||
|
||||
private void QuickEquip(
|
||||
Entity<ClothingComponent> toEquipEnt,
|
||||
Entity<InventoryComponent, HandsComponent> userEnt)
|
||||
{
|
||||
foreach (var slotDef in userEnt.Comp1.Slots)
|
||||
{
|
||||
if (!_invSystem.CanEquip(userEnt, toEquipEnt, slotDef.Name, out _, slotDef, userEnt, toEquipEnt))
|
||||
continue;
|
||||
|
||||
if (_invSystem.TryGetSlotEntity(userEnt, slotDef.Name, out var slotEntity, userEnt))
|
||||
{
|
||||
// Item in slot has to be quick equipable as well
|
||||
if (TryComp(slotEntity, out ClothingComponent? item) && !item.QuickEquip)
|
||||
continue;
|
||||
|
||||
if (!_invSystem.TryUnequip(userEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt))
|
||||
continue;
|
||||
|
||||
if (!_invSystem.TryEquip(userEnt, toEquipEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt))
|
||||
continue;
|
||||
|
||||
_handsSystem.PickupOrDrop(userEnt, slotEntity.Value, handsComp: userEnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_invSystem.TryEquip(userEnt, toEquipEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt))
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnGotEquipped(EntityUid uid, ClothingComponent component, GotEquippedEvent args)
|
||||
{
|
||||
@@ -71,7 +125,7 @@ public abstract class ClothingSystem : EntitySystem
|
||||
|
||||
clothing.EquippedPrefix = prefix;
|
||||
_itemSys.VisualsChanged(uid);
|
||||
Dirty(clothing);
|
||||
Dirty(uid, clothing);
|
||||
}
|
||||
|
||||
public void SetSlots(EntityUid uid, SlotFlags slots, ClothingComponent? clothing = null)
|
||||
@@ -80,7 +134,7 @@ public abstract class ClothingSystem : EntitySystem
|
||||
return;
|
||||
|
||||
clothing.Slots = slots;
|
||||
Dirty(clothing);
|
||||
Dirty(uid, clothing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -97,7 +151,7 @@ public abstract class ClothingSystem : EntitySystem
|
||||
clothing.FemaleMask = otherClothing.FemaleMask;
|
||||
|
||||
_itemSys.VisualsChanged(uid);
|
||||
Dirty(clothing);
|
||||
Dirty(uid, clothing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user