2020-07-20 02:06:51 +02:00
|
|
|
|
using System;
|
2019-07-31 15:02:36 +02:00
|
|
|
|
using System.Collections.Generic;
|
2020-07-25 15:11:16 +02:00
|
|
|
|
using Content.Server.GameObjects.Components.GUI;
|
2020-07-07 00:23:41 +02:00
|
|
|
|
using Content.Server.GameObjects.Components.Items.Storage;
|
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;
|
2020-10-14 15:24:07 +02:00
|
|
|
|
using Content.Shared.GameObjects.Components.Storage;
|
2020-09-01 12:34:53 +02:00
|
|
|
|
using Content.Shared.Interfaces;
|
2020-07-18 22:51:56 -07:00
|
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-02-18 09:09:07 +01:00
|
|
|
|
using Robust.Shared.Players;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.Serialization;
|
2020-09-08 13:30:22 +02:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
2018-04-25 06:42:35 -05:00
|
|
|
|
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
|
|
|
|
|
|
2020-08-13 14:40:27 +02:00
|
|
|
|
namespace Content.Server.GameObjects.Components.Items.Clothing
|
2018-04-25 06:42:35 -05:00
|
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
|
[RegisterComponent]
|
|
|
|
|
|
[ComponentReference(typeof(ItemComponent))]
|
2020-07-17 11:03:07 +02:00
|
|
|
|
[ComponentReference(typeof(StorableComponent))]
|
2020-10-14 15:24:07 +02:00
|
|
|
|
[ComponentReference(typeof(SharedStorableComponent))]
|
2020-07-08 18:28:59 +02:00
|
|
|
|
[ComponentReference(typeof(IItemComponent))]
|
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;
|
|
|
|
|
|
|
2020-09-08 13:30:22 +02:00
|
|
|
|
[ViewVariables]
|
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;
|
2020-09-08 13:30:22 +02:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2019-04-06 17:11:51 +02:00
|
|
|
|
public int HeatResistance => _heatResistance;
|
|
|
|
|
|
|
2019-04-08 12:18:27 +02:00
|
|
|
|
private string _clothingEquippedPrefix;
|
2020-09-08 13:30:22 +02:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2019-04-08 12:18:27 +02:00
|
|
|
|
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
|
|
|
|
|
2021-02-18 09:09:07 +01:00
|
|
|
|
public override ComponentState GetComponentState(ICommonSession player)
|
2019-04-08 12:18:27 +02:00
|
|
|
|
{
|
|
|
|
|
|
return new ClothingComponentState(ClothingEquippedPrefix, EquippedPrefix);
|
|
|
|
|
|
}
|
2019-07-19 16:31:56 +02:00
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
|
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
2019-07-19 16:31:56 +02:00
|
|
|
|
{
|
|
|
|
|
|
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);
|
2020-05-23 17:27:57 +02:00
|
|
|
|
|
|
|
|
|
|
if (!TryEquip(inv, slot, eventArgs.User))
|
|
|
|
|
|
{
|
|
|
|
|
|
hands.Drop(item.Owner);
|
|
|
|
|
|
inv.Equip(slot, item);
|
|
|
|
|
|
hands.PutInHand(Owner.GetComponent<ItemComponent>());
|
|
|
|
|
|
}
|
2019-07-19 16:31:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
hands.Drop(Owner);
|
2020-05-23 17:27:57 +02:00
|
|
|
|
if (!TryEquip(inv, slot, eventArgs.User))
|
|
|
|
|
|
hands.PutInHand(Owner.GetComponent<ItemComponent>());
|
2019-07-19 16:31:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-23 17:27:57 +02:00
|
|
|
|
return true;
|
2019-07-19 16:31:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2020-05-23 17:27:57 +02:00
|
|
|
|
|
|
|
|
|
|
private bool TryEquip(InventoryComponent inv, Slots slot, IEntity user)
|
|
|
|
|
|
{
|
2020-08-16 16:30:52 +02:00
|
|
|
|
if (!inv.Equip(slot, this, true, out var reason))
|
2020-05-23 17:27:57 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (reason != null)
|
2020-09-01 12:34:53 +02:00
|
|
|
|
Owner.PopupMessage(user, reason);
|
2020-05-23 17:27:57 +02:00
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2018-04-25 06:42:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|