1
0
Fork 0

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

master v3.8
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,11 +106,13 @@ internal sealed class CeruleumTankWindow : ShopWindow
if (PurchaseState != null) if (PurchaseState != null)
{ {
HandleNextPurchaseStep(); HandleNextPurchaseStep();
if (PurchaseState != null)
{
ImGui.Text($"Buying {FormatStackCount(PurchaseState.ItemsLeftToBuy)}..."); ImGui.Text($"Buying {FormatStackCount(PurchaseState.ItemsLeftToBuy)}...");
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy")) if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
CancelAutoPurchase(); CancelAutoPurchase();
} }
}
else else
{ {
int toPurchase = Math.Min(GetMaxItemsToPurchase(), missingItems); int toPurchase = Math.Min(GetMaxItemsToPurchase(), missingItems);

View File

@ -101,10 +101,12 @@ internal sealed class RepairKitWindow : ShopWindow
if (PurchaseState != null) if (PurchaseState != null)
{ {
HandleNextPurchaseStep(); HandleNextPurchaseStep();
if (PurchaseState != null)
{
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy")) if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
CancelAutoPurchase(); CancelAutoPurchase();
} }
}
else else
{ {
int toPurchase = Math.Min(GetMaxItemsToPurchase(), missingItems); int toPurchase = Math.Min(GetMaxItemsToPurchase(), missingItems);

View File

@ -157,7 +157,8 @@ internal abstract class ShopWindow : LImGui.LWindow, IDisposable
if (ItemForSale == null || PurchaseState == null) if (ItemForSale == null || PurchaseState == null)
return; 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}"); _pluginLog.Warning($"No free inventory slots, can't buy more {ItemForSale.ItemName}");
PurchaseState = null; PurchaseState = null;
@ -168,7 +169,7 @@ internal abstract class ShopWindow : LImGui.LWindow, IDisposable
if (PurchaseState.NextStep <= DateTime.Now && if (PurchaseState.NextStep <= DateTime.Now &&
_gameGui.TryGetAddonByName(_addonName, out AtkUnitBase* addonShop)) _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}"); _pluginLog.Information($"Buying {buyNow}x {ItemForSale.ItemName}");
FirePurchaseCallback(addonShop, buyNow); FirePurchaseCallback(addonShop, buyNow);

View File

@ -42,7 +42,8 @@ partial class WorkshopPlugin
if (npcIds.Contains(GetNpcId(obj))) if (npcIds.Contains(GetNpcId(obj)))
{ {
o = 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) if (distance > 0.01)
return distance; return distance;
} }
@ -62,7 +63,8 @@ partial class WorkshopPlugin
private unsafe AtkUnitBase* GetCompanyCraftingLogAddon() 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 addon;
return null; return null;
@ -244,4 +246,32 @@ partial class WorkshopPlugin
return count; 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"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<Version>3.7</Version> <Version>3.8</Version>
<LangVersion>11.0</LangVersion> <LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>