142 lines
3.6 KiB
C#
142 lines
3.6 KiB
C#
using FFXIVClientStructs.FFXIV.Client.Game;
|
|
|
|
namespace LLib.Gear;
|
|
|
|
public static class EEquipSlotCategoryExtensions
|
|
{
|
|
public static InventoryType? GetArmoryContainer(this EEquipSlotCategory slot)
|
|
{
|
|
switch (slot)
|
|
{
|
|
case EEquipSlotCategory.OneHandedMainHand:
|
|
case EEquipSlotCategory.TwoHandedMainHand:
|
|
return InventoryType.ArmoryMainHand;
|
|
case EEquipSlotCategory.Shield:
|
|
return InventoryType.ArmoryOffHand;
|
|
case EEquipSlotCategory.Head:
|
|
return InventoryType.ArmoryHead;
|
|
case EEquipSlotCategory.Body:
|
|
return InventoryType.ArmoryBody;
|
|
case EEquipSlotCategory.Hands:
|
|
return InventoryType.ArmoryHands;
|
|
case EEquipSlotCategory.Legs:
|
|
return InventoryType.ArmoryLegs;
|
|
case EEquipSlotCategory.Feet:
|
|
return InventoryType.ArmoryFeets;
|
|
case EEquipSlotCategory.Ears:
|
|
return InventoryType.ArmoryEar;
|
|
case EEquipSlotCategory.Neck:
|
|
return InventoryType.ArmoryNeck;
|
|
case EEquipSlotCategory.Wrists:
|
|
return InventoryType.ArmoryWrist;
|
|
case EEquipSlotCategory.Rings:
|
|
return InventoryType.ArmoryRings;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public unsafe static int? FindFreeSlot(InventoryType container)
|
|
{
|
|
InventoryManager* ptr = InventoryManager.Instance();
|
|
if (ptr == null)
|
|
{
|
|
return null;
|
|
}
|
|
InventoryContainer* inventoryContainer = ptr->GetInventoryContainer(container);
|
|
if (inventoryContainer == null)
|
|
{
|
|
return null;
|
|
}
|
|
for (int i = 0; i < inventoryContainer->Size; i++)
|
|
{
|
|
InventoryItem* inventorySlot = inventoryContainer->GetInventorySlot(i);
|
|
if (inventorySlot != null && inventorySlot->ItemId == 0)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public unsafe static bool TryUnequipItem(int equippedSlotIndex)
|
|
{
|
|
InventoryType? inventoryType;
|
|
switch (equippedSlotIndex)
|
|
{
|
|
case 0:
|
|
inventoryType = InventoryType.ArmoryMainHand;
|
|
break;
|
|
case 1:
|
|
inventoryType = InventoryType.ArmoryOffHand;
|
|
break;
|
|
case 2:
|
|
inventoryType = InventoryType.ArmoryHead;
|
|
break;
|
|
case 3:
|
|
inventoryType = InventoryType.ArmoryBody;
|
|
break;
|
|
case 4:
|
|
inventoryType = InventoryType.ArmoryHands;
|
|
break;
|
|
case 6:
|
|
inventoryType = InventoryType.ArmoryLegs;
|
|
break;
|
|
case 7:
|
|
inventoryType = InventoryType.ArmoryFeets;
|
|
break;
|
|
case 8:
|
|
inventoryType = InventoryType.ArmoryEar;
|
|
break;
|
|
case 9:
|
|
inventoryType = InventoryType.ArmoryNeck;
|
|
break;
|
|
case 10:
|
|
inventoryType = InventoryType.ArmoryWrist;
|
|
break;
|
|
case 11:
|
|
case 12:
|
|
inventoryType = InventoryType.ArmoryRings;
|
|
break;
|
|
case 13:
|
|
inventoryType = InventoryType.ArmorySoulCrystal;
|
|
break;
|
|
default:
|
|
inventoryType = null;
|
|
break;
|
|
}
|
|
InventoryType? inventoryType2 = inventoryType;
|
|
if (inventoryType2.HasValue)
|
|
{
|
|
InventoryType valueOrDefault = inventoryType2.GetValueOrDefault();
|
|
InventoryManager* ptr = InventoryManager.Instance();
|
|
if (ptr == null)
|
|
{
|
|
return false;
|
|
}
|
|
InventoryContainer* inventoryContainer = ptr->GetInventoryContainer(InventoryType.EquippedItems);
|
|
if (inventoryContainer == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (equippedSlotIndex < 0 || equippedSlotIndex >= inventoryContainer->Size)
|
|
{
|
|
return false;
|
|
}
|
|
InventoryItem* inventorySlot = inventoryContainer->GetInventorySlot(equippedSlotIndex);
|
|
if (inventorySlot == null || inventorySlot->ItemId == 0)
|
|
{
|
|
return false;
|
|
}
|
|
int? num = FindFreeSlot(valueOrDefault);
|
|
if (num.HasValue)
|
|
{
|
|
int valueOrDefault2 = num.GetValueOrDefault();
|
|
ptr->MoveItemSlot(InventoryType.EquippedItems, (ushort)equippedSlotIndex, valueOrDefault, (ushort)valueOrDefault2, a6: true);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
}
|