using System; using System.Collections.Generic; using FFXIVClientStructs.FFXIV.Client.Game; namespace LLib.Inventory; public static class InventoryContainers { public static ReadOnlySpan Bags => new InventoryType[4] { InventoryType.Inventory1, InventoryType.Inventory2, InventoryType.Inventory3, InventoryType.Inventory4 }; public static ReadOnlySpan ArmouryMainHand => new InventoryType[1] { InventoryType.ArmoryMainHand }; public static ReadOnlySpan ArmouryOffHand => new InventoryType[1] { InventoryType.ArmoryOffHand }; public static ReadOnlySpan ArmouryLeftSide => new InventoryType[5] { InventoryType.ArmoryHead, InventoryType.ArmoryBody, InventoryType.ArmoryHands, InventoryType.ArmoryLegs, InventoryType.ArmoryFeets }; public static ReadOnlySpan ArmouryRightSide => new InventoryType[4] { InventoryType.ArmoryEar, InventoryType.ArmoryNeck, InventoryType.ArmoryWrist, InventoryType.ArmoryRings }; public static ReadOnlySpan SaddleBag => new InventoryType[2] { InventoryType.SaddleBag1, InventoryType.SaddleBag2 }; public static ReadOnlySpan PremiumSaddleBag => new InventoryType[2] { InventoryType.PremiumSaddleBag1, InventoryType.PremiumSaddleBag2 }; public unsafe static int CountFreeSlots(ReadOnlySpan containers) { InventoryManager* ptr = InventoryManager.Instance(); if (ptr == null) { return 0; } int num = 0; ReadOnlySpan 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 containers) { InventoryManager* ptr = InventoryManager.Instance(); if (ptr == null) { return 0; } int num = 0; ReadOnlySpan 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 GetHqItems(ReadOnlySpan containers) { List list = new List(); InventoryManager* ptr = InventoryManager.Instance(); if (ptr == null) { return list; } ReadOnlySpan 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; } }