Simple quick equip (#275)

* Quick equip

* Minor improvements.
This commit is contained in:
Víctor Aguilera Puerto
2019-07-19 16:31:56 +02:00
committed by Pieter-Jan Briers
parent b34a68a519
commit 5f276cd39d
2 changed files with 37 additions and 2 deletions

View File

@@ -1,14 +1,16 @@
using Content.Shared.GameObjects; using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Items; using Content.Shared.GameObjects.Components.Items;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.Utility;
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
namespace Content.Server.GameObjects namespace Content.Server.GameObjects
{ {
public class ClothingComponent : ItemComponent public class ClothingComponent : ItemComponent, IUse
{ {
public override string Name => "Clothing"; public override string Name => "Clothing";
public override uint? NetID => ContentNetIDs.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 public SlotFlags SlotFlags = SlotFlags.PREVENTEQUIP; //Different from None, NONE allows equips if no slot flags are required
private bool _quickEquipEnabled = true;
private int _heatResistance; private int _heatResistance;
public int HeatResistance => _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); serializer.DataFieldCached(ref _heatResistance, "HeatResistance", 323);
} }
@@ -53,5 +58,34 @@ namespace Content.Server.GameObjects
{ {
return new ClothingComponentState(ClothingEquippedPrefix, EquippedPrefix); 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;
}
} }
} }

View File

@@ -12,6 +12,7 @@
state: backpack state: backpack
- type: Clothing - type: Clothing
Size: 9999 Size: 9999
QuickEquip: false
Slots: Slots:
- back - back
sprite: Clothing/backpack.rsi sprite: Clothing/backpack.rsi