Fix inventory slots not being filled to 999 if no free inventory slots available

This commit is contained in:
Liza 2023-11-17 15:13:13 +01:00
parent c4a02ac2d9
commit ee2b8bae27
Signed by: liza
GPG Key ID: 7199F8D727D55F67
5 changed files with 47 additions and 12 deletions

View File

@ -106,10 +106,12 @@ internal sealed class CeruleumTankWindow : ShopWindow
if (PurchaseState != null)
{
HandleNextPurchaseStep();
ImGui.Text($"Buying {FormatStackCount(PurchaseState.ItemsLeftToBuy)}...");
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
CancelAutoPurchase();
if (PurchaseState != null)
{
ImGui.Text($"Buying {FormatStackCount(PurchaseState.ItemsLeftToBuy)}...");
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
CancelAutoPurchase();
}
}
else
{

View File

@ -101,9 +101,11 @@ internal sealed class RepairKitWindow : ShopWindow
if (PurchaseState != null)
{
HandleNextPurchaseStep();
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
CancelAutoPurchase();
if (PurchaseState != null)
{
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
CancelAutoPurchase();
}
}
else
{

View File

@ -157,7 +157,8 @@ internal abstract class ShopWindow : LImGui.LWindow, IDisposable
if (ItemForSale == null || PurchaseState == null)
return;
if (!_plugin.HasFreeInventorySlot())
int maxStackSize = _plugin.DetermineMaxStackSize(ItemForSale.ItemId);
if (maxStackSize == 0 && !_plugin.HasFreeInventorySlot())
{
_pluginLog.Warning($"No free inventory slots, can't buy more {ItemForSale.ItemName}");
PurchaseState = null;
@ -168,7 +169,7 @@ internal abstract class ShopWindow : LImGui.LWindow, IDisposable
if (PurchaseState.NextStep <= DateTime.Now &&
_gameGui.TryGetAddonByName(_addonName, out AtkUnitBase* addonShop))
{
int buyNow = Math.Min(PurchaseState.ItemsLeftToBuy, 99);
int buyNow = Math.Min(PurchaseState.ItemsLeftToBuy, maxStackSize);
_pluginLog.Information($"Buying {buyNow}x {ItemForSale.ItemName}");
FirePurchaseCallback(addonShop, buyNow);

View File

@ -42,7 +42,8 @@ partial class WorkshopPlugin
if (npcIds.Contains(GetNpcId(obj)))
{
o = obj;
float distance = Vector3.Distance(localPlayerPosition.Value, obj.Position + new Vector3(0, -2, 0));
float distance = Vector3.Distance(localPlayerPosition.Value,
obj.Position + new Vector3(0, -2, 0));
if (distance > 0.01)
return distance;
}
@ -62,7 +63,8 @@ partial class WorkshopPlugin
private unsafe AtkUnitBase* GetCompanyCraftingLogAddon()
{
if (_gameGui.TryGetAddonByName<AtkUnitBase>("CompanyCraftRecipeNoteBook", out var addon) && LAddon.IsAddonReady(addon))
if (_gameGui.TryGetAddonByName<AtkUnitBase>("CompanyCraftRecipeNoteBook", out var addon) &&
LAddon.IsAddonReady(addon))
return addon;
return null;
@ -244,4 +246,32 @@ partial class WorkshopPlugin
return count;
}
public unsafe int DetermineMaxStackSize(uint itemId)
{
var inventoryManger = InventoryManager.Instance();
if (inventoryManger == null)
return 0;
int max = 0;
for (InventoryType t = InventoryType.Inventory1; t <= InventoryType.Inventory4; ++t)
{
var container = inventoryManger->GetInventoryContainer(t);
for (int i = 0; i < container->Size; ++i)
{
var item = container->GetInventorySlot(i);
if (item == null || item->ItemID == 0)
return 99;
if (item->ItemID == itemId)
{
max += (999 - (int)item->Quantity);
if (max >= 99)
break;
}
}
}
return Math.Min(99, max);
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<Version>3.7</Version>
<Version>3.8</Version>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>