0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00

Improved about 5-10% performance on botgen and fixed bug that would skip containers when generating items that wouldnt fit in pockets (!314)

Co-authored-by: clodan <clodan@clodan.com>
Reviewed-on: SPT-AKI/Server#314
This commit is contained in:
chomp 2024-04-29 13:27:07 +00:00
parent 619137417b
commit b6926c1bf9
2 changed files with 46 additions and 11 deletions

View File

@ -119,6 +119,10 @@ export class BotLootGenerator
const containersBotHasAvailable = this.getAvailableContainersBotCanStoreItemsIn(botInventory);
// This set is passed as a reference to fill up the containers that are already full, this aliviates
// generation of the bots by avoiding checking the slots of containers we already know are full
const containersIdFull = new Set<string>();
// Special items
this.addLootFromPool(
this.botLootCacheService.getLootFromCache(botRole, isPmc, LootCacheType.SPECIAL, botJsonTemplate),
@ -127,6 +131,9 @@ export class BotLootGenerator
botInventory,
botRole,
botItemLimits,
undefined,
undefined,
containersIdFull,
);
// Healing items / Meds
@ -139,6 +146,7 @@ export class BotLootGenerator
null,
0,
isPmc,
containersIdFull,
);
// Drugs
@ -151,6 +159,7 @@ export class BotLootGenerator
null,
0,
isPmc,
containersIdFull,
);
// Food
@ -163,6 +172,7 @@ export class BotLootGenerator
null,
0,
isPmc,
containersIdFull,
);
// Drink
@ -175,6 +185,7 @@ export class BotLootGenerator
null,
0,
isPmc,
containersIdFull,
);
// Currency
@ -187,6 +198,7 @@ export class BotLootGenerator
null,
0,
isPmc,
containersIdFull,
);
// Stims
@ -199,6 +211,7 @@ export class BotLootGenerator
botItemLimits,
0,
isPmc,
containersIdFull,
);
// Grenades
@ -211,6 +224,7 @@ export class BotLootGenerator
null,
0,
isPmc,
containersIdFull,
);
// Backpack - generate loot if they have one
@ -228,6 +242,7 @@ export class BotLootGenerator
botRole,
isPmc,
botLevel,
containersIdFull,
);
}
@ -240,6 +255,7 @@ export class BotLootGenerator
botItemLimits,
this.pmcConfig.maxBackpackLootTotalRub,
isPmc,
containersIdFull,
);
}
@ -256,6 +272,7 @@ export class BotLootGenerator
botItemLimits,
this.pmcConfig.maxVestLootTotalRub,
isPmc,
containersIdFull,
);
}
@ -269,6 +286,7 @@ export class BotLootGenerator
botItemLimits,
this.pmcConfig.maxPocketLootTotalRub,
isPmc,
containersIdFull,
);
// Secure
@ -281,6 +299,7 @@ export class BotLootGenerator
null,
-1,
isPmc,
containersIdFull,
);
}
@ -373,6 +392,7 @@ export class BotLootGenerator
itemSpawnLimits: IItemSpawnLimitSettings = null,
totalValueLimitRub = 0,
isPmc = false,
containersIdFull = new Set<string>(),
): void
{
// Loot pool has items
@ -465,6 +485,7 @@ export class BotLootGenerator
itemToAddTemplate._id,
itemWithChildrenToAdd,
inventoryToAddItemsTo,
containersIdFull,
);
// Handle when item cannot be added
@ -593,6 +614,7 @@ export class BotLootGenerator
botRole: string,
isPmc: boolean,
botLevel: number,
containersIdFull?: Set<string>,
): void
{
const chosenWeaponType = this.randomUtil.getArrayValue([
@ -625,6 +647,7 @@ export class BotLootGenerator
generatedWeapon.weapon[0]._tpl,
[...generatedWeapon.weapon],
botInventory,
containersIdFull,
);
if (result !== ItemAddedResult.SUCCESS)

View File

@ -532,12 +532,17 @@ export class BotGeneratorHelper
rootItemTplId: string,
itemWithChildren: Item[],
inventory: Inventory,
containersIdFull?: Set<string>,
): ItemAddedResult
{
/** Track how many containers are unable to be found */
let missingContainerCount = 0;
for (const equipmentSlotId of equipmentSlots)
{
if (containersIdFull?.has(equipmentSlotId))
{
continue;
}
// Get container to put item into
const container = inventory.items.find((item) => item.slotId === equipmentSlotId);
if (!container)
@ -583,8 +588,11 @@ export class BotGeneratorHelper
const totalSlotGridCount = containerTemplate[1]._props.Grids.length;
for (const slotGrid of containerTemplate[1]._props.Grids)
{
// Grid is empty, skip
if (slotGrid._props.cellsH === 0 || slotGrid._props.cellsV === 0)
// Grid is empty, skip or item size is bigger than grid
if (
(slotGrid._props.cellsH === 0 || slotGrid._props.cellsV === 0)
|| (itemSize[0] * itemSize[1] > slotGrid._props.cellsV * slotGrid._props.cellsH)
)
{
continue;
}
@ -592,12 +600,6 @@ export class BotGeneratorHelper
// Can't put item type in grid, skip all grids as we're assuming they have the same rules
if (!this.itemAllowedInContainer(slotGrid, rootItemTplId))
{
// 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;
}
@ -653,15 +655,25 @@ export class BotGeneratorHelper
// If we've checked all grids in container and reached this point, there's no space for item
if (currentGridCount >= totalSlotGridCount)
{
return ItemAddedResult.NO_SPACE;
break;
}
currentGridCount++;
currentGridCount++;
// 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 (containersIdFull)
{
// 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
if ((itemSize[0] === 1 && itemSize[1] === 1))
{
containersIdFull.add(equipmentSlotId);
}
}
}
return ItemAddedResult.UNKNOWN;
return ItemAddedResult.NO_SPACE;
}
/**