qstbak/LLib/LLib.Inventory/InventoryContainers.cs
2026-08-17 20:29:32 +10:00

136 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using FFXIVClientStructs.FFXIV.Client.Game;
namespace LLib.Inventory;
public static class InventoryContainers
{
public static ReadOnlySpan<InventoryType> Bags => new InventoryType[4]
{
InventoryType.Inventory1,
InventoryType.Inventory2,
InventoryType.Inventory3,
InventoryType.Inventory4
};
public static ReadOnlySpan<InventoryType> ArmouryMainHand => new InventoryType[1] { InventoryType.ArmoryMainHand };
public static ReadOnlySpan<InventoryType> ArmouryOffHand => new InventoryType[1] { InventoryType.ArmoryOffHand };
public static ReadOnlySpan<InventoryType> ArmouryLeftSide => new InventoryType[5]
{
InventoryType.ArmoryHead,
InventoryType.ArmoryBody,
InventoryType.ArmoryHands,
InventoryType.ArmoryLegs,
InventoryType.ArmoryFeets
};
public static ReadOnlySpan<InventoryType> ArmouryRightSide => new InventoryType[4]
{
InventoryType.ArmoryEar,
InventoryType.ArmoryNeck,
InventoryType.ArmoryWrist,
InventoryType.ArmoryRings
};
public static ReadOnlySpan<InventoryType> SaddleBag => new InventoryType[2]
{
InventoryType.SaddleBag1,
InventoryType.SaddleBag2
};
public static ReadOnlySpan<InventoryType> PremiumSaddleBag => new InventoryType[2]
{
InventoryType.PremiumSaddleBag1,
InventoryType.PremiumSaddleBag2
};
public unsafe static int CountFreeSlots(ReadOnlySpan<InventoryType> containers)
{
InventoryManager* ptr = InventoryManager.Instance();
if (ptr == null)
{
return 0;
}
int num = 0;
ReadOnlySpan<InventoryType> readOnlySpan = containers;
for (int i = 0; i < readOnlySpan.Length; i++)
{
InventoryType inventoryType = readOnlySpan[i];
InventoryContainer* inventoryContainer = ptr->GetInventoryContainer(inventoryType);
if (inventoryContainer == null)
{
continue;
}
for (int j = 0; j < inventoryContainer->Size; j++)
{
InventoryItem* inventorySlot = inventoryContainer->GetInventorySlot(j);
if (inventorySlot == null || inventorySlot->ItemId == 0)
{
num++;
}
}
}
return num;
}
public unsafe static int CountItems(uint itemId, ReadOnlySpan<InventoryType> containers)
{
InventoryManager* ptr = InventoryManager.Instance();
if (ptr == null)
{
return 0;
}
int num = 0;
ReadOnlySpan<InventoryType> readOnlySpan = containers;
for (int i = 0; i < readOnlySpan.Length; i++)
{
InventoryType inventoryType = readOnlySpan[i];
InventoryContainer* inventoryContainer = ptr->GetInventoryContainer(inventoryType);
if (inventoryContainer == null)
{
continue;
}
for (int j = 0; j < inventoryContainer->Size; j++)
{
InventoryItem* inventorySlot = inventoryContainer->GetInventorySlot(j);
if (inventorySlot != null && inventorySlot->ItemId == itemId)
{
num += inventorySlot->Quantity;
}
}
}
return num;
}
public unsafe static List<InventoryItem> GetHqItems(ReadOnlySpan<InventoryType> containers)
{
List<InventoryItem> list = new List<InventoryItem>();
InventoryManager* ptr = InventoryManager.Instance();
if (ptr == null)
{
return list;
}
ReadOnlySpan<InventoryType> readOnlySpan = containers;
for (int i = 0; i < readOnlySpan.Length; i++)
{
InventoryType inventoryType = readOnlySpan[i];
InventoryContainer* inventoryContainer = ptr->GetInventoryContainer(inventoryType);
if (inventoryContainer == null)
{
continue;
}
for (int j = 0; j < inventoryContainer->Size; j++)
{
InventoryItem* inventorySlot = inventoryContainer->GetInventorySlot(j);
if (inventorySlot != null && inventorySlot->ItemId != 0 && (inventorySlot->Flags & InventoryItem.ItemFlags.HighQuality) != InventoryItem.ItemFlags.None)
{
list.Add(*inventorySlot);
}
}
}
return list;
}
}