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

132 lines
3.4 KiB
C#

using System.Collections.Generic;
using FFXIVClientStructs.FFXIV.Client.Game;
namespace LLib.Gear;
public static class GearConditionHelper
{
private const ushort MaxCondition = 30000;
private const ushort MaxSpiritbond = 10000;
public unsafe static int? GetLowestConditionPercent()
{
InventoryContainer* equippedContainer = EquipmentSlots.GetEquippedContainer();
if (equippedContainer == null)
{
return null;
}
int? result = null;
for (int i = 0; i < 13; i++)
{
if (i != 5 && EquipmentSlots.TryGetEquippedItem(equippedContainer, i, out var item))
{
int num = item->Condition * 100 / 30000;
if (!result.HasValue || num < result.Value)
{
result = num;
}
}
}
return result;
}
public unsafe static List<SlotCondition> GetAllSlotConditions()
{
List<SlotCondition> list = new List<SlotCondition>(13);
InventoryContainer* equippedContainer = EquipmentSlots.GetEquippedContainer();
if (equippedContainer == null)
{
return list;
}
for (int i = 0; i < 13; i++)
{
if (i != 5 && EquipmentSlots.TryGetEquippedItem(equippedContainer, i, out var item))
{
list.Add(new SlotCondition(i, item->ItemId, item->Condition * 100 / 30000));
}
}
return list;
}
public unsafe static bool HasSpiritbondReadyItem(bool includeBags = false)
{
InventoryContainer* equippedContainer = EquipmentSlots.GetEquippedContainer();
if (equippedContainer != null)
{
for (int i = 0; i < 13; i++)
{
if (i != 5 && EquipmentSlots.TryGetEquippedItem(equippedContainer, i, out var item) && item->SpiritbondOrCollectability >= 10000)
{
return true;
}
}
}
if (!includeBags)
{
return false;
}
InventoryManager* ptr = InventoryManager.Instance();
if (ptr == null)
{
return false;
}
for (InventoryType inventoryType = InventoryType.Inventory1; inventoryType <= InventoryType.Inventory4; inventoryType++)
{
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.Collectable) == 0 && inventorySlot->SpiritbondOrCollectability >= 10000)
{
return true;
}
}
}
return false;
}
public unsafe static int? GetLowestSpiritbondPercent()
{
InventoryContainer* equippedContainer = EquipmentSlots.GetEquippedContainer();
if (equippedContainer == null)
{
return null;
}
int? result = null;
for (int i = 0; i < 13; i++)
{
if (i != 5 && EquipmentSlots.TryGetEquippedItem(equippedContainer, i, out var item))
{
int num = item->SpiritbondOrCollectability * 100 / 10000;
if (!result.HasValue || num < result.Value)
{
result = num;
}
}
}
return result;
}
public unsafe static List<SlotSpiritbond> GetAllSpiritbondInfo()
{
List<SlotSpiritbond> list = new List<SlotSpiritbond>(13);
InventoryContainer* equippedContainer = EquipmentSlots.GetEquippedContainer();
if (equippedContainer == null)
{
return list;
}
for (int i = 0; i < 13; i++)
{
if (i != 5 && EquipmentSlots.TryGetEquippedItem(equippedContainer, i, out var item))
{
list.Add(new SlotSpiritbond(i, item->ItemId, item->SpiritbondOrCollectability * 100 / 10000, item->SpiritbondOrCollectability >= 10000));
}
}
return list;
}
}