neon-sprawl/server/NeonSprawl.Server/Game/Items/PlayerInventorySnapshot.cs

53 lines
2.1 KiB
C#

namespace NeonSprawl.Server.Game.Items;
/// <summary>Fixed-size bag + equipment slot arrays for one player (NEO-54).</summary>
public sealed class PlayerInventorySnapshot
{
public const int BagSlotCount = 24;
public const int EquipmentSlotCount = 1;
public required InventorySlotState[] BagSlots { get; init; }
public required InventorySlotState[] EquipmentSlots { get; init; }
public static PlayerInventorySnapshot Empty()
{
return new PlayerInventorySnapshot
{
BagSlots = CreateEmptySlots(BagSlotCount),
EquipmentSlots = CreateEmptySlots(EquipmentSlotCount),
};
}
public static InventorySlotState[] CreateEmptySlots(int count)
{
var slots = new InventorySlotState[count];
for (var i = 0; i < count; i++)
{
slots[i] = new InventorySlotState(i, null, 0);
}
return slots;
}
public InventorySlotState[] GetSlots(InventoryContainerKind container) =>
container == InventoryContainerKind.Equipment ? EquipmentSlots : BagSlots;
public PlayerInventorySnapshot WithSlots(InventoryContainerKind container, InventorySlotState[] slots) =>
container == InventoryContainerKind.Equipment
? new PlayerInventorySnapshot { BagSlots = BagSlots, EquipmentSlots = slots }
: new PlayerInventorySnapshot { BagSlots = slots, EquipmentSlots = EquipmentSlots };
public static InventoryContainerKind ContainerFromSlotKind(string inventorySlotKind) =>
string.Equals(inventorySlotKind, "equipment", StringComparison.OrdinalIgnoreCase)
? InventoryContainerKind.Equipment
: InventoryContainerKind.Bag;
public static string ContainerKindToPersistence(InventoryContainerKind container) =>
container == InventoryContainerKind.Equipment ? "equipment" : "bag";
public static InventoryContainerKind ContainerKindFromPersistence(string value) =>
string.Equals(value, "equipment", StringComparison.OrdinalIgnoreCase)
? InventoryContainerKind.Equipment
: InventoryContainerKind.Bag;
}