1
0
Fork 0

Add a stack limit for items to discard

master
Liza 2023-09-21 11:23:30 +02:00
parent d9ce02123c
commit 22314f556d
Signed by: liza
GPG Key ID: 7199F8D727D55F67
4 changed files with 28 additions and 6 deletions

View File

@ -17,7 +17,7 @@
<PropertyGroup> <PropertyGroup>
<DalamudLibPath>$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath> <DalamudLibPath>$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
<AutoRetainerLibPath>$(appdata)\XIVLauncher\installedPlugins\AutoRetainer\4.1.1.6\</AutoRetainerLibPath> <AutoRetainerLibPath>$(appdata)\XIVLauncher\installedPlugins\AutoRetainer\4.1.1.8\</AutoRetainerLibPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'"> <PropertyGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'">

View File

@ -13,6 +13,7 @@ internal sealed class Configuration : IPluginConfiguration
public ArmouryConfiguration Armoury { get; set; } = new(); public ArmouryConfiguration Armoury { get; set; } = new();
public ContextMenuConfiguration ContextMenu { get; set; } = new(); public ContextMenuConfiguration ContextMenu { get; set; } = new();
public uint IgnoreItemCountWhenAbove { get; set; } = 50;
public sealed class CharacterInfo public sealed class CharacterInfo
{ {

View File

@ -55,10 +55,11 @@ internal sealed class InventoryUtils
public unsafe List<ItemWrapper> GetAllItemsToDiscard() public unsafe List<ItemWrapper> GetAllItemsToDiscard()
{ {
List<ItemWrapper> toDiscard = new List<ItemWrapper>(); List<ItemWrapper> toDiscard = new List<ItemWrapper>();
Dictionary<uint, uint> itemCounts = new();
InventoryManager* inventoryManager = InventoryManager.Instance(); InventoryManager* inventoryManager = InventoryManager.Instance();
foreach (InventoryType inventoryType in DefaultInventoryTypes) foreach (InventoryType inventoryType in DefaultInventoryTypes)
toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, false, null)); toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, itemCounts, false, null));
if (_configuration.Armoury.DiscardFromArmouryChest) if (_configuration.Armoury.DiscardFromArmouryChest)
{ {
@ -67,17 +68,21 @@ internal sealed class InventoryUtils
if (_configuration.Armoury.CheckLeftSideGear) if (_configuration.Armoury.CheckLeftSideGear)
{ {
foreach (InventoryType inventoryType in LeftSideGearInventoryTypes) foreach (InventoryType inventoryType in LeftSideGearInventoryTypes)
toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, true, gearsetItems)); toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, itemCounts, true,
gearsetItems));
} }
if (_configuration.Armoury.CheckRightSideGear) if (_configuration.Armoury.CheckRightSideGear)
{ {
foreach (InventoryType inventoryType in RightSideGearInventoryTypes) 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) public unsafe InventoryItem* GetNextItemToDiscard(ItemFilter? itemFilter)
@ -89,7 +94,8 @@ internal sealed class InventoryUtils
} }
private unsafe IReadOnlyList<ItemWrapper> GetItemsToDiscard(InventoryManager* inventoryManager, private unsafe IReadOnlyList<ItemWrapper> GetItemsToDiscard(InventoryManager* inventoryManager,
InventoryType inventoryType, bool doGearChecks, IReadOnlyList<uint>? gearsetItems) InventoryType inventoryType, Dictionary<uint, uint> itemCounts, bool doGearChecks,
IReadOnlyList<uint>? gearsetItems)
{ {
List<ItemWrapper> toDiscard = new List<ItemWrapper>(); List<ItemWrapper> toDiscard = new List<ItemWrapper>();
InventoryContainer* container = inventoryManager->GetInventoryContainer(inventoryType); InventoryContainer* container = inventoryManager->GetInventoryContainer(inventoryType);
@ -99,6 +105,11 @@ internal sealed class InventoryUtils
var item = container->GetInventorySlot(i); var item = container->GetInventorySlot(i);
if (item != null && item->ItemID != 0) 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)) if (InternalConfiguration.BlacklistedItems.Contains(item->ItemID))
continue; continue;

View File

@ -321,6 +321,16 @@ internal sealed class ConfigWindow : Window
ImGui.Unindent(30); ImGui.Unindent(30);
ImGui.EndDisabled(); 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(); ImGui.EndTabItem();
} }
} }