From 7497f0d40f22af87766640b9da98287a9fe7b852 Mon Sep 17 00:00:00 2001 From: Dev Date: Sun, 7 Jul 2024 18:55:36 +0100 Subject: [PATCH] Fixed dynamic loot code choosing blacklisted items - credit to Drakia for solution --- project/src/generators/LocationLootGenerator.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/project/src/generators/LocationLootGenerator.ts b/project/src/generators/LocationLootGenerator.ts index e9fcac09..f9b17da6 100644 --- a/project/src/generators/LocationLootGenerator.ts +++ b/project/src/generators/LocationLootGenerator.ts @@ -649,6 +649,7 @@ export class LocationLootGenerator continue; } + // 100%, add it to guaranteed if (spawnpoint.probability === 1) { guaranteedLoosePoints.push(spawnpoint); @@ -663,7 +664,7 @@ export class LocationLootGenerator let chosenSpawnpoints: Spawnpoint[] = [...guaranteedLoosePoints]; const randomSpawnpointCount = desiredSpawnpointCount - chosenSpawnpoints.length; - // only draw random spawn points if needed + // Only draw random spawn points if needed if (randomSpawnpointCount > 0 && spawnpointArray.length > 0) { // Add randomly chosen spawn points @@ -696,6 +697,7 @@ export class LocationLootGenerator const seasonalItemTplBlacklist = this.seasonalEventService.getInactiveSeasonalEventItems(); for (const spawnPoint of chosenSpawnpoints) { + // Spawnpoint is invalid, skip it if (!spawnPoint.template) { this.logger.warning( @@ -709,14 +711,14 @@ export class LocationLootGenerator spawnPoint.template.Items = spawnPoint.template.Items .filter((item) => !this.itemFilterService.isLootableItemBlacklisted(item._tpl)); - // Ensure no seasonal items are in pool + // Ensure no seasonal items are in pool if not in-season if (!seasonalEventActive) { spawnPoint.template.Items = spawnPoint.template.Items .filter((item) => !seasonalItemTplBlacklist.includes(item._tpl)); } - // Has no items, useless + // Spawn point has no items after filtering, skip if (!spawnPoint.template.Items || spawnPoint.template.Items.length === 0) { this.logger.warning( @@ -726,10 +728,18 @@ export class LocationLootGenerator continue; } + // Get an array of allowed IDs after above filtering has occured + const validItemIds = spawnPoint.template.Items.map((item) => item._id); + // Construct container to hold above filtered items, letting us pick an item for the spot const itemArray = new ProbabilityObjectArray(this.mathUtil, this.cloner); for (const itemDist of spawnPoint.itemDistribution) { + if (!validItemIds.includes(itemDist.composedKey.key)) + { + continue; + } + itemArray.push(new ProbabilityObject(itemDist.composedKey.key, itemDist.relativeProbability)); }