From 2ae5143ad6cb0a99ded8b37f162a5f5a0950c44e Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sat, 30 Nov 2024 18:15:17 +0100 Subject: [PATCH] Show currency count for 'Allied Societies' glamour set tab --- KitchenSink/Commands/GlamourSetter.cs | 114 +++++++++++++++++--------- 1 file changed, 76 insertions(+), 38 deletions(-) diff --git a/KitchenSink/Commands/GlamourSetter.cs b/KitchenSink/Commands/GlamourSetter.cs index c93e141..8f51090 100644 --- a/KitchenSink/Commands/GlamourSetter.cs +++ b/KitchenSink/Commands/GlamourSetter.cs @@ -3,13 +3,11 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Collections.ObjectModel; using System.Linq; -using Dalamud.Game.Addon.Events; using Dalamud.Game.Addon.Lifecycle; using Dalamud.Game.Addon.Lifecycle.AddonArgTypes; using Dalamud.Game.Command; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Interface.Colors; -using Dalamud.Interface.Style; using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Windowing; using Dalamud.Plugin; @@ -28,6 +26,13 @@ internal sealed class GlamourSetter : Window, IDisposable private const uint ItemMgp = 29; private const uint ItemTrophyCrystals = 36656; + private static readonly (uint ItemId, string Name)[] AlliedSocietyCurrencies = + [ + (21074, "Vanu Whitebone"), + (21079, "Black Copper Gil"), + (21081, "Kojin Sango"), + ]; + private static readonly ImmutableHashSet MgpMakaiSets = new HashSet { // makai gear @@ -109,23 +114,25 @@ internal sealed class GlamourSetter : Window, IDisposable .Where(x => x.RowId > 0) .Select(x => x.Item.RowId) .ToHashSet(); - var specialShopItems = dataManager.GetExcelSheet() - .Where(x => x.RowId > 0 && !string.IsNullOrEmpty(x.Name.ToString())) - .SelectMany(x => x.Item.SelectMany(y => - y.ReceiveItems.Select(z => new SpecialShopItem - { - ItemId = z.Item.RowId, - CostItemId = y.ItemCosts[0].ItemCost.Value.RowId, - CostType = y.ItemCosts[0].ItemCost.Value.ItemUICategory.RowId, - CostName = y.ItemCosts[0].ItemCost.Value.Name.ToString(), - CostQuantity = y.ItemCosts[0].CurrencyCost, - }) - .Where(z => z.ItemId > 0 && (z.CostItemId < 100 || z.CostType == 100)))) - .GroupBy(x => x.ItemId) - .ToDictionary(x => x.Key, x => x.FirstOrDefault()); + var specialShopItems = BuildSpecialShopItems(dataManager); + _glamourSets = BuildGlamourSets(dataManager, armoireItems, specialShopItems); + _commandManager.AddHandler("/glamoursets", new CommandInfo(ProcessCommand) + { + HelpMessage = "Shows the glamour set tracker" + }); + _addonLifecycle.RegisterListener(AddonEvent.PostRefresh, "MiragePrismPrismBox", UpdateFromGlamourDresser); + _clientState.Logout += Reset; + + if (_clientState.IsLoggedIn) + Update(); + } + + private static ReadOnlyCollection BuildGlamourSets(IDataManager dataManager, HashSet armoireItems, + Dictionary specialShopItems) + { ExcelSheet itemSheet = dataManager.GetExcelSheet(); - _glamourSets = dataManager.GetExcelSheet() + return dataManager.GetExcelSheet() .Where(x => x.RowId > 0) .Select(x => { @@ -160,20 +167,7 @@ internal sealed class GlamourSetter : Window, IDisposable ItemId = x.RowId, Name = itemSheet.GetRow(x.RowId).Name.ToString(), Items = items, - SetType = - x.RowId == MostRecentPvpSet - ? ESetType.PvP - : UnobtainableSets.Contains(x.RowId) - ? ESetType.Unobtainable - : EternalBondingSets.Contains(x.RowId) || UndyedRathalosSets.Contains(x.RowId) || MgpMakaiSets.Contains(x.RowId) - ? ESetType.Special - : items.FirstOrDefault()?.ShopItem?.CostItemId switch - { - ItemWolfMarks or ItemTrophyCrystals => ESetType.PvP, - ItemMgp => ESetType.MGP, - > 100 => ESetType.AlliedSociety, - _ => ESetType.Default, - }, + SetType = DetermineSetType(x, items), }; }) .Where(x => x.Items.Count > 0 && x.Items.Any(y => !armoireItems.Contains(y.ItemId))) @@ -181,16 +175,49 @@ internal sealed class GlamourSetter : Window, IDisposable .ThenBy(x => x.ItemId) .ToList() .AsReadOnly(); + } - _commandManager.AddHandler("/glamoursets", new CommandInfo(ProcessCommand) + private static ESetType DetermineSetType(MirageStoreSetItem item, ReadOnlyCollection items) + { + if (item.RowId == MostRecentPvpSet) + return ESetType.PvP; + + if (UnobtainableSets.Contains(item.RowId)) + return ESetType.Unobtainable; + + if (EternalBondingSets.Contains(item.RowId) || + UndyedRathalosSets.Contains(item.RowId) || + MgpMakaiSets.Contains(item.RowId)) + return ESetType.Special; + + uint? costItemId = items.FirstOrDefault()?.ShopItem?.CostItemId; + if (AlliedSocietyCurrencies.Any(x => x.ItemId == costItemId)) + return ESetType.AlliedSociety; + + return costItemId switch { - HelpMessage = "Shows the glamour set tracker" - }); - _addonLifecycle.RegisterListener(AddonEvent.PostRefresh, "MiragePrismPrismBox", UpdateFromGlamourDresser); - _clientState.Logout += Reset; + ItemWolfMarks or ItemTrophyCrystals => ESetType.PvP, + ItemMgp => ESetType.MGP, + _ => ESetType.Default, + }; + } - if (_clientState.IsLoggedIn) - Update(); + private static Dictionary BuildSpecialShopItems(IDataManager dataManager) + { + return dataManager.GetExcelSheet() + .Where(x => x.RowId > 0 && !string.IsNullOrEmpty(x.Name.ToString())) + .SelectMany(x => x.Item.SelectMany(y => + y.ReceiveItems.Select(z => new SpecialShopItem + { + ItemId = z.Item.RowId, + CostItemId = y.ItemCosts[0].ItemCost.Value.RowId, + CostType = y.ItemCosts[0].ItemCost.Value.ItemUICategory.RowId, + CostName = y.ItemCosts[0].ItemCost.Value.Name.ToString(), + CostQuantity = y.ItemCosts[0].CurrencyCost, + }) + .Where(z => z.ItemId > 0 && (z.CostItemId < 100 || z.CostType == 100)))) + .GroupBy(x => x.ItemId) + .ToDictionary(x => x.Key, x => x.First()); } private void ProcessCommand(string command, string arguments) @@ -241,6 +268,8 @@ internal sealed class GlamourSetter : Window, IDisposable _ownedCurrencies[ItemMgp] = inventoryManager->GetItemCountInContainer(ItemMgp, InventoryType.Currency); _ownedCurrencies[ItemWolfMarks] = (int)inventoryManager->GetWolfMarks(); _ownedCurrencies[ItemTrophyCrystals] = inventoryManager->GetInventoryItemCount(ItemTrophyCrystals); + foreach (var (itemId, _) in AlliedSocietyCurrencies) + _ownedCurrencies[itemId] = inventoryManager->GetInventoryItemCount(itemId); } else _ownedCurrencies.Clear(); @@ -332,6 +361,15 @@ internal sealed class GlamourSetter : Window, IDisposable $"MGP: {_ownedCurrencies.GetValueOrDefault(ItemMgp):N0} / {missingItems.Where(x => x is { ShopItem.CostItemId: ItemMgp }).Sum(x => x.ShopItem!.CostQuantity):N0}"); ImGui.Separator(); } + else if (setType == ESetType.AlliedSociety) + { + foreach (var (itemId, name) in AlliedSocietyCurrencies) + { + ImGui.Text( + $"{name}: {_ownedCurrencies.GetValueOrDefault(itemId):N0} / {missingItems.Where(x => x is { ShopItem: { } shopItem } && shopItem.CostItemId == itemId).Sum(x => x.ShopItem!.CostQuantity):N0}"); + } + ImGui.Separator(); + } } private void DrawSetRange(List glamourSets, List ownedSets,