From a1d82af41f46e0459c35481b5191b9f6f84c3d68 Mon Sep 17 00:00:00 2001 From: qe201020335 Date: Thu, 15 Feb 2024 09:09:35 +0000 Subject: [PATCH] Fix dynamic loot generation not respecting spawn point's `IsAlwaysSpawn` field (!226) A similar field can also be seen in static container generation which the value is respected Also Limited the amount of random draws to avoid going over the `desiredSpawnpointCount` - Consider a potential mod that changes every spawn point's `IsAlwaysSpawn` to true, then there is absolute no point for the generator to draw them again and only to have them removed during dedupe Co-authored-by: qe201020335 Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/226 Co-authored-by: qe201020335 Co-committed-by: qe201020335 --- project/src/generators/LocationGenerator.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/project/src/generators/LocationGenerator.ts b/project/src/generators/LocationGenerator.ts index 273764c2..7673e8a3 100644 --- a/project/src/generators/LocationGenerator.ts +++ b/project/src/generators/LocationGenerator.ts @@ -623,7 +623,7 @@ export class LocationGenerator continue; } - if (spawnpoint.probability === 1) + if (spawnpoint.probability === 1 || spawnpoint.template.IsAlwaysSpawn) { guaranteedLoosePoints.push(spawnpoint); continue; @@ -636,10 +636,15 @@ export class LocationGenerator // Add ALL loose loot with 100% chance to pool let chosenSpawnpoints: Spawnpoint[] = [...guaranteedLoosePoints]; - // Add randomly chosen spawn points - for (const si of spawnpointArray.draw(desiredSpawnpointCount, false)) + const randomSpawnpointCount = desiredSpawnpointCount - chosenSpawnpoints.length + // only draw random spawn points if needed + if (randomSpawnpointCount > 0) { - chosenSpawnpoints.push(spawnpointArray.data(si)); + // Add randomly chosen spawn points + for (const si of spawnpointArray.draw(randomSpawnpointCount, false)) + { + chosenSpawnpoints.push(spawnpointArray.data(si)); + } } // Filter out duplicate locationIds