From 7589ece13c1d908e234fbbde42cba79fece21697 Mon Sep 17 00:00:00 2001 From: Thomas Brooks <34015422+NostraThomas99@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:21:21 -0500 Subject: [PATCH] Supermarket sweep improvments Removed max listings from search results Improved allagan tools error handling Quantities no longer go below 0 --- .idea/.idea.RebornToolbox/.idea/vcs.xml | 2 ++ .../MBShoppingList/MBShoppingList.Config.cs | 1 - .../MBShoppingList/MBShoppingList.UI.cs | 6 ------ .../Features/MBShoppingList/MBShoppingList.cs | 2 ++ .../MBShoppingList/Models/ShoppingListItem.cs | 19 +++++++++++++++---- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.idea/.idea.RebornToolbox/.idea/vcs.xml b/.idea/.idea.RebornToolbox/.idea/vcs.xml index 94a25f7..697a02f 100644 --- a/.idea/.idea.RebornToolbox/.idea/vcs.xml +++ b/.idea/.idea.RebornToolbox/.idea/vcs.xml @@ -2,5 +2,7 @@ + + \ No newline at end of file diff --git a/RebornToolbox/Features/MBShoppingList/MBShoppingList.Config.cs b/RebornToolbox/Features/MBShoppingList/MBShoppingList.Config.cs index 89ebc68..392daf7 100644 --- a/RebornToolbox/Features/MBShoppingList/MBShoppingList.Config.cs +++ b/RebornToolbox/Features/MBShoppingList/MBShoppingList.Config.cs @@ -6,7 +6,6 @@ public class MBShoppingList_Config { public bool Enabled { get; set; } = false; public RegionType ShoppingRegion { get; set; } = RegionType.NorthAmerica; - public int MaxResults { get; set; } = 100; public int LifeStreamTimeout { get; set; } = 300; public bool UseVnavPathing { get; set; } = false; public bool RemoveQuantityAutomatically { get; set; } = false; diff --git a/RebornToolbox/Features/MBShoppingList/MBShoppingList.UI.cs b/RebornToolbox/Features/MBShoppingList/MBShoppingList.UI.cs index 12df58f..79cd04c 100644 --- a/RebornToolbox/Features/MBShoppingList/MBShoppingList.UI.cs +++ b/RebornToolbox/Features/MBShoppingList/MBShoppingList.UI.cs @@ -60,12 +60,6 @@ public override void Draw() } ImGui.SetNextItemWidth(100); - int maxResults = Plugin.Configuration.ShoppingListConfig.MaxResults; - if (ImGui.InputInt("Max Search Results", ref maxResults)) - { - Plugin.Configuration.ShoppingListConfig.MaxResults = maxResults; - Plugin.Configuration.SaveConfig(); - } if (Plugin.Configuration.ExpertMode) diff --git a/RebornToolbox/Features/MBShoppingList/MBShoppingList.cs b/RebornToolbox/Features/MBShoppingList/MBShoppingList.cs index c766d2c..99e2a61 100644 --- a/RebornToolbox/Features/MBShoppingList/MBShoppingList.cs +++ b/RebornToolbox/Features/MBShoppingList/MBShoppingList.cs @@ -75,6 +75,8 @@ private void OnItemAdded((uint, InventoryItem.ItemFlags, ulong, uint) itemDetail return; wantedItem.Quantity -= itemDetails.Item4; + if (wantedItem.Quantity < 0) + wantedItem.Quantity = 0; } diff --git a/RebornToolbox/Features/MBShoppingList/Models/ShoppingListItem.cs b/RebornToolbox/Features/MBShoppingList/Models/ShoppingListItem.cs index ef9db54..61845eb 100644 --- a/RebornToolbox/Features/MBShoppingList/Models/ShoppingListItem.cs +++ b/RebornToolbox/Features/MBShoppingList/Models/ShoppingListItem.cs @@ -1,4 +1,5 @@ using System.Runtime.Serialization; +using Dalamud.Plugin.Ipc.Exceptions; using ECommons; using ECommons.DalamudServices; using FFXIVClientStructs.FFXIV.Client.Game; @@ -62,8 +63,19 @@ public long InventoryCount { if (DateTime.Now.Subtract(_inventoryLastUpdated).TotalSeconds > 1) { - _inventoryLastUpdated = DateTime.Now; - _inventoryCount = AllaganTools_IPCSubscriber.IsInitialized() ? AllaganTools_IPCSubscriber.ItemCountOwned(ItemId, !Plugin.Configuration.ShoppingListConfig.AllCharactersInventory, ValidInventoryTypes.Select(i => (uint)i).ToArray()) : 0; + try + { + _inventoryCount = AllaganTools_IPCSubscriber.IsInitialized() + ? AllaganTools_IPCSubscriber.ItemCountOwned(ItemId, + !Plugin.Configuration.ShoppingListConfig.AllCharactersInventory, + ValidInventoryTypes.Select(i => (uint)i).ToArray()) + : 0; + _inventoryLastUpdated = DateTime.Now; + } + catch (Exception ex) + { + Svc.Log.Error($"Allagan Tools IPC failed: {ex.Message}"); + } } return _inventoryCount; @@ -227,10 +239,9 @@ private async Task FetchMarketDataAsync() { using var client = new HttpClient(); - var maxResults = Plugin.Configuration.ShoppingListConfig.MaxResults; var responseString = await client .GetStringAsync( - $"https://universalis.app/api/v2/{Plugin.Configuration.ShoppingListConfig.ShoppingRegion.ToUniversalisString()}/{ItemId}?listings={maxResults}&entries={maxResults}") + $"https://universalis.app/api/v2/{Plugin.Configuration.ShoppingListConfig.ShoppingRegion.ToUniversalisString()}/{ItemId}") .ConfigureAwait(false); if (!string.IsNullOrEmpty(responseString))