From 22314f556dbb56720cfc9badc72435edac6daa76 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Thu, 21 Sep 2023 11:23:30 +0200 Subject: [PATCH] Add a stack limit for items to discard --- ARDiscard/ARDiscard.csproj | 2 +- ARDiscard/Configuration.cs | 1 + ARDiscard/GameData/InventoryUtils.cs | 21 ++++++++++++++++----- ARDiscard/Windows/ConfigWindow.cs | 10 ++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ARDiscard/ARDiscard.csproj b/ARDiscard/ARDiscard.csproj index 415ff1b..f0d8663 100644 --- a/ARDiscard/ARDiscard.csproj +++ b/ARDiscard/ARDiscard.csproj @@ -17,7 +17,7 @@ $(appdata)\XIVLauncher\addon\Hooks\dev\ - $(appdata)\XIVLauncher\installedPlugins\AutoRetainer\4.1.1.6\ + $(appdata)\XIVLauncher\installedPlugins\AutoRetainer\4.1.1.8\ diff --git a/ARDiscard/Configuration.cs b/ARDiscard/Configuration.cs index 21fe700..6dccac5 100644 --- a/ARDiscard/Configuration.cs +++ b/ARDiscard/Configuration.cs @@ -13,6 +13,7 @@ internal sealed class Configuration : IPluginConfiguration public ArmouryConfiguration Armoury { get; set; } = new(); public ContextMenuConfiguration ContextMenu { get; set; } = new(); + public uint IgnoreItemCountWhenAbove { get; set; } = 50; public sealed class CharacterInfo { diff --git a/ARDiscard/GameData/InventoryUtils.cs b/ARDiscard/GameData/InventoryUtils.cs index ca1cce0..5c2756c 100644 --- a/ARDiscard/GameData/InventoryUtils.cs +++ b/ARDiscard/GameData/InventoryUtils.cs @@ -55,10 +55,11 @@ internal sealed class InventoryUtils public unsafe List GetAllItemsToDiscard() { List toDiscard = new List(); + Dictionary itemCounts = new(); InventoryManager* inventoryManager = InventoryManager.Instance(); foreach (InventoryType inventoryType in DefaultInventoryTypes) - toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, false, null)); + toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, itemCounts, false, null)); if (_configuration.Armoury.DiscardFromArmouryChest) { @@ -67,17 +68,21 @@ internal sealed class InventoryUtils if (_configuration.Armoury.CheckLeftSideGear) { foreach (InventoryType inventoryType in LeftSideGearInventoryTypes) - toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, true, gearsetItems)); + toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, itemCounts, true, + gearsetItems)); } if (_configuration.Armoury.CheckRightSideGear) { foreach (InventoryType inventoryType in RightSideGearInventoryTypes) - toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, true, gearsetItems)); + toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, itemCounts, true, + gearsetItems)); } } - return toDiscard; + return toDiscard + .Where(x => itemCounts[x.InventoryItem->ItemID] < _configuration.IgnoreItemCountWhenAbove) + .ToList(); } public unsafe InventoryItem* GetNextItemToDiscard(ItemFilter? itemFilter) @@ -89,7 +94,8 @@ internal sealed class InventoryUtils } private unsafe IReadOnlyList GetItemsToDiscard(InventoryManager* inventoryManager, - InventoryType inventoryType, bool doGearChecks, IReadOnlyList? gearsetItems) + InventoryType inventoryType, Dictionary itemCounts, bool doGearChecks, + IReadOnlyList? gearsetItems) { List toDiscard = new List(); InventoryContainer* container = inventoryManager->GetInventoryContainer(inventoryType); @@ -99,6 +105,11 @@ internal sealed class InventoryUtils var item = container->GetInventorySlot(i); if (item != null && item->ItemID != 0) { + if (itemCounts.TryGetValue(item->ItemID, out uint itemCount)) + itemCounts[item->ItemID] = itemCount + item->Quantity; + else + itemCounts[item->ItemID] = item->Quantity; + if (InternalConfiguration.BlacklistedItems.Contains(item->ItemID)) continue; diff --git a/ARDiscard/Windows/ConfigWindow.cs b/ARDiscard/Windows/ConfigWindow.cs index a021085..319ae25 100644 --- a/ARDiscard/Windows/ConfigWindow.cs +++ b/ARDiscard/Windows/ConfigWindow.cs @@ -321,6 +321,16 @@ internal sealed class ConfigWindow : Window ImGui.Unindent(30); ImGui.EndDisabled(); + ImGui.Separator(); + + ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 100); + int ignoreItemCountWhenAbove = (int)_configuration.IgnoreItemCountWhenAbove; + if (ImGui.InputInt("Ignore stacks with >= this number of items", ref ignoreItemCountWhenAbove)) + { + _configuration.IgnoreItemCountWhenAbove = (uint)Math.Max(2, ignoreItemCountWhenAbove); + Save(); + } + ImGui.EndTabItem(); } }