mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -05:00
Improve handling of adding items to a bot container when the items type is incompatible with container
This commit is contained in:
parent
8a78e074a4
commit
18dc76ec2c
@ -352,13 +352,14 @@ export class BotLootGenerator
|
|||||||
itemsToAdd,
|
itemsToAdd,
|
||||||
inventoryToAddItemsTo,
|
inventoryToAddItemsTo,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Handle when item cannot be added
|
||||||
if (itemAddedResult !== ItemAddedResult.SUCCESS)
|
if (itemAddedResult !== ItemAddedResult.SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (itemAddedResult === ItemAddedResult.NO_CONTAINERS)
|
if (itemAddedResult === ItemAddedResult.NO_CONTAINERS)
|
||||||
{
|
{
|
||||||
// Bot has no container to put item in, exit
|
// Bot has no container to put item in, exit
|
||||||
this.logger.debug(`Unable to add ${totalItemCount} items to bot as it lacks a container to include them`);
|
this.logger.debug(`Unable to add: ${totalItemCount} items to bot as it lacks a container to include them`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,10 +372,13 @@ export class BotLootGenerator
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset loop, try again
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Reset counter
|
// Item added okay, reset counter for next item
|
||||||
fitItemIntoContainerAttempts = 0;
|
fitItemIntoContainerAttempts = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ export class BotWeaponGeneratorHelper
|
|||||||
|
|
||||||
if (result === ItemAddedResult.NO_SPACE || result === ItemAddedResult.NO_CONTAINERS)
|
if (result === ItemAddedResult.NO_SPACE || result === ItemAddedResult.NO_CONTAINERS)
|
||||||
{
|
{
|
||||||
// If there's no space for 1 stack, there's no space for the others
|
// If there's no space for 1 stack or no containers to hold item, there's no space for the others
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ export class BotWeaponGeneratorHelper
|
|||||||
missingContainerCount++;
|
missingContainerCount++;
|
||||||
if (missingContainerCount === equipmentSlots.length)
|
if (missingContainerCount === equipmentSlots.length)
|
||||||
{
|
{
|
||||||
// Bot doesnt have any containers
|
// Bot doesnt have any containers we want to add item to
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Unable to add item: ${
|
`Unable to add item: ${
|
||||||
itemWithChildren[0]._tpl
|
itemWithChildren[0]._tpl
|
||||||
@ -193,6 +193,7 @@ export class BotWeaponGeneratorHelper
|
|||||||
return ItemAddedResult.NO_CONTAINERS
|
return ItemAddedResult.NO_CONTAINERS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No container of desired type found, skip to next container type
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,8 +201,9 @@ export class BotWeaponGeneratorHelper
|
|||||||
const containerTemplate = this.itemHelper.getItem(container._tpl);
|
const containerTemplate = this.itemHelper.getItem(container._tpl);
|
||||||
if (!containerTemplate[0])
|
if (!containerTemplate[0])
|
||||||
{
|
{
|
||||||
this.logger.error(this.localisationService.getText("bot-missing_container_with_tpl", container._tpl));
|
this.logger.warning(this.localisationService.getText("bot-missing_container_with_tpl", container._tpl));
|
||||||
|
|
||||||
|
// Bad item, skip
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,10 +227,17 @@ export class BotWeaponGeneratorHelper
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't put item type in grid, skip
|
// Can't put item type in grid, skip all grids as we're assuming they have the same rules
|
||||||
if (!this.itemAllowedInContainer(slotGrid, parentTpl))
|
if (!this.itemAllowedInContainer(slotGrid, parentTpl))
|
||||||
{
|
{
|
||||||
continue;
|
// Only one possible slot and item is incompatible, exit function and inform caller
|
||||||
|
if (equipmentSlots.length === 1)
|
||||||
|
{
|
||||||
|
return ItemAddedResult.INCOMPATIBLE_ITEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiple containers, maybe next one allows item, only break out of loop for this containers grids
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all root items in backpack
|
// Get all root items in backpack
|
||||||
@ -236,7 +245,7 @@ export class BotWeaponGeneratorHelper
|
|||||||
i.parentId === container._id && i.slotId === slotGrid._name
|
i.parentId === container._id && i.slotId === slotGrid._name
|
||||||
);
|
);
|
||||||
|
|
||||||
// Get a copy of base level items we can iterate over
|
// Get root items in container we can iterate over to find out what space is free
|
||||||
const containerItemsToCheck = existingContainerItems.filter((x) => x.slotId === slotGrid._name);
|
const containerItemsToCheck = existingContainerItems.filter((x) => x.slotId === slotGrid._name);
|
||||||
for (const item of containerItemsToCheck)
|
for (const item of containerItemsToCheck)
|
||||||
{
|
{
|
||||||
@ -286,7 +295,7 @@ export class BotWeaponGeneratorHelper
|
|||||||
}
|
}
|
||||||
currentGridCount++;
|
currentGridCount++;
|
||||||
|
|
||||||
// Start loop again in next grid of container
|
// No space in this grid, move to next container grid and try again
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,34 +303,42 @@ export class BotWeaponGeneratorHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* is the provided item allowed inside a container
|
* Is the provided item allowed inside a container
|
||||||
* @param slot location item wants to be placed in
|
* @param slotGrid Items sub-grid we want to place item inside
|
||||||
* @param itemTpl item being placed
|
* @param itemTpl Item tpl being placed
|
||||||
* @returns true if allowed
|
* @returns True if allowed
|
||||||
*/
|
*/
|
||||||
protected itemAllowedInContainer(slot: Grid, itemTpl: string): boolean
|
protected itemAllowedInContainer(slotGrid: Grid, itemTpl: string): boolean
|
||||||
{
|
{
|
||||||
const filters = slot._props.filters;
|
const propFilters = slotGrid._props.filters;
|
||||||
|
const excludedFilter = propFilters[0]?.ExcludedFilter;
|
||||||
|
const filter = propFilters[0]?.Filter;
|
||||||
|
|
||||||
|
if (propFilters.length === 0)
|
||||||
|
{
|
||||||
|
// no filters, item is fine to add
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if item base type is excluded
|
// Check if item base type is excluded
|
||||||
if (filters?.length && (filters[0].ExcludedFilter || filters[0].Filter))
|
if (excludedFilter || filter)
|
||||||
{
|
{
|
||||||
const itemDetails = this.itemHelper.getItem(itemTpl)[1];
|
const itemDetails = this.itemHelper.getItem(itemTpl)[1];
|
||||||
|
|
||||||
// if item to add is found in exclude filter, not allowed
|
// if item to add is found in exclude filter, not allowed
|
||||||
if (filters[0].ExcludedFilter.includes(itemDetails._parent))
|
if (excludedFilter.includes(itemDetails._parent))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if Filter array only contains 1 filter and its for 'item', allowed
|
// If Filter array only contains 1 filter and its for basetype 'item', allow it
|
||||||
if (filters[0].Filter.length === 1 && filters[0].Filter.includes(BaseClasses.ITEM))
|
if (filter.length === 1 && filter.includes(BaseClasses.ITEM))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if allowed filter has something in it + filter doesnt have item, not allowed
|
// If allowed filter has something in it + filter doesnt have basetype 'item', not allowed
|
||||||
if (filters[0].Filter.length > 0 && !filters[0].Filter.includes(itemDetails._parent))
|
if (filter.length > 0 && !filter.includes(itemDetails._parent))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1034,6 +1034,11 @@ class ItemHelper
|
|||||||
magazineCartridgeMaxCount,
|
magazineCartridgeMaxCount,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (magazine.length > 1)
|
||||||
|
{
|
||||||
|
this.logger.warning(`Magazine ${magTemplate._name} already has cartridges defined, this may cause issues`);
|
||||||
|
}
|
||||||
|
|
||||||
// Loop over cartridge count and add stacks to magazine
|
// Loop over cartridge count and add stacks to magazine
|
||||||
let currentStoredCartridgeCount = 0;
|
let currentStoredCartridgeCount = 0;
|
||||||
let location = 0;
|
let location = 0;
|
||||||
|
@ -2,5 +2,6 @@ export enum ItemAddedResult {
|
|||||||
UNKNOWN = -1,
|
UNKNOWN = -1,
|
||||||
SUCCESS = 1,
|
SUCCESS = 1,
|
||||||
NO_SPACE = 2,
|
NO_SPACE = 2,
|
||||||
NO_CONTAINERS = 3
|
NO_CONTAINERS = 3,
|
||||||
|
INCOMPATIBLE_ITEM = 4,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user