From 5f276cd39d32e76232d81709de5cbe6043d923f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Aguilera=20Puerto?= <6766154+Zumorica@users.noreply.github.com> Date: Fri, 19 Jul 2019 16:31:56 +0200 Subject: [PATCH] Simple quick equip (#275) * Quick equip * Minor improvements. --- .../Items/Clothing/ClothingComponent.cs | 38 ++++++++++++++++++- .../Entities/Clothing/backpacks.yml | 1 + 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Content.Server/GameObjects/Components/Items/Clothing/ClothingComponent.cs b/Content.Server/GameObjects/Components/Items/Clothing/ClothingComponent.cs index 5b846a9e22..6235e24ee0 100644 --- a/Content.Server/GameObjects/Components/Items/Clothing/ClothingComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Clothing/ClothingComponent.cs @@ -1,14 +1,16 @@ -using Content.Shared.GameObjects; +using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Items; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; using System; using System.Collections.Generic; +using Content.Server.GameObjects.EntitySystems; +using Robust.Shared.Utility; using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; namespace Content.Server.GameObjects { - public class ClothingComponent : ItemComponent + public class ClothingComponent : ItemComponent, IUse { public override string Name => "Clothing"; public override uint? NetID => ContentNetIDs.CLOTHING; @@ -16,6 +18,7 @@ namespace Content.Server.GameObjects public SlotFlags SlotFlags = SlotFlags.PREVENTEQUIP; //Different from None, NONE allows equips if no slot flags are required + private bool _quickEquipEnabled = true; private int _heatResistance; public int HeatResistance => _heatResistance; @@ -46,6 +49,8 @@ namespace Content.Server.GameObjects } }); + serializer.DataField(ref _quickEquipEnabled, "QuickEquip", true); + serializer.DataFieldCached(ref _heatResistance, "HeatResistance", 323); } @@ -53,5 +58,34 @@ namespace Content.Server.GameObjects { return new ClothingComponentState(ClothingEquippedPrefix, EquippedPrefix); } + + public bool UseEntity(UseEntityEventArgs eventArgs) + { + if (!_quickEquipEnabled) return false; + if (!eventArgs.User.TryGetComponent(out InventoryComponent inv) + || !eventArgs.User.TryGetComponent(out HandsComponent hands)) return false; + + foreach (var (slot, flag) in SlotMasks) + { + // We check if the clothing can be equipped in this slot. + if ((SlotFlags & flag) == 0) continue; + + if (inv.TryGetSlotItem(slot, out ItemComponent item)) + { + if (!inv.CanUnequip(slot)) continue; + hands.Drop(Owner); + inv.Unequip(slot); + hands.PutInHand(item); + } + else + { + hands.Drop(Owner); + } + + return inv.Equip(slot, this); + } + + return false; + } } } diff --git a/Resources/Prototypes/Entities/Clothing/backpacks.yml b/Resources/Prototypes/Entities/Clothing/backpacks.yml index c2ca6f2991..7f4651e457 100644 --- a/Resources/Prototypes/Entities/Clothing/backpacks.yml +++ b/Resources/Prototypes/Entities/Clothing/backpacks.yml @@ -12,6 +12,7 @@ state: backpack - type: Clothing Size: 9999 + QuickEquip: false Slots: - back sprite: Clothing/backpack.rsi