Allow for weapons/tools to be discarded

This commit is contained in:
Liza 2024-01-24 07:55:49 +01:00
parent f60cfab13b
commit 34b40a8c88
Signed by: liza
GPG Key ID: 7199F8D727D55F67
5 changed files with 46 additions and 21 deletions

View File

@ -26,6 +26,7 @@ internal sealed class Configuration : IPluginConfiguration
public sealed class ArmouryConfiguration public sealed class ArmouryConfiguration
{ {
public bool DiscardFromArmouryChest { get; set; } = false; public bool DiscardFromArmouryChest { get; set; } = false;
public bool CheckMainHandOffHand { get; set; } = false;
public bool CheckLeftSideGear { get; set; } = false; public bool CheckLeftSideGear { get; set; } = false;
public bool CheckRightSideGear { get; set; } = false; public bool CheckRightSideGear { get; set; } = false;
public int MaximumGearItemLevel { get; set; } = 45; public int MaximumGearItemLevel { get; set; } = 45;

View File

@ -29,6 +29,8 @@ internal static class InternalConfiguration
.ToList() .ToList()
.AsReadOnly(); .AsReadOnly();
public static readonly IList<uint> UltimateWeapons = new List<uint>();
/// <summary> /// <summary>
/// Items that are unique/untradeable, but should still be possible to discard. This is moreso because /// Items that are unique/untradeable, but should still be possible to discard. This is moreso because
/// 99% of the unique/untradeable items should NOT be selectable for discard, but these are OK. /// 99% of the unique/untradeable items should NOT be selectable for discard, but these are OK.

View File

@ -18,6 +18,12 @@ internal sealed class InventoryUtils
InventoryType.Inventory4 InventoryType.Inventory4
}; };
private static readonly InventoryType[] MainHandOffHandInventoryTypes =
{
InventoryType.ArmoryMainHand,
InventoryType.ArmoryOffHand,
};
private static readonly InventoryType[] LeftSideGearInventoryTypes = private static readonly InventoryType[] LeftSideGearInventoryTypes =
{ {
InventoryType.ArmoryHead, InventoryType.ArmoryHead,
@ -60,20 +66,12 @@ internal sealed class InventoryUtils
if (_configuration.Armoury.DiscardFromArmouryChest) if (_configuration.Armoury.DiscardFromArmouryChest)
{ {
var gearsetItems = GetAllGearsetItems(); var gearsetItems = GetAllGearsetItems();
toDiscard.AddRange(GetArmouryItemsToDiscard(_configuration.Armoury.CheckMainHandOffHand, inventoryManager,
if (_configuration.Armoury.CheckLeftSideGear) MainHandOffHandInventoryTypes, itemCounts, gearsetItems));
{ toDiscard.AddRange(GetArmouryItemsToDiscard(_configuration.Armoury.CheckLeftSideGear, inventoryManager,
foreach (InventoryType inventoryType in LeftSideGearInventoryTypes) LeftSideGearInventoryTypes, itemCounts, gearsetItems));
toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, itemCounts, toDiscard.AddRange(GetArmouryItemsToDiscard(_configuration.Armoury.CheckRightSideGear, inventoryManager,
gearsetItems)); RightSideGearInventoryTypes, itemCounts, gearsetItems));
}
if (_configuration.Armoury.CheckRightSideGear)
{
foreach (InventoryType inventoryType in RightSideGearInventoryTypes)
toDiscard.AddRange(GetItemsToDiscard(inventoryManager, inventoryType, itemCounts,
gearsetItems));
}
} }
return toDiscard return toDiscard
@ -81,6 +79,18 @@ internal sealed class InventoryUtils
.ToList(); .ToList();
} }
private unsafe IEnumerable<ItemWrapper> GetArmouryItemsToDiscard(bool condition, InventoryManager* inventoryManager,
InventoryType[] inventoryTypes, Dictionary<uint, uint> itemCounts, List<uint>? gearsetItems)
{
if (condition)
{
foreach (InventoryType inventoryType in inventoryTypes)
return GetItemsToDiscard(inventoryManager, inventoryType, itemCounts, gearsetItems);
}
return new List<ItemWrapper>();
}
public unsafe InventoryItem* GetNextItemToDiscard(ItemFilter? itemFilter) public unsafe InventoryItem* GetNextItemToDiscard(ItemFilter? itemFilter)
{ {
List<ItemWrapper> allItemsToDiscard = GetAllItemsToDiscard(); List<ItemWrapper> allItemsToDiscard = GetAllItemsToDiscard();
@ -106,10 +116,12 @@ internal sealed class InventoryUtils
else else
itemCounts[item->ItemID] = item->Quantity; itemCounts[item->ItemID] = item->Quantity;
if (InternalConfiguration.BlacklistedItems.Contains(item->ItemID)) if (InternalConfiguration.BlacklistedItems.Contains(item->ItemID) ||
InternalConfiguration.UltimateWeapons.Contains(item->ItemID))
continue; continue;
if (!_itemCache.TryGetItem(item->ItemID, out ItemCache.CachedItemInfo? itemInfo) || !itemInfo.CanBeDiscarded()) if (!_itemCache.TryGetItem(item->ItemID, out ItemCache.CachedItemInfo? itemInfo) ||
!itemInfo.CanBeDiscarded())
continue; // no info, who knows what that item is continue; // no info, who knows what that item is
// skip gear if we're unable to load gearsets or it is used in a gearset // skip gear if we're unable to load gearsets or it is used in a gearset
@ -177,7 +189,8 @@ internal sealed class InventoryUtils
public unsafe void Discard(InventoryItem* item) public unsafe void Discard(InventoryItem* item)
{ {
if (InternalConfiguration.BlacklistedItems.Contains(item->ItemID)) if (InternalConfiguration.BlacklistedItems.Contains(item->ItemID) ||
InternalConfiguration.UltimateWeapons.Contains(item->ItemID))
throw new Exception($"Can't discard {item->ItemID}"); throw new Exception($"Can't discard {item->ItemID}");
AgentInventoryContext.Instance()->DiscardItem(item, item->Container, item->Slot, 0); AgentInventoryContext.Instance()->DiscardItem(item, item->Container, item->Slot, 0);

View File

@ -33,6 +33,11 @@ internal sealed class ItemCache
UiCategoryName = item.ItemUICategory.Value!.Name.ToString(), UiCategoryName = item.ItemUICategory.Value!.Name.ToString(),
EquipSlotCategory = item.EquipSlotCategory.Row, EquipSlotCategory = item.EquipSlotCategory.Row,
}; };
if (item is { Rarity: 3, MateriaSlotCount: 3, RowId: < 33154 or > 33358 })
{
InternalConfiguration.UltimateWeapons.Add(item.RowId);
}
} }
foreach (var shopItem in dataManager.GetExcelSheet<GilShopItem>()!) foreach (var shopItem in dataManager.GetExcelSheet<GilShopItem>()!)
@ -115,15 +120,12 @@ internal sealed class ItemCache
public bool CanBeDiscarded() public bool CanBeDiscarded()
{ {
if (InternalConfiguration.BlacklistedItems.Contains(ItemId)) if (InternalConfiguration.BlacklistedItems.Contains(ItemId) || InternalConfiguration.UltimateWeapons.Contains(ItemId))
return false; return false;
if (UiCategory is UiCategories.Currency or UiCategories.Crystals or UiCategories.Unobtainable) if (UiCategory is UiCategories.Currency or UiCategories.Crystals or UiCategories.Unobtainable)
return false; return false;
if (EquipSlotCategory is 1 or 2 or 13 or 14)
return false;
if (InternalConfiguration.WhitelistedItems.Contains(ItemId)) if (InternalConfiguration.WhitelistedItems.Contains(ItemId))
return true; return true;

View File

@ -283,6 +283,13 @@ internal sealed class ConfigWindow : LImGui.LWindow
ImGui.BeginDisabled(!discardFromArmouryChest); ImGui.BeginDisabled(!discardFromArmouryChest);
ImGui.Indent(30); ImGui.Indent(30);
bool mainHandOffHand = _configuration.Armoury.CheckMainHandOffHand;
if (ImGui.Checkbox("Discard when items are found in Main Hand/Off Hand (Weapons and Tools)", ref mainHandOffHand))
{
_configuration.Armoury.CheckMainHandOffHand = mainHandOffHand;
Save();
}
bool leftSideGear = _configuration.Armoury.CheckLeftSideGear; bool leftSideGear = _configuration.Armoury.CheckLeftSideGear;
if (ImGui.Checkbox("Discard when items are found in Head/Body/Hands/Legs/Feet", ref leftSideGear)) if (ImGui.Checkbox("Discard when items are found in Head/Body/Hands/Legs/Feet", ref leftSideGear))
{ {