From 09c0424b956aff9a5e306e47ff427ee989b0d1de Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sun, 24 Mar 2024 10:21:26 +0100 Subject: [PATCH] Include free inventory slots in character stats --- Influx.sln.DotSettings | 3 ++- Influx/AllaganTools/AllaganToolsIpc.cs | 4 ++++ Influx/AllaganTools/Currencies.cs | 1 + Influx/AllaganTools/Inventory.cs | 1 + Influx/AllaganTools/InventoryItem.cs | 5 +++++ Influx/Influx/InfluxStatisticsClient.cs | 3 ++- 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Influx.sln.DotSettings b/Influx.sln.DotSettings index 6a6eae6..df0680d 100644 --- a/Influx.sln.DotSettings +++ b/Influx.sln.DotSettings @@ -1,2 +1,3 @@  - True \ No newline at end of file + True + True \ No newline at end of file diff --git a/Influx/AllaganTools/AllaganToolsIpc.cs b/Influx/AllaganTools/AllaganToolsIpc.cs index 04d054e..b022606 100644 --- a/Influx/AllaganTools/AllaganToolsIpc.cs +++ b/Influx/AllaganTools/AllaganToolsIpc.cs @@ -5,6 +5,7 @@ using Dalamud.Plugin; using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc.Exceptions; using Dalamud.Plugin.Services; +using FFXIVClientStructs.FFXIV.Client.Game; using LLib; namespace Influx.AllaganTools; @@ -129,6 +130,7 @@ internal sealed class AllaganToolsIpc : IDisposable Ventures = inv.Sum(21072), CeruleumTanks = inv.Sum(10155), RepairKits = inv.Sum(10373), + FreeSlots = inv.FreeInventorySlots, }; }); } @@ -144,5 +146,7 @@ internal sealed class AllaganToolsIpc : IDisposable private sealed class InventoryWrapper(IEnumerable items) { public long Sum(int itemId) => items.Where(x => x.ItemId == itemId).Sum(x => x.Quantity); + + public int FreeInventorySlots => 140 - items.Count(x => x.Category == 1); } } diff --git a/Influx/AllaganTools/Currencies.cs b/Influx/AllaganTools/Currencies.cs index fc05a63..d37908a 100644 --- a/Influx/AllaganTools/Currencies.cs +++ b/Influx/AllaganTools/Currencies.cs @@ -10,4 +10,5 @@ internal struct Currencies public long Ventures { get; init; } public long CeruleumTanks { get; init; } public long RepairKits { get; init; } + public int FreeSlots { get; init; } } diff --git a/Influx/AllaganTools/Inventory.cs b/Influx/AllaganTools/Inventory.cs index 0028dbd..d93c909 100644 --- a/Influx/AllaganTools/Inventory.cs +++ b/Influx/AllaganTools/Inventory.cs @@ -27,5 +27,6 @@ internal sealed class Inventory .SelectMany(x => x.Cast()) .Where(x => x != null) .Select(x => new InventoryItem(x!)) + .Where(x => x.ItemId != 0) .ToList(); } diff --git a/Influx/AllaganTools/InventoryItem.cs b/Influx/AllaganTools/InventoryItem.cs index b9e8780..f9f5c0d 100644 --- a/Influx/AllaganTools/InventoryItem.cs +++ b/Influx/AllaganTools/InventoryItem.cs @@ -1,4 +1,5 @@ using System; +using FFXIVClientStructs.FFXIV.Client.Game; namespace Influx.AllaganTools; @@ -7,10 +8,14 @@ internal sealed class InventoryItem public InventoryItem(object @delegate) { ArgumentNullException.ThrowIfNull(@delegate); + Category = (int)@delegate.GetType().GetField("SortedCategory")!.GetValue(@delegate)!; + Container = (int)@delegate.GetType().GetField("SortedContainer")!.GetValue(@delegate)!; ItemId = (uint)@delegate.GetType().GetField("ItemId")!.GetValue(@delegate)!; Quantity = (uint)@delegate.GetType().GetField("Quantity")!.GetValue(@delegate)!; } + public int Category { get; } + public int Container { get; } public uint ItemId { get; } public uint Quantity { get; } } diff --git a/Influx/Influx/InfluxStatisticsClient.cs b/Influx/Influx/InfluxStatisticsClient.cs index 8d33fd6..2f1d827 100644 --- a/Influx/Influx/InfluxStatisticsClient.cs +++ b/Influx/Influx/InfluxStatisticsClient.cs @@ -171,7 +171,8 @@ internal sealed class InfluxStatisticsClient : IDisposable .Field("mgp", localStats?.MGP ?? 0) .Field("ventures", currencies.Ventures) .Field("ceruleum_tanks", currencies.CeruleumTanks) - .Field("repair_kits", currencies.RepairKits); + .Field("repair_kits", currencies.RepairKits) + .Field("free_inventory", currencies.FreeSlots); if (localStats != null) {