using System;
using FFXIVClientStructs.FFXIV.Client.Game;
namespace Mappy.Data;
///
/// Returns the condition percentage of the player's most damaged equipped item.
/// Uses the same logic as RepairMe (chalkos/RepairMe): raw condition / 300.
///
public static class EquipmentConditionHelper
{
private const uint EquipmentContainerSize = 13;
///
/// Gets the lowest condition percent among equipped items (0–100+).
/// Returns 100 if no gear or unavailable (e.g. not logged in).
///
public static unsafe float GetLowestConditionPercent()
{
var inventoryManager = InventoryManager.Instance();
if (inventoryManager == null) return 100f;
var equipmentContainer = inventoryManager->GetInventoryContainer(InventoryType.EquippedItems);
if (equipmentContainer == null) return 100f;
var inventoryItem = equipmentContainer->GetInventorySlot(0);
if (inventoryItem == null) return 100f;
ushort lowestCondition = 60000; // max raw condition is 30000
var foundAny = false;
for (var i = 0; i < EquipmentContainerSize; i++, inventoryItem++)
{
if (inventoryItem->ItemId == 0) continue;
foundAny = true;
if (lowestCondition > inventoryItem->Condition)
lowestCondition = inventoryItem->Condition;
}
return foundAny ? lowestCondition / 300f : 100f;
}
}