Replaced ProbabilityObjectArray.Draw() with DrawAndRemove Draw

Reduced overhead when drawing a large number of elements during loot generation
This commit is contained in:
Chomp
2025-08-06 17:52:49 +01:00
parent 3f405fc67e
commit 6b297adf68
4 changed files with 86 additions and 48 deletions
@@ -460,10 +460,11 @@ public class LocationLootGenerator(
// Choose items to add to container, factor in weighting + lock money down
// Filter out items picked that are already in the above `tplsForced` array
var chosenTpls = containerLootPool
.Draw(itemCountToAdd, _locationConfig.AllowDuplicateItemsInStaticContainers, lockList)
.Where(tpl => !tplsForced.Contains(tpl))
.Where(tpl => !counterTrackerHelper.IncrementCount(tpl));
var chosenTpls = _locationConfig.AllowDuplicateItemsInStaticContainers
? containerLootPool.Draw(itemCountToAdd).Where(tpl => !tplsForced.Contains(tpl) && !counterTrackerHelper.IncrementCount(tpl))
: containerLootPool
.DrawAndRemove(itemCountToAdd, lockList)
.Where(tpl => !tplsForced.Contains(tpl) && !counterTrackerHelper.IncrementCount(tpl));
// Add forced loot to chosen item pool
var tplsToAddToContainer = tplsForced.Concat(chosenTpls);
@@ -710,9 +711,9 @@ public class LocationLootGenerator(
var randomSpawnPointCount = desiredSpawnPointCount - chosenSpawnPoints.Count;
// Only draw random spawn points if needed
if (randomSpawnPointCount > 0 && spawnPointArray.Count > 0)
// Add randomly chosen spawn points
// Add randomly chosen spawn points, remove from pool after being picked
{
foreach (var si in spawnPointArray.Draw((int)randomSpawnPointCount, false))
foreach (var si in spawnPointArray.DrawAndRemove((int)randomSpawnPointCount))
{
chosenSpawnPoints.Add(spawnPointArray.Data(si));
}