From 038f12ab6c73baebef525d0798b599e2b2363b7c Mon Sep 17 00:00:00 2001 From: Chomp Date: Wed, 20 Aug 2025 14:12:17 +0100 Subject: [PATCH] Copy improvements over to `AddItemToBotContainerFixedPosition` --- .../Services/BotInventoryContainerService.cs | 71 ++++++++----------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Services/BotInventoryContainerService.cs b/Libraries/SPTarkov.Server.Core/Services/BotInventoryContainerService.cs index 9c57ce39..67d6836c 100644 --- a/Libraries/SPTarkov.Server.Core/Services/BotInventoryContainerService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/BotInventoryContainerService.cs @@ -146,29 +146,6 @@ public class BotInventoryContainerService(ISptLogger logger, return addResult; } - /// - /// Flag a container grid as full if a 1x1 item cannot fit or there are no spaces left in the 2d array - /// - /// - /// - /// - protected static void FlagGridIfFull(ContainerMapDetails gridDetails, int itemWidth, int itemHeight) - { - // If item is 1x1 and it failed to fit, grid must be full - if (itemHeight == 1 && itemWidth == 1) - { - gridDetails.GridFull = true; // Flag now so later items can skip grid - - return; - } - - // Check if grid is full and flag - if (gridDetails.GridMap.ContainerIsFull()) - { - gridDetails.GridFull = true; - } - } - /// /// Attempt to add an item + children to a container at a specific x/y grid position /// @@ -190,15 +167,17 @@ public class BotInventoryContainerService(ISptLogger logger, ItemLocation fixedLocation ) { + if (itemAndChildren.Count == 0) + { + return ItemAddedResult.INCOMPATIBLE_ITEM; + } + // Default result var addResult = ItemAddedResult.UNKNOWN; // Find bot and the container we are attempting to store item in var botContainers = GetOrCreateBotContainerDictionary(botId); - - botContainers.TryGetValue(containerName, out var containerDetails); - - if (containerDetails.ContainerGridDetails.Count == 0) + if (!botContainers.TryGetValue(containerName, out var containerDetails) || containerDetails.ContainerGridDetails.Count == 0) { // No grids, cannot add item return ItemAddedResult.NO_CONTAINERS; @@ -278,18 +257,7 @@ public class BotInventoryContainerService(ISptLogger logger, // Didn't fit, flag as no space, hopefully next grid has space addResult = ItemAddedResult.NO_SPACE; - // If the item is 1x1 and it failed to fit, grid must be full - if (itemHeight == 1 && itemWidth == 1) - { - gridDetails.GridFull = true; - continue; - } - - // Check if grid is full and flag - if (gridDetails.GridMap.ContainerIsFull()) - { - gridDetails.GridFull = true; - } + FlagGridIfFull(gridDetails, itemWidth, itemHeight); } return addResult; @@ -319,7 +287,7 @@ public class BotInventoryContainerService(ISptLogger logger, /// The starting row index (top) /// The number of cells to update horizontally /// The number of cells to update vertically - private void FillGridRegion(int[,] grid, int x, int y, int itemWidth, int itemHeight) + protected void FillGridRegion(int[,] grid, int x, int y, int itemWidth, int itemHeight) { // Outer loop iterates through rows (from starting y position) for (var row = y; row < y + itemHeight; row++) @@ -332,6 +300,29 @@ public class BotInventoryContainerService(ISptLogger logger, } } + /// + /// Flag a container grid as full if a 1x1 item cannot fit or there are no spaces left in the 2d array + /// + /// + /// + /// + protected static void FlagGridIfFull(ContainerMapDetails gridDetails, int itemWidth, int itemHeight) + { + // If item is 1x1 and it failed to fit, grid must be full + if (itemHeight == 1 && itemWidth == 1) + { + gridDetails.GridFull = true; // Flag now so later items can skip grid + + return; + } + + // Check if grid is full and flag + if (gridDetails.GridMap.ContainerIsFull()) + { + gridDetails.GridFull = true; + } + } + /// /// Is the items subtype allowed inside this container / is it excluded from this container ///