From 0161f3df319d010fd53096b879f7a7a513689ddb Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Tue, 30 Jan 2024 17:21:02 +0100 Subject: [PATCH] Ensure retainer items are cached --- Deliveroo/DeliverooPlugin.GameFunctions.cs | 11 ++++++++++- Deliveroo/DeliverooPlugin.cs | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Deliveroo/DeliverooPlugin.GameFunctions.cs b/Deliveroo/DeliverooPlugin.GameFunctions.cs index 75a4c31..d8ad900 100644 --- a/Deliveroo/DeliverooPlugin.GameFunctions.cs +++ b/Deliveroo/DeliverooPlugin.GameFunctions.cs @@ -101,8 +101,17 @@ partial class DeliverooPlugin { InventoryManager* inventoryManager = InventoryManager.Instance(); int count = inventoryManager->GetInventoryItemCount(itemId, false, false, false); + if (checkRetainerInventory) - count += (int)_externalPluginHandler.GetRetainerItemCount(itemId); + { + if (!_retainerItemCache.TryGetValue(itemId, out int retainerCount)) + { + _retainerItemCache[itemId] = retainerCount = (int)_externalPluginHandler.GetRetainerItemCount(itemId); + } + + count += retainerCount; + } + return count; } diff --git a/Deliveroo/DeliverooPlugin.cs b/Deliveroo/DeliverooPlugin.cs index f72e0f4..e2abe4e 100644 --- a/Deliveroo/DeliverooPlugin.cs +++ b/Deliveroo/DeliverooPlugin.cs @@ -53,6 +53,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin private readonly ConfigWindow _configWindow; private readonly TurnInWindow _turnInWindow; private readonly IReadOnlyDictionary _sealCaps; + private readonly Dictionary _retainerItemCache = new(); private Stage _currentStageInternal = Stage.Stopped; private DateTime _continueAt = DateTime.MinValue; @@ -95,6 +96,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin _pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle; _clientState.Login += Login; _clientState.Logout += Logout; + _clientState.TerritoryChanged += TerritoryChanged; _chatGui.ChatMessage += ChatMessage; _commandManager.AddHandler("/deliveroo", new CommandInfo(ProcessCommand) { @@ -200,6 +202,13 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin private void Logout() { CharacterConfiguration = null; + _retainerItemCache.Clear(); + } + + private void TerritoryChanged(ushort territoryType) + { + // there is no GC area that is in the same zone as a retainer bell, so this should be often enough. + _retainerItemCache.Clear(); } private unsafe void FrameworkUpdate(IFramework f) @@ -348,6 +357,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin _commandManager.RemoveHandler("/deliveroo"); _chatGui.ChatMessage -= ChatMessage; + _clientState.TerritoryChanged -= TerritoryChanged; _clientState.Logout -= Logout; _clientState.Login -= Login; _pluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle;