Refactor of how bot loot has its position picked to improve performance (#548)

* Initial work on moving container space checks into new class

* Updated tests

Wired up service to save item into inventory when space is found

Updated `FillContainerMapWithItem` to return outcome and not throw exception on failure

Add containers to bot when generating bot equipment

Clean bot cache after completion of loot generation

Removed redundant code from `AddItemWithChildrenToEquipmentSlot`

Removed unnecessary Singleton status from `BotInventoryContainerService`

* Clean-up of service

* Add botId xml docs

* Updated documentation for `FillContainerMapWithItem`

* Code review fixes and improvements

* Remove TODO

---------

Co-authored-by: Chomp <dev@dev.sp-tarkov.com>
This commit is contained in:
Chomp
2025-08-13 15:35:57 +00:00
committed by GitHub
parent 965d503021
commit b061200803
17 changed files with 719 additions and 314 deletions
@@ -24,7 +24,7 @@ public static class ContainerExtensions
var limitX = containerX - minVolume;
// Every x+y slot taken up in container, exit
if (ContainerIsFull(container2D))
if (container2D.ContainerIsFull())
{
return new FindSlotResult(false);
}
@@ -84,7 +84,8 @@ public static class ContainerExtensions
/// <param name="itemXWidth">Items width</param>
/// <param name="itemYHeight">Items height</param>
/// <param name="isRotated">is item rotated</param>
public static void FillContainerMapWithItem(
/// <returns>bool = true when successful, string = error message if failed</returns>
public static (bool, string) FillContainerMapWithItem(
this int[,] container2D,
int columnStartPositionX,
int rowStartPositionY,
@@ -108,7 +109,7 @@ public static class ContainerExtensions
{
container2D[rowStartPositionY, columnStartPositionX] = 1;
return;
return (true, string.Empty);
}
// Loop over rows and columns and flag each as taken by item
@@ -123,12 +124,15 @@ public static class ContainerExtensions
}
else
{
throw new Exception(
return (
false,
$"Slot at: ({containerX}, {containerY}) is already filled. Cannot fit: {itemXWidth} by {itemYHeight} item"
);
}
}
}
return (true, string.Empty);
}
/// <summary>
@@ -158,7 +162,7 @@ public static class ContainerExtensions
/// </summary>
/// <param name="container2D">Container to check</param>
/// <returns>True = full</returns>
private static bool ContainerIsFull(int[,] container2D)
public static bool ContainerIsFull(this int[,] container2D)
{
var containerY = container2D.GetLength(0); // rows
var containerX = container2D.GetLength(1); // columns