From 62bc3fe03cbea43a3ade2c8b04272433dc31c1d7 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sat, 7 Oct 2023 12:08:00 +0200 Subject: [PATCH] Fix tickets of the wrong GC messing up turn-in window, fix adding itemId 0 to your purchase list --- Deliveroo/GameData/GcRewardItem.cs | 7 ++-- Deliveroo/GameData/GcRewardsCache.cs | 58 ++++++++++++++++------------ Deliveroo/Windows/ConfigWindow.cs | 56 +++++++++++---------------- Deliveroo/Windows/TurnInWindow.cs | 37 ++++++++++++------ 4 files changed, 85 insertions(+), 73 deletions(-) diff --git a/Deliveroo/GameData/GcRewardItem.cs b/Deliveroo/GameData/GcRewardItem.cs index 588ddb4..0b918ff 100644 --- a/Deliveroo/GameData/GcRewardItem.cs +++ b/Deliveroo/GameData/GcRewardItem.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using FFXIVClientStructs.FFXIV.Client.UI.Agent; namespace Deliveroo.GameData; @@ -9,7 +10,7 @@ internal sealed class GcRewardItem : IEquatable { ItemId = 0, Name = "---", - GrandCompany = GrandCompany.None, + GrandCompanies = new List().AsReadOnly(), Tier = RewardTier.First, SubCategory = RewardSubCategory.Unknown, RequiredRank = 0, @@ -19,14 +20,14 @@ internal sealed class GcRewardItem : IEquatable public required uint ItemId { get; init; } public required string Name { get; init; } - public required GrandCompany GrandCompany { get; init; } + public required IReadOnlyList GrandCompanies { get; init; } public required RewardTier Tier { get; init; } public required RewardSubCategory SubCategory { get; init; } public required uint RequiredRank { get; init; } public required uint StackSize { get; init; } public required uint SealCost { get; init; } - public bool IsValid() => ItemId > 0 && GrandCompany != GrandCompany.None; + public bool IsValid() => ItemId > 0 && GrandCompanies.Count > 0; public bool Equals(GcRewardItem? other) { diff --git a/Deliveroo/GameData/GcRewardsCache.cs b/Deliveroo/GameData/GcRewardsCache.cs index 714be45..1755fc4 100644 --- a/Deliveroo/GameData/GcRewardsCache.cs +++ b/Deliveroo/GameData/GcRewardsCache.cs @@ -18,34 +18,42 @@ internal sealed class GcRewardsCache Tier: (RewardTier)x.Tier, SubCategory: (RewardSubCategory)x.SubCategory)); - var items = dataManager.GetExcelSheet()! + Rewards = dataManager.GetExcelSheet()! .Where(x => x.RowId > 0 && x.Item.Row > 0) - .ToList(); - - foreach (var item in items) - { - var category = categories[item.RowId]; - Rewards[category.GrandCompany].Add(new GcRewardItem + .GroupBy(item => { - ItemId = item.Item.Row, - Name = item.Item.Value!.Name.ToString(), - GrandCompany = category.GrandCompany, - Tier = category.Tier, - SubCategory = category.SubCategory, - RequiredRank = item.RequiredGrandCompanyRank.Row, - StackSize = item.Item!.Value.StackSize, - SealCost = item.CostGCSeals, - }); - } + var category = categories[item.RowId]; + return new + { + ItemId = item.Item.Row, + Name = item.Item.Value!.Name.ToString(), + category.Tier, + category.SubCategory, + RequiredRank = item.RequiredGrandCompanyRank.Row, + item.Item!.Value.StackSize, + SealCost = item.CostGCSeals, + }; + }) + .Select(item => new GcRewardItem + { + ItemId = item.Key.ItemId, + Name = item.Key.Name, + Tier = item.Key.Tier, + SubCategory = item.Key.SubCategory, + RequiredRank = item.Key.RequiredRank, + StackSize = item.Key.StackSize, + SealCost = item.Key.SealCost, + GrandCompanies = item.Select(x => categories[x.RowId].GrandCompany) + .ToList() + .AsReadOnly(), + }) + .ToList() + .AsReadOnly(); + RewardLookup = Rewards.ToDictionary(x => x.ItemId).AsReadOnly(); } - public Dictionary> Rewards { get; } = new() - { - { GrandCompany.Maelstrom, new() }, - { GrandCompany.TwinAdder, new() }, - { GrandCompany.ImmortalFlames, new() } - }; + public IReadOnlyList Rewards { get; } + public IReadOnlyDictionary RewardLookup { get; } - public GcRewardItem GetReward(GrandCompany grandCompany, uint itemId) - => Rewards[grandCompany].Single(x => x.ItemId == itemId); + public GcRewardItem GetReward(uint itemId) => RewardLookup[itemId]; } diff --git a/Deliveroo/Windows/ConfigWindow.cs b/Deliveroo/Windows/ConfigWindow.cs index dd729c4..a0b9167 100644 --- a/Deliveroo/Windows/ConfigWindow.cs +++ b/Deliveroo/Windows/ConfigWindow.cs @@ -23,8 +23,8 @@ internal sealed class ConfigWindow : Window private readonly IClientState _clientState; private readonly IPluginLog _pluginLog; - private readonly Dictionary _itemLookup; - private uint _dragDropSource = 0; + private readonly IReadOnlyDictionary _itemLookup; + private uint _dragDropSource; public ConfigWindow(DalamudPluginInterface pluginInterface, DeliverooPlugin plugin, Configuration configuration, GcRewardsCache gcRewardsCache, IClientState clientState, IPluginLog pluginLog) @@ -37,10 +37,7 @@ internal sealed class ConfigWindow : Window _clientState = clientState; _pluginLog = pluginLog; - _itemLookup = _gcRewardsCache.Rewards.Values - .SelectMany(x => x) - .Distinct() - .ToDictionary(x => x.ItemId, x => x); + _itemLookup = _gcRewardsCache.RewardLookup; Size = new Vector2(420, 300); SizeCondition = ImGuiCond.Appearing; @@ -136,33 +133,22 @@ internal sealed class ConfigWindow : Window Save(); } - if (_plugin.GetGrandCompany() != GrandCompany.None) - { - List<(uint ItemId, string Name)> comboValues = _gcRewardsCache.Rewards[_plugin.GetGrandCompany()] - .Where(x => x.SubCategory == RewardSubCategory.Materials || - x.SubCategory == RewardSubCategory.Materiel) - .Where(x => x.StackSize > 1) - .Where(x => !_configuration.ItemsAvailableForPurchase.Contains(x.ItemId)) - .Select(x => (x.ItemId, x.Name)) - .OrderBy(x => x.Name) - .ThenBy(x => x.GetHashCode()) - .ToList(); - comboValues.Insert(0, (0, "")); + List<(uint ItemId, string Name)> comboValues = _gcRewardsCache.Rewards + .Where(x => x.SubCategory is RewardSubCategory.Materials or RewardSubCategory.Materiel) + .Where(x => x.StackSize > 1) + .Where(x => !_configuration.ItemsAvailableForPurchase.Contains(x.ItemId)) + .Select(x => (x.ItemId, x.Name)) + .OrderBy(x => x.Name) + .ThenBy(x => x.GetHashCode()) + .ToList(); + comboValues.Insert(0, (0, "")); - int currentItem = 0; - if (ImGui.Combo("Add Item", ref currentItem, comboValues.Select(x => x.Name).ToArray(), - comboValues.Count)) - { - _configuration.ItemsAvailableForPurchase.Add(comboValues[currentItem].ItemId); - Save(); - } - } - else + int currentItem = 0; + if (ImGui.Combo("Add Item", ref currentItem, comboValues.Select(x => x.Name).ToArray(), comboValues.Count) + && comboValues[currentItem].ItemId != GcRewardItem.None.ItemId) { - ImGui.BeginDisabled(); - int currentItem = 0; - ImGui.Combo("Add Item", ref currentItem, new[] { "(Not part of a GC)" }, 1); - ImGui.EndDisabled(); + _configuration.ItemsAvailableForPurchase.Add(comboValues[currentItem].ItemId); + Save(); } ImGui.EndTabItem(); @@ -185,7 +171,6 @@ internal sealed class ConfigWindow : Window var charConfiguration = _plugin.CharacterConfiguration; if (charConfiguration != null) { - bool disableForCharacter = charConfiguration.DisableForCharacter; if (ImGui.Checkbox("Disable plugin for this character", ref disableForCharacter)) { @@ -203,7 +188,8 @@ internal sealed class ConfigWindow : Window } if (charConfiguration.ItemsToPurchase.Count > 1 || - (charConfiguration.ItemsToPurchase.Count == 1 && charConfiguration.ItemsToPurchase[0].ItemId != GcRewardItem.None.ItemId)) + (charConfiguration.ItemsToPurchase.Count == 1 && + charConfiguration.ItemsToPurchase[0].ItemId != GcRewardItem.None.ItemId)) { ImGui.SameLine(); if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Trash, "Clear")) @@ -219,8 +205,10 @@ internal sealed class ConfigWindow : Window charConfiguration.UseHideArmouryChestItemsFilter = useHideArmouryChestItemsFilter; charConfiguration.Save(_pluginInterface); } + if (ImGui.IsItemHovered()) - ImGui.SetTooltip("The default filter for all characters is 'Hide Gear Set Items', but you may want to override this to hide all Armoury Chest items (regardless of whether they're part of a gear set) e.g. for your main character."); + ImGui.SetTooltip( + "The default filter for all characters is 'Hide Gear Set Items', but you may want to override this to hide all Armoury Chest items (regardless of whether they're part of a gear set) e.g. for your main character."); ImGui.EndDisabled(); ImGui.Spacing(); diff --git a/Deliveroo/Windows/TurnInWindow.cs b/Deliveroo/Windows/TurnInWindow.cs index cb6f4ef..3deb53c 100644 --- a/Deliveroo/Windows/TurnInWindow.cs +++ b/Deliveroo/Windows/TurnInWindow.cs @@ -50,7 +50,8 @@ internal sealed class TurnInWindow : Window public decimal Multiplier { private get; set; } public string Error { private get; set; } = string.Empty; - private bool UseCharacterSpecificItemsToPurchase => _plugin.CharacterConfiguration is {OverrideItemsToPurchase: true }; + private bool UseCharacterSpecificItemsToPurchase => + _plugin.CharacterConfiguration is { OverrideItemsToPurchase: true }; private IItemsToPurchase ItemsWrapper => UseCharacterSpecificItemsToPurchase ? new CharacterSpecificItemsToPurchase(_plugin.CharacterConfiguration!, _pluginInterface) @@ -67,7 +68,8 @@ internal sealed class TurnInWindow : Window var rank = _plugin.GetGrandCompanyRank(); return ItemsWrapper.GetItemsToPurchase() .Where(x => x.ItemId != 0) - .Select(x => new { Item = x, Reward = _gcRewardsCache.GetReward(grandCompany, x.ItemId) }) + .Select(x => new { Item = x, Reward = _gcRewardsCache.GetReward(x.ItemId) }) + .Where(x => x.Reward.GrandCompanies.Contains(grandCompany)) .Where(x => x.Reward.RequiredRank <= rank) .Select(x => new PurchaseItemRequest { @@ -147,16 +149,18 @@ internal sealed class TurnInWindow : Window var itemsWrapper = ItemsWrapper; ImGui.Text($"Items to buy ({itemsWrapper.Name}):"); - List<(uint ItemId, string Name, uint Rank)> comboValues = new() - { (GcRewardItem.None.ItemId, GcRewardItem.None.Name, GcRewardItem.None.RequiredRank) }; + List<(uint ItemId, string Name, IReadOnlyList GrandCompanies, uint Rank)> comboValues = new() + { + (GcRewardItem.None.ItemId, GcRewardItem.None.Name, new List(), GcRewardItem.None.RequiredRank) + }; foreach (uint itemId in _configuration.ItemsAvailableForPurchase) { - var gcReward = _gcRewardsCache.GetReward(grandCompany, itemId); + var gcReward = _gcRewardsCache.GetReward(itemId); int itemCount = _plugin.GetItemCount(itemId); string itemName = gcReward.Name; if (itemCount > 0) itemName += $" ({itemCount:N0})"; - comboValues.Add((itemId, itemName, gcReward.RequiredRank)); + comboValues.Add((itemId, itemName, gcReward.GrandCompanies, gcReward.RequiredRank)); } if (itemsWrapper.GetItemsToPurchase().Count == 0) @@ -216,10 +220,19 @@ internal sealed class TurnInWindow : Window itemsWrapper.Save(); } - if (comboValueIndex > 0 && comboValues[comboValueIndex].Rank > _plugin.GetGrandCompanyRank()) + if (comboValueIndex > 0) { - ImGui.TextColored(ImGuiColors.DalamudRed, - "This item will be skipped, your rank isn't high enough to buy it."); + var comboItem = comboValues[comboValueIndex]; + if (!comboItem.GrandCompanies.Contains(grandCompany)) + { + ImGui.TextColored(ImGuiColors.DalamudRed, + "This item will be skipped, as you are in the wrong Grand Company."); + } + else if (comboItem.Rank > _plugin.GetGrandCompanyRank()) + { + ImGui.TextColored(ImGuiColors.DalamudRed, + "This item will be skipped, your rank isn't high enough to buy it."); + } } ImGui.Unindent(27); @@ -232,7 +245,8 @@ internal sealed class TurnInWindow : Window itemsWrapper.Save(); } - if (_configuration.ItemsAvailableForPurchase.Any(x => itemsWrapper.GetItemsToPurchase().All(y => x != y.ItemId))) + if (_configuration.ItemsAvailableForPurchase.Any(x => + itemsWrapper.GetItemsToPurchase().All(y => x != y.ItemId))) { if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Plus, "Add Item")) { @@ -284,7 +298,8 @@ internal sealed class TurnInWindow : Window private readonly CharacterConfiguration _characterConfiguration; private readonly DalamudPluginInterface _pluginInterface; - public CharacterSpecificItemsToPurchase(CharacterConfiguration characterConfiguration, DalamudPluginInterface pluginInterface) + public CharacterSpecificItemsToPurchase(CharacterConfiguration characterConfiguration, + DalamudPluginInterface pluginInterface) { _characterConfiguration = characterConfiguration; _pluginInterface = pluginInterface;