e160af2ab5
Made-with: Cursor
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using System;
|
||
using FFXIVClientStructs.FFXIV.Client.Game;
|
||
|
||
namespace Mappy.Data;
|
||
|
||
/// <summary>
|
||
/// Returns the condition percentage of the player's most damaged equipped item.
|
||
/// Uses the same logic as RepairMe (chalkos/RepairMe): raw condition / 300.
|
||
/// </summary>
|
||
public static class EquipmentConditionHelper
|
||
{
|
||
private const uint EquipmentContainerSize = 13;
|
||
|
||
/// <summary>
|
||
/// Gets the lowest condition percent among equipped items (0–100+).
|
||
/// Returns 100 if no gear or unavailable (e.g. not logged in).
|
||
/// </summary>
|
||
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;
|
||
}
|
||
}
|