Fix inventory slots not being filled to 999 if no free inventory slots available
This commit is contained in:
parent
c4a02ac2d9
commit
ee2b8bae27
@ -106,11 +106,13 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
||||
if (PurchaseState != null)
|
||||
{
|
||||
HandleNextPurchaseStep();
|
||||
|
||||
if (PurchaseState != null)
|
||||
{
|
||||
ImGui.Text($"Buying {FormatStackCount(PurchaseState.ItemsLeftToBuy)}...");
|
||||
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
|
||||
CancelAutoPurchase();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int toPurchase = Math.Min(GetMaxItemsToPurchase(), missingItems);
|
||||
|
@ -101,10 +101,12 @@ internal sealed class RepairKitWindow : ShopWindow
|
||||
if (PurchaseState != null)
|
||||
{
|
||||
HandleNextPurchaseStep();
|
||||
|
||||
if (PurchaseState != null)
|
||||
{
|
||||
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
|
||||
CancelAutoPurchase();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int toPurchase = Math.Min(GetMaxItemsToPurchase(), missingItems);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user