Check for enough inventory slots
authorLiza Carvelli <liza@carvel.li>
Mon, 5 Aug 2024 16:12:01 +0000 (18:12 +0200)
committerLiza Carvelli <liza@carvel.li>
Mon, 5 Aug 2024 16:12:01 +0000 (18:12 +0200)
Questionable/Controller/ContextMenuController.cs
Questionable/Controller/Steps/Gathering/DoGather.cs
Questionable/Controller/Steps/Gathering/DoGatherCollectable.cs
Questionable/Functions/GameFunctions.cs

index 6b3f7f9f79e9f485ed68edf4fc0ac5397a418c22..59f0d876e2fe1c3e75e53cdf4a306a91174b1df1 100644 (file)
@@ -108,6 +108,8 @@ internal sealed class ContextMenuController : IDisposable
             lockedReasonn = $"{classJob} not unlocked";
         else if (quantityToGather == 0)
             lockedReasonn = "No allowances";
+        else if (quantityToGather > _gameFunctions.GetFreeInventorySlots())
+            lockedReasonn = "Inventory full";
         else if (_gameFunctions.IsOccupied())
             lockedReasonn = "Can't be used while interacting";
 
index 71ba96b11e3e08edf9d5fc70951bee7b45699bf6..9bdf27a222d531ac202957b99ede2a021a895a1b 100644 (file)
@@ -4,12 +4,14 @@ using Dalamud.Game.ClientState.Conditions;
 using Dalamud.Plugin.Services;
 using FFXIVClientStructs.FFXIV.Component.GUI;
 using LLib.GameUI;
+using Questionable.Functions;
 using Questionable.Model.Gathering;
 
 namespace Questionable.Controller.Steps.Gathering;
 
 internal sealed class DoGather(
     GatheringController gatheringController,
+    GameFunctions gameFunctions,
     IGameGui gameGui,
     ICondition condition) : ITask
 {
@@ -33,6 +35,9 @@ internal sealed class DoGather(
         if (gatheringController.HasNodeDisappeared(_currentNode))
             return ETaskResult.TaskComplete;
 
+        if (gameFunctions.GetFreeInventorySlots() == 0)
+            throw new TaskException("Inventory full");
+
         if (condition[ConditionFlag.Gathering])
         {
             if (gameGui.TryGetAddonByName("GatheringMasterpiece", out AtkUnitBase* _))
index 36447e997f60abd0f3ee93d04a5dc87861b3a44c..63432931556533b92ab7a8be5c1d4e81ce62f58f 100644 (file)
@@ -52,6 +52,9 @@ internal sealed class DoGatherCollectable(
             }
         }
 
+        if (gameFunctions.GetFreeInventorySlots() == 0)
+            throw new TaskException("Inventory full");
+
         NodeCondition? nodeCondition = GetNodeCondition();
         if (nodeCondition == null)
             return ETaskResult.TaskComplete;
index 689c340eb0aeac09d23296492b550bb362bcf21d..2427c81dcd9d9f2edc9fc4b46152157d61cb2391 100644 (file)
@@ -477,4 +477,30 @@ internal sealed unsafe class GameFunctions
                LAddon.IsAddonReady(fade) &&
                fade->IsVisible;
     }
+
+    public int GetFreeInventorySlots()
+    {
+        InventoryManager* inventoryManager = InventoryManager.Instance();
+        if (inventoryManager == null)
+            return 0;
+
+        int slots = 0;
+        for (InventoryType inventoryType = InventoryType.Inventory1;
+             inventoryType <= InventoryType.Inventory4;
+             ++inventoryType)
+        {
+            InventoryContainer* inventoryContainer = inventoryManager->GetInventoryContainer(inventoryType);
+            if (inventoryContainer == null)
+                continue;
+
+            for (int i = 0; i < inventoryContainer->Size; ++i)
+            {
+                InventoryItem* item = inventoryContainer->GetInventorySlot(i);
+                if (item == null || item->ItemId == 0)
+                    ++slots;
+            }
+        }
+
+        return slots;
+    }
 }