73 lines
2.7 KiB
C#
73 lines
2.7 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 static InventorySlotState[] CloneSlots(InventorySlotState[] slots)
|
|
{
|
|
var copy = new InventorySlotState[slots.Length];
|
|
for (var i = 0; i < slots.Length; i++)
|
|
{
|
|
var s = slots[i];
|
|
copy[i] = new InventorySlotState(s.SlotIndex, s.ItemId, s.Quantity);
|
|
}
|
|
|
|
return copy;
|
|
}
|
|
|
|
/// <summary>Deep-copies bag and equipment slot arrays (NEO-69 craft pre-flight, NEO-105 encounter grant pre-flight).</summary>
|
|
public PlayerInventorySnapshot Clone() =>
|
|
new()
|
|
{
|
|
BagSlots = CloneSlots(BagSlots),
|
|
EquipmentSlots = CloneSlots(EquipmentSlots),
|
|
};
|
|
|
|
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;
|
|
}
|