Fix ProbabilityObjectArray.draw
returning undefined
when the pool is initially empty (!227)
It now returns an empty array if the pool is initially empty. This function does not guarantee the number of elements returned because it will break out the loop early if the pool is exhausted. Co-authored-by: qe201020335 <qe201020335@sina.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/227 Co-authored-by: qe201020335 <qe201020335@noreply.dev.sp-tarkov.com> Co-committed-by: qe201020335 <qe201020335@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
7bc867a8f7
commit
a7ae3c3c67
@ -638,7 +638,7 @@ export class LocationGenerator
|
||||
|
||||
const randomSpawnpointCount = desiredSpawnpointCount - chosenSpawnpoints.length
|
||||
// only draw random spawn points if needed
|
||||
if (randomSpawnpointCount > 0)
|
||||
if (randomSpawnpointCount > 0 && spawnpointArray.length > 0)
|
||||
{
|
||||
// Add randomly chosen spawn points
|
||||
for (const si of spawnpointArray.draw(randomSpawnpointCount, false))
|
||||
|
@ -136,6 +136,8 @@ export class ProbabilityObjectArray<K, V = undefined> extends Array<ProbabilityO
|
||||
*/
|
||||
public draw(count = 1, replacement = true, locklist: Array<K> = []): K[]
|
||||
{
|
||||
if (this.length === 0) return [];
|
||||
|
||||
const { probArray, keyArray } = this.reduce((acc, x) =>
|
||||
{
|
||||
acc.probArray.push(x.relativeProbability);
|
||||
|
Loading…
Reference in New Issue
Block a user