Files
HSMappy/Mappy/Data/EquipmentConditionHelper.cs

44 lines
1.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 (0100+).
/// 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;
}
}