Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supermarket sweep improvements #5

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/.idea.RebornToolbox/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions RebornToolbox/Features/MBShoppingList/MBShoppingList.UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions RebornToolbox/Features/MBShoppingList/MBShoppingList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
19 changes: 15 additions & 4 deletions RebornToolbox/Features/MBShoppingList/Models/ShoppingListItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.Serialization;
using Dalamud.Plugin.Ipc.Exceptions;
using ECommons;
using ECommons.DalamudServices;
using FFXIVClientStructs.FFXIV.Client.Game;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down