diff --git a/Deliveroo/Deliveroo.csproj b/Deliveroo/Deliveroo.csproj index 1b63539..461d967 100644 --- a/Deliveroo/Deliveroo.csproj +++ b/Deliveroo/Deliveroo.csproj @@ -1,7 +1,7 @@ net7.0-windows - 2.24 + 2.25 11.0 enable true diff --git a/Deliveroo/DeliverooPlugin.Supply.cs b/Deliveroo/DeliverooPlugin.Supply.cs index 5fd19b5..bd80862 100644 --- a/Deliveroo/DeliverooPlugin.Supply.cs +++ b/Deliveroo/DeliverooPlugin.Supply.cs @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; +using System.Linq; using Dalamud.Game.ClientState.Objects.Types; +using Dalamud.Game.Text.SeStringHandling; using Deliveroo.GameData; using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Component.GUI; using LLib.GameUI; +using Lumina.Text.Payloads; using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType; namespace Deliveroo; @@ -78,7 +81,8 @@ partial class DeliverooPlugin return; var addonGc = (AddonGrandCompanySupplyList*)addon; - if (addonGc->ExpertDeliveryList == null || !addonGc->ExpertDeliveryList->AtkComponentBase.OwnerNode->AtkResNode.IsVisible) + if (addonGc->ExpertDeliveryList == null || + !addonGc->ExpertDeliveryList->AtkComponentBase.OwnerNode->AtkResNode.IsVisible) return; if (addonGc->SelectedTab != 2) @@ -98,7 +102,8 @@ partial class DeliverooPlugin int currentListSize = addonGc->ExpertDeliveryList->ListLength; if (addonGc->ListEmptyTextNode->AtkResNode.IsVisible || currentListSize == 0) { - _pluginLog.Information($"No items to turn in ({addonGc->ListEmptyTextNode->AtkResNode.IsVisible}, {currentListSize})"); + _pluginLog.Information( + $"No items to turn in ({addonGc->ListEmptyTextNode->AtkResNode.IsVisible}, {currentListSize})"); CurrentStage = Stage.CloseGcSupplyThenStop; addon->FireCallbackInt(-1); return; @@ -115,7 +120,8 @@ partial class DeliverooPlugin if (currentListSize >= _lastTurnInListSize) { _turnInErrors++; - _pluginLog.Information($"Trying to refresh expert delivery list manually ({_turnInErrors}, old list size = {_lastTurnInListSize}, new list size = {currentListSize})..."); + _pluginLog.Information( + $"Trying to refresh expert delivery list manually ({_turnInErrors}, old list size = {_lastTurnInListSize}, new list size = {currentListSize})..."); addon->FireCallbackInt(2); _continueAt = DateTime.Now.AddSeconds(0.1); @@ -176,7 +182,20 @@ partial class DeliverooPlugin if (_gameGui.TryGetAddonByName("GrandCompanySupplyReward", out var addonSupplyReward) && LAddon.IsAddonReady(&addonSupplyReward->AtkUnitBase)) { - _pluginLog.Information($"Turning in '{addonSupplyReward->AtkUnitBase.AtkValues[4].ReadAtkString()}'"); + string? itemName = addonSupplyReward->AtkUnitBase.AtkValues[4].ReadAtkString(); + if (itemName != null && _itemCache.GetItemIdFromItemName(itemName) + .Any(itemId => DisabledTurnInItems.Contains(itemId))) + { + _chatGui.Print(new SeStringBuilder().Append("Won't turn in ") + .AddItemLink(_itemCache.GetItemIdFromItemName(itemName).First()) + .Append(".") + .Build()); + + addonSupplyReward->AtkUnitBase.FireCallbackInt(1); + return; + } + + _pluginLog.Information($"Turning in '{itemName}'"); addonSupplyReward->AtkUnitBase.FireCallbackInt(0); _continueAt = DateTime.Now.AddSeconds(0.58); diff --git a/Deliveroo/DeliverooPlugin.cs b/Deliveroo/DeliverooPlugin.cs index f133b5f..f72e0f4 100644 --- a/Deliveroo/DeliverooPlugin.cs +++ b/Deliveroo/DeliverooPlugin.cs @@ -25,6 +25,7 @@ namespace Deliveroo; public sealed partial class DeliverooPlugin : IDalamudPlugin { private readonly WindowSystem _windowSystem = new(typeof(DeliverooPlugin).AssemblyQualifiedName); + private readonly IReadOnlyList DisabledTurnInItems = new List { 2820 }.AsReadOnly(); private readonly DalamudPluginInterface _pluginInterface; private readonly IChatGui _chatGui; @@ -48,6 +49,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin private readonly GcRewardsCache _gcRewardsCache; private readonly IconCache _iconCache; + private readonly ItemCache _itemCache; private readonly ConfigWindow _configWindow; private readonly TurnInWindow _turnInWindow; private readonly IReadOnlyDictionary _sealCaps; @@ -80,6 +82,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin _configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration(); _gcRewardsCache = new GcRewardsCache(dataManager); _iconCache = new IconCache(textureProvider); + _itemCache = new ItemCache(dataManager); _configWindow = new ConfigWindow(_pluginInterface, this, _configuration, _gcRewardsCache, _clientState, _pluginLog, _iconCache); _windowSystem.AddWindow(_configWindow); _turnInWindow = new TurnInWindow(this, _pluginInterface, _configuration, _condition, _clientState, _gcRewardsCache, _configWindow, _iconCache); diff --git a/Deliveroo/GameData/ItemCache.cs b/Deliveroo/GameData/ItemCache.cs new file mode 100644 index 0000000..32fff06 --- /dev/null +++ b/Deliveroo/GameData/ItemCache.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using Dalamud.Plugin.Services; +using Lumina.Excel.GeneratedSheets; + +namespace Deliveroo.GameData; + +internal class ItemCache +{ + private readonly Dictionary> _itemNamesToIds = new(); + + public ItemCache(IDataManager dataManager) + { + foreach (var item in dataManager.GetExcelSheet()!) + { + string name = item.Name.ToString(); + if (string.IsNullOrWhiteSpace(name)) + continue; + + if (_itemNamesToIds.TryGetValue(name, out HashSet? itemIds)) + itemIds.Add(item.RowId); + else + _itemNamesToIds.Add(name, new HashSet{item.RowId}); + } + } + + public HashSet GetItemIdFromItemName(string name) => _itemNamesToIds[name]; +}