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