Ensure retainer items are cached

This commit is contained in:
Liza 2024-01-30 17:21:02 +01:00
parent 9f91da23b6
commit 0161f3df31
Signed by: liza
GPG Key ID: 7199F8D727D55F67
2 changed files with 20 additions and 1 deletions

View File

@ -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;
}

View File

@ -53,6 +53,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin
private readonly ConfigWindow _configWindow;
private readonly TurnInWindow _turnInWindow;
private readonly IReadOnlyDictionary<uint, uint> _sealCaps;
private readonly Dictionary<uint, int> _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;