2021-03-16 15:50:20 +01:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Items;
|
|
|
|
|
using Content.Shared.Item;
|
2021-03-01 15:24:46 -08:00
|
|
|
using Robust.Shared.Containers;
|
2020-01-20 00:26:11 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-05-23 17:27:57 +02:00
|
|
|
using Robust.Shared.Localization;
|
2021-06-09 22:19:39 +02:00
|
|
|
using static Content.Shared.Inventory.EquipmentSlotDefines;
|
2020-01-20 00:26:11 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Inventory.Components
|
2020-01-20 00:26:11 +01:00
|
|
|
{
|
|
|
|
|
// Handles the special behavior of pockets/ID card slot and their relation to uniforms.
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
[ComponentReference(typeof(IInventoryController))]
|
|
|
|
|
public class HumanInventoryControllerComponent : Component, IInventoryController
|
|
|
|
|
{
|
|
|
|
|
public override string Name => "HumanInventoryController";
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
private InventoryComponent _inventory = default!;
|
2020-01-20 00:26:11 +01:00
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2020-01-20 00:26:11 +01:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
_inventory = Owner.EnsureComponent<InventoryComponent>();
|
2020-01-20 00:26:11 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
bool IInventoryController.CanEquip(Slots slot, IEntity entity, bool flagsCheck, [NotNullWhen(false)] out string? reason)
|
2020-01-20 00:26:11 +01:00
|
|
|
{
|
|
|
|
|
var slotMask = SlotMasks[slot];
|
2020-05-23 17:27:57 +02:00
|
|
|
reason = null;
|
2020-01-20 00:26:11 +01:00
|
|
|
|
|
|
|
|
if ((slotMask & (SlotFlags.POCKET | SlotFlags.IDCARD)) != SlotFlags.NONE)
|
|
|
|
|
{
|
|
|
|
|
// Can't wear stuff in ID card or pockets unless you have a uniform.
|
|
|
|
|
if (_inventory.GetSlotItem(Slots.INNERCLOTHING) == null)
|
|
|
|
|
{
|
2020-05-23 22:57:25 +02:00
|
|
|
reason = Loc.GetString(slotMask == SlotFlags.IDCARD
|
2021-06-21 02:13:54 +02:00
|
|
|
? "human-inventory-controller-component-need-uniform-to-store-in-id-slot-text"
|
|
|
|
|
: "human-inventory-controller-component-need-uniform-to-store-in-pockets-text");
|
2020-01-20 00:26:11 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slotMask == SlotFlags.POCKET)
|
|
|
|
|
{
|
|
|
|
|
var itemComponent = entity.GetComponent<ItemComponent>();
|
|
|
|
|
|
|
|
|
|
// If this item is small enough then it always fits in pockets.
|
2020-10-14 15:24:07 +02:00
|
|
|
if (itemComponent.Size <= (int) ReferenceSizes.Pocket)
|
2020-01-20 00:26:11 +01:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-05-23 17:27:57 +02:00
|
|
|
else if (!flagsCheck)
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
reason = Loc.GetString("human-inventory-controller-component-too-large-text");
|
2020-05-23 17:27:57 +02:00
|
|
|
}
|
2020-01-20 00:26:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Standard flag check.
|
|
|
|
|
return flagsCheck;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-18 01:49:18 -07:00
|
|
|
public void CheckUniformExists() { Owner.SpawnTimer(0, DropIdAndPocketsIfWeNoLongerHaveAUniform); }
|
2020-01-20 00:26:11 +01:00
|
|
|
|
|
|
|
|
// Hey, it's descriptive.
|
|
|
|
|
private void DropIdAndPocketsIfWeNoLongerHaveAUniform()
|
|
|
|
|
{
|
2020-01-26 19:52:09 +01:00
|
|
|
if (Deleted)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 00:26:11 +01:00
|
|
|
if (_inventory.GetSlotItem(Slots.INNERCLOTHING) != null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DropMaybe(Slots slot)
|
|
|
|
|
{
|
|
|
|
|
if (_inventory.GetSlotItem(slot) != null)
|
|
|
|
|
{
|
|
|
|
|
_inventory.Unequip(slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DropMaybe(Slots.POCKET1);
|
|
|
|
|
DropMaybe(Slots.POCKET2);
|
|
|
|
|
DropMaybe(Slots.IDCARD);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|