Inventory Implementations

This commit is contained in:
Chomp
2025-01-20 17:59:39 +00:00
parent 3d90bfdfd8
commit d8beb5ad24
4 changed files with 55 additions and 8 deletions
@@ -482,6 +482,7 @@ public class BotInventoryGenerator(
// Does item have slots for sub-mods to be inserted into
if (pickedItemDb.Properties?.Slots?.Count > 0
&& settings?.GenerateModsBlacklist is not null
&& settings.GenerateModsBlacklist.Contains(pickedItemDb.Id))
{
var childItemsToAdd = _botEquipmentModGenerator.GenerateModsForEquipment(
+19 -6
View File
@@ -535,17 +535,30 @@ public class BotGeneratorHelper(
// Get root items in container we can iterate over to find out what space is free
var containerItemsToCheck = existingContainerItems.Where(x => x.SlotId == slotGrid.Name);
var itemsToRemove = new List<Item>();
var itemsToAdd = new List<Item>();
foreach (var item in containerItemsToCheck)
{
// Look for children on items, insert into array if found
// Check item in contain for children, store for later insertion into `containerItemsToCheck`
// (used later when figuring out how much space weapon takes up)
var itemWithChildrens = _itemHelper.FindAndReturnChildrenAsItems(inventory.Items, item.Id);
if (itemWithChildrens.Count <= 1) continue;
var itemWithChildItems = _itemHelper.FindAndReturnChildrenAsItems(inventory.Items, item.Id);
if (itemWithChildItems.Count <= 1) continue;
existingContainerItems.Remove(item);
existingContainerItems.AddRange(itemWithChildrens);
// Store replaced item + new Child items to add later as we can't modify a collecting while looking over it
itemsToRemove.Add(item);
itemsToAdd.AddRange(itemsToAdd);
}
// Remove the base items flagged above
foreach (var item in itemsToRemove)
{
existingContainerItems.Remove(item);
}
// Add item back with its child items
existingContainerItems.AddRange(itemsToAdd);
// Get rid of items free/used spots in current grid
if (slotGrid.Props is not null)
{
@@ -594,7 +607,7 @@ public class BotGeneratorHelper(
// No space in this grid, move to next container grid and try again
}
// if we got to this point, the item couldnt be placed on the container
// if we got to this point, the item couldn't be placed on the container
if (containersIdFull is null) continue;
// if the item was a one by one, we know it must be full. Or if the maps cant find a slot for a one by one
+33 -1
View File
@@ -88,7 +88,39 @@ public class ContainerHelper
int itemW,
int itemH)
{
throw new NotImplementedException();
var foundSlot = true;
for (var itemY = 0; itemY < itemH; itemY++)
{
if (foundSlot && y + itemH - 1 > containerY - 1)
{
foundSlot = false;
break;
}
// Does item fit x-ways across
for (var itemX = 0; itemX < itemW; itemX++)
{
if (foundSlot && x + itemW - 1 > containerX - 1)
{
foundSlot = false;
break;
}
if (container2D[y + itemY][x + itemX] != 0)
{
foundSlot = false;
break;
}
}
if (!foundSlot)
{
break;
}
}
return foundSlot;
}
/// <summary>
+2 -1
View File
@@ -413,7 +413,8 @@ public class InventoryHelper(
protected bool IsVertical(ItemLocation itemLocation)
{
throw new NotImplementedException();
var castValue = itemLocation.R.ToString();
return castValue == "1" || castValue == "Vertical" || itemLocation.Rotation?.ToString() == "Vertical";
}
protected InventoryItemHash GetInventoryItemHash(List<Item> inventoryItems)