2021-07-12 01:32:10 -07:00
|
|
|
using System;
|
2018-09-19 18:54:04 +02:00
|
|
|
using System.Collections.Generic;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Movement.Components;
|
2019-07-23 23:24:47 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2019-07-23 23:24:47 +02:00
|
|
|
using Robust.Shared.IoC;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Reflection;
|
2019-07-23 23:24:47 +02:00
|
|
|
using Robust.Shared.Serialization;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2019-07-23 23:24:47 +02:00
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
2021-06-09 22:19:39 +02:00
|
|
|
using static Content.Shared.Inventory.EquipmentSlotDefines;
|
2018-04-25 06:42:35 -05:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Inventory
|
2018-04-25 06:42:35 -05:00
|
|
|
{
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2021-11-07 22:17:35 -07:00
|
|
|
public abstract class SharedInventoryComponent : Component
|
2018-04-25 06:42:35 -05:00
|
|
|
{
|
2021-03-15 21:55:49 +01:00
|
|
|
[Dependency] protected readonly IReflectionManager ReflectionManager = default!;
|
|
|
|
|
[Dependency] protected readonly IDynamicTypeFactory DynamicTypeFactory = default!;
|
2019-07-23 23:24:47 +02:00
|
|
|
|
2018-04-25 06:42:35 -05:00
|
|
|
public sealed override string Name => "Inventory";
|
|
|
|
|
|
2019-07-23 23:24:47 +02:00
|
|
|
[ViewVariables]
|
2021-03-15 21:55:49 +01:00
|
|
|
protected Inventory InventoryInstance { get; private set; } = default!;
|
2019-07-23 23:24:47 +02:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("Template")]
|
2019-07-23 23:24:47 +02:00
|
|
|
private string _templateName = "HumanInventory"; //stored for serialization purposes
|
|
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2019-07-23 23:24:47 +02:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
CreateInventory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateInventory()
|
|
|
|
|
{
|
|
|
|
|
var type = ReflectionManager.LooseGetType(_templateName);
|
|
|
|
|
DebugTools.Assert(type != null);
|
2021-03-15 21:55:49 +01:00
|
|
|
InventoryInstance = DynamicTypeFactory.CreateInstance<Inventory>(type!);
|
2019-07-23 23:24:47 +02:00
|
|
|
}
|
|
|
|
|
|
2020-12-13 14:28:20 -08:00
|
|
|
/// <returns>true if the item is equipped to an equip slot (NOT inside an equipped container
|
|
|
|
|
/// like inside a backpack)</returns>
|
2021-12-04 12:59:44 +01:00
|
|
|
public abstract bool IsEquipped(EntityUid item);
|
2020-12-13 14:28:20 -08:00
|
|
|
|
2018-04-25 06:42:35 -05:00
|
|
|
[Serializable, NetSerializable]
|
2018-09-19 18:54:04 +02:00
|
|
|
protected class InventoryComponentState : ComponentState
|
2018-04-25 06:42:35 -05:00
|
|
|
{
|
2018-09-19 18:54:04 +02:00
|
|
|
public List<KeyValuePair<Slots, EntityUid>> Entities { get; }
|
2020-07-26 07:25:38 -05:00
|
|
|
public KeyValuePair<Slots, (EntityUid entity, bool fits)>? HoverEntity { get; }
|
2018-04-25 06:42:35 -05:00
|
|
|
|
2021-07-12 01:32:10 -07:00
|
|
|
public InventoryComponentState(List<KeyValuePair<Slots, EntityUid>> entities, KeyValuePair<Slots, (EntityUid entity, bool fits)>? hoverEntity = null)
|
2018-04-25 06:42:35 -05:00
|
|
|
{
|
2018-09-19 18:54:04 +02:00
|
|
|
Entities = entities;
|
2020-07-26 07:25:38 -05:00
|
|
|
HoverEntity = hoverEntity;
|
2018-04-25 06:42:35 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2018-04-25 06:42:35 -05:00
|
|
|
public class ClientInventoryMessage : ComponentMessage
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2018-04-25 06:42:35 -05:00
|
|
|
{
|
|
|
|
|
public Slots Inventoryslot;
|
|
|
|
|
public ClientInventoryUpdate Updatetype;
|
|
|
|
|
|
|
|
|
|
public ClientInventoryMessage(Slots inventoryslot, ClientInventoryUpdate updatetype)
|
|
|
|
|
{
|
|
|
|
|
Directed = true;
|
|
|
|
|
Inventoryslot = inventoryslot;
|
|
|
|
|
Updatetype = updatetype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ClientInventoryUpdate
|
|
|
|
|
{
|
|
|
|
|
Equip = 0,
|
2020-07-26 07:25:38 -05:00
|
|
|
Use = 1,
|
|
|
|
|
Hover = 2
|
2018-04-25 06:42:35 -05:00
|
|
|
}
|
|
|
|
|
}
|
2019-07-29 13:32:04 -07:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Component message for opening the Storage UI of item in Slot
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable, NetSerializable]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2019-07-29 13:32:04 -07:00
|
|
|
public class OpenSlotStorageUIMessage : ComponentMessage
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2019-07-29 13:32:04 -07:00
|
|
|
{
|
|
|
|
|
public Slots Slot;
|
|
|
|
|
|
|
|
|
|
public OpenSlotStorageUIMessage(Slots slot)
|
|
|
|
|
{
|
|
|
|
|
Directed = true;
|
|
|
|
|
Slot = slot;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-25 06:42:35 -05:00
|
|
|
}
|
|
|
|
|
}
|