diff --git a/ARDiscard/AutoDiscardPlogon.cs b/ARDiscard/AutoDiscardPlogon.cs index 22fc68d..4c754bf 100644 --- a/ARDiscard/AutoDiscardPlogon.cs +++ b/ARDiscard/AutoDiscardPlogon.cs @@ -277,7 +277,6 @@ public class AutoDiscardPlogon : IDalamudPlugin _autoRetainerApi.Dispose(); ECommonsMain.Dispose(); - _inventoryUtils.Dispose(); _pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi; _pluginInterface.UiBuilder.Draw -= _windowSystem.Draw; _commandManager.RemoveHandler("/discard"); diff --git a/ARDiscard/GameData/InternalConfiguration.cs b/ARDiscard/GameData/InternalConfiguration.cs index 37d3675..ecbcb1a 100644 --- a/ARDiscard/GameData/InternalConfiguration.cs +++ b/ARDiscard/GameData/InternalConfiguration.cs @@ -7,5 +7,8 @@ public static class InternalConfiguration public static IReadOnlyList BlacklistedItems = new List { 2820, // red onion helm + 16039, // ala mhigan earrings + 24589, // aetheryte earrings + 33648, // menphina's earrings }.AsReadOnly(); } diff --git a/ARDiscard/GameData/InventoryUtils.cs b/ARDiscard/GameData/InventoryUtils.cs index c31ed1c..e23c852 100644 --- a/ARDiscard/GameData/InventoryUtils.cs +++ b/ARDiscard/GameData/InventoryUtils.cs @@ -1,18 +1,15 @@ using System; using System.Collections.Generic; using System.Linq; -using Dalamud.Data; -using Dalamud.Hooking; using Dalamud.Logging; using Dalamud.Utility.Signatures; using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Client.UI.Misc; -using Lumina.Excel.GeneratedSheets; namespace ARDiscard.GameData; -public class InventoryUtils : IDisposable +public sealed class InventoryUtils { private static readonly InventoryType[] DefaultInventoryTypes = { @@ -55,30 +52,28 @@ public class InventoryUtils : IDisposable SignatureHelper.Initialise(this); } - public void Dispose() - { - } - public unsafe List GetAllItemsToDiscard() { List toDiscard = new List(); InventoryManager* inventoryManager = InventoryManager.Instance(); foreach (InventoryType inventoryType in DefaultInventoryTypes) - toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, false)); + toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, false, null)); if (_configuration.Armoury.DiscardFromArmouryChest) { + var gearsetItems = GetAllGearsetItems(); + if (_configuration.Armoury.CheckLeftSideGear) { foreach (InventoryType inventoryType in LeftSideGearInventoryTypes) - toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, true)); + toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, true, gearsetItems)); } if (_configuration.Armoury.CheckRightSideGear) { foreach (InventoryType inventoryType in RightSideGearInventoryTypes) - toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, true)); + toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, true, gearsetItems)); } } @@ -94,10 +89,9 @@ public class InventoryUtils : IDisposable } private unsafe IReadOnlyList GetItemsToDiscard(InventoryManager* inventoryManager, - InventoryType inventoryType, bool doGearChecks) + InventoryType inventoryType, bool doGearChecks, IReadOnlyList? gearsetItems) { List toDiscard = new List(); - InventoryContainer* container = inventoryManager->GetInventoryContainer(inventoryType); //PluginLog.Verbose($"Checking {inventoryType}, {container->Size}"); for (int i = 0; i < container->Size; ++i) @@ -110,7 +104,7 @@ public class InventoryUtils : IDisposable if (doGearChecks) { - if (IsItemPartOfGearset(item->ItemID)) + if (gearsetItems == null || gearsetItems.Contains(item->ItemID)) continue; ItemCache.CachedItemInfo? itemInfo = _itemCache.GetItem(item->ItemID); @@ -138,12 +132,13 @@ public class InventoryUtils : IDisposable return toDiscard; } - private unsafe bool IsItemPartOfGearset(uint searchForItemId) + private unsafe List? GetAllGearsetItems() { var gearsetModule = RaptureGearsetModule.Instance(); if (gearsetModule == null) - return true; // can't check gearsets, pretend everything is part of one + return null; + List allGearsetItems = new(); for (int i = 0; i < 100; ++i) { var gearset = gearsetModule->GetGearset(i); @@ -166,17 +161,20 @@ public class InventoryUtils : IDisposable }; foreach (var gearsetItem in gearsetItems) { - if (gearsetItem.ItemID == searchForItemId) - return true; + if (gearsetItem.ItemID != 0) + allGearsetItems.Add(gearsetItem.ItemID); } } } - return false; + return allGearsetItems; } public unsafe void Discard(InventoryItem* item) { + if (InternalConfiguration.BlacklistedItems.Contains(item->ItemID)) + throw new Exception($"Can't discard {item->ItemID}"); + _discardItem(AgentInventoryContext.Instance(), item, item->Container, item->Slot, 0); }