2019-11-13 17:37:46 -05:00
|
|
|
// Only unused on .NET Core due to KeyValuePair.Deconstruct
|
|
|
|
|
// ReSharper disable once RedundantUsingDirective
|
|
|
|
|
using Robust.Shared.Utility;
|
2019-07-31 15:02:36 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Content.Server.GameObjects.EntitySystems;
|
2019-07-19 16:31:56 +02:00
|
|
|
using Content.Shared.GameObjects;
|
2019-04-08 12:18:27 +02:00
|
|
|
using Content.Shared.GameObjects.Components.Items;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.Serialization;
|
2018-04-25 06:42:35 -05:00
|
|
|
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects
|
|
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
|
|
|
|
[ComponentReference(typeof(ItemComponent))]
|
|
|
|
|
[ComponentReference(typeof(StoreableComponent))]
|
2019-07-19 16:31:56 +02:00
|
|
|
public class ClothingComponent : ItemComponent, IUse
|
2018-04-25 06:42:35 -05:00
|
|
|
{
|
|
|
|
|
public override string Name => "Clothing";
|
2019-04-08 12:18:27 +02:00
|
|
|
public override uint? NetID => ContentNetIDs.CLOTHING;
|
|
|
|
|
|
2018-04-25 06:42:35 -05:00
|
|
|
public SlotFlags SlotFlags = SlotFlags.PREVENTEQUIP; //Different from None, NONE allows equips if no slot flags are required
|
|
|
|
|
|
2019-07-19 16:31:56 +02:00
|
|
|
private bool _quickEquipEnabled = true;
|
2019-04-06 17:11:51 +02:00
|
|
|
private int _heatResistance;
|
|
|
|
|
public int HeatResistance => _heatResistance;
|
|
|
|
|
|
2019-04-08 12:18:27 +02:00
|
|
|
private string _clothingEquippedPrefix;
|
|
|
|
|
public string ClothingEquippedPrefix
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _clothingEquippedPrefix;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Dirty();
|
|
|
|
|
_clothingEquippedPrefix = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-26 23:38:16 +02:00
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
2018-04-25 06:42:35 -05:00
|
|
|
{
|
|
|
|
|
base.ExposeData(serializer);
|
|
|
|
|
|
2019-08-12 21:34:35 +02:00
|
|
|
serializer.DataField(ref _clothingEquippedPrefix, "ClothingPrefix", null);
|
|
|
|
|
|
2018-07-26 23:38:16 +02:00
|
|
|
// TODO: Writing.
|
|
|
|
|
serializer.DataReadFunction("Slots", new List<string>(0), list =>
|
2018-04-25 06:42:35 -05:00
|
|
|
{
|
2018-08-16 22:43:04 +02:00
|
|
|
foreach (var slotflagsloaded in list)
|
2018-07-26 23:38:16 +02:00
|
|
|
{
|
|
|
|
|
SlotFlags |= (SlotFlags)Enum.Parse(typeof(SlotFlags), slotflagsloaded.ToUpper());
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-04-06 17:11:51 +02:00
|
|
|
|
2019-07-19 16:31:56 +02:00
|
|
|
serializer.DataField(ref _quickEquipEnabled, "QuickEquip", true);
|
|
|
|
|
|
2019-04-06 17:11:51 +02:00
|
|
|
serializer.DataFieldCached(ref _heatResistance, "HeatResistance", 323);
|
2018-04-25 06:42:35 -05:00
|
|
|
}
|
2019-04-08 12:18:27 +02:00
|
|
|
|
|
|
|
|
public override ComponentState GetComponentState()
|
|
|
|
|
{
|
|
|
|
|
return new ClothingComponentState(ClothingEquippedPrefix, EquippedPrefix);
|
|
|
|
|
}
|
2019-07-19 16:31:56 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2018-04-25 06:42:35 -05:00
|
|
|
}
|
|
|
|
|
}
|