From 24ab327ac203607780b20508f6543ddecfd6a94a Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 30 Sep 2024 16:55:34 +0100 Subject: [PATCH] Fixed off by one error inside `generateUniqueBotNickname` that would result in undefined names when the unique name pool was low --- project/src/services/BotNameService.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/project/src/services/BotNameService.ts b/project/src/services/BotNameService.ts index 2c289fc1..12a6d42d 100644 --- a/project/src/services/BotNameService.ts +++ b/project/src/services/BotNameService.ts @@ -60,7 +60,7 @@ export class BotNameService { let isUnique = true; let attempts = 0; - while (attempts < 5) { + while (attempts <= 5) { const isPlayerScav = botGenerationDetails.isPlayerScav; const simulateScavName = isPlayerScav ? false : this.shouldSimulatePlayerScavName(botRole); @@ -93,7 +93,11 @@ export class BotNameService { // Not unique if (attempts >= 5) { // 5 attempts to generate a name, pool probably isn't big enough - this.logger.debug(`Failed to find unique name for: ${name} after 5 attempts`); + const genericName = `${botGenerationDetails.side} ${this.randomUtil.getInt(100000, 999999)}`; + this.logger.debug( + `Failed to find unique name for: ${name} after 5 attempts, using: ${genericName}`, + ); + return genericName; } attempts++;