From 30d620d3469bfd9b4cf90d7635ff55a25184f2fc Mon Sep 17 00:00:00 2001 From: Chomp Date: Sun, 22 Dec 2024 16:35:15 +0000 Subject: [PATCH] Improved simulation of AI player scavs, their 'pmc' name + game edtion is correctly passed to client Pulled pscav code out of `generateUniqueBotNickname` and into its own function `simulatePlayerScavName` --- project/src/generators/BotGenerator.ts | 15 +++++++ .../src/models/eft/common/tables/IBotBase.ts | 1 + project/src/services/BotNameService.ts | 39 +++++++++---------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/project/src/generators/BotGenerator.ts b/project/src/generators/BotGenerator.ts index 2b05edca..30876683 100644 --- a/project/src/generators/BotGenerator.ts +++ b/project/src/generators/BotGenerator.ts @@ -193,6 +193,12 @@ export class BotGenerator { this.botConfig.botRolesThatMustHaveUniqueName, ); + // Only run when generating a 'fake' playerscav, not actual player scav + if (!botGenerationDetails.isPlayerScav || this.shouldSimulatePlayerScav(botRoleLowercase)) { + this.botNameService.addRandomPmcNameToBotMainProfileNicknameProperty(bot); + this.setRandomisedGameVersionAndCategory(bot.Info); + } + if (!this.seasonalEventService.christmasEventEnabled()) { // Process all bots EXCEPT gifter, he needs christmas items if (botGenerationDetails.role !== "gifter") { @@ -273,6 +279,15 @@ export class BotGenerator { return bot; } + /** + * Should this bot have a name like "name (Pmc Name)" and be alterd by client patch to be hostile to player + * @param botRole Role bot has + * @returns True if name should be simulated pscav + */ + protected shouldSimulatePlayerScav(botRole: string): boolean { + return botRole === "assault" && this.randomUtil.getChance100(this.botConfig.chanceAssaultScavHasPlayerScavName); + } + /** * Get exp for kill by bot difficulty * @param experience Dict of difficulties and experience diff --git a/project/src/models/eft/common/tables/IBotBase.ts b/project/src/models/eft/common/tables/IBotBase.ts index 4ccb57cc..5d9bf29d 100644 --- a/project/src/models/eft/common/tables/IBotBase.ts +++ b/project/src/models/eft/common/tables/IBotBase.ts @@ -66,6 +66,7 @@ export interface IUnlockedInfo { export interface IInfo { EntryPoint: string; Nickname: string; + MainProfileNickname?: string; LowerNickname: string; Side: string; SquadInviteRestriction: boolean; diff --git a/project/src/services/BotNameService.ts b/project/src/services/BotNameService.ts index a3af1b62..5d3535b5 100644 --- a/project/src/services/BotNameService.ts +++ b/project/src/services/BotNameService.ts @@ -1,5 +1,6 @@ import { BotHelper } from "@spt/helpers/BotHelper"; import { ProfileHelper } from "@spt/helpers/ProfileHelper"; +import { IBotBase } from "@spt/models/eft/common/tables/IBotBase"; import { IBotType } from "@spt/models/eft/common/tables/IBotType"; import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; import { IBotGenerationDetails } from "@spt/models/spt/bots/BotGenerationDetails"; @@ -58,9 +59,9 @@ export class BotNameService { uniqueRoles?: string[], ): string { const isPmc = botGenerationDetails.isPmc; - const isPlayerScav = botGenerationDetails.isPlayerScav; - const simulateScavName = isPlayerScav ? false : this.shouldSimulatePlayerScavName(botRole); - const showTypeInNickname = this.botConfig.showTypeInNickname && !isPlayerScav; + + // Never show for players + const showTypeInNickname = !botGenerationDetails.isPlayerScav && this.botConfig.showTypeInNickname; const roleShouldBeUnique = uniqueRoles?.includes(botRole.toLowerCase()); let isUnique = true; @@ -72,12 +73,6 @@ export class BotNameService { : `${this.randomUtil.getArrayValue(botJsonTemplate.firstName)} ${this.randomUtil.getArrayValue(botJsonTemplate.lastName) || ""}`; name = name.trim(); - // Simulate bot looking like a player scav with the PMC name in brackets. - // E.g. "ScavName (PMC Name)" - if (simulateScavName) { - return this.addPlayerScavNameSimulationSuffix(name); - } - // Config is set to add role to end of bot name if (showTypeInNickname) { name += ` ${botRole}`; @@ -119,19 +114,23 @@ export class BotNameService { } /** - * Should this bot have a name like "name (Pmc Name)" - * @param botRole Role bot has - * @returns True if name should be simulated pscav + * Add random PMC name to bots MainProfileNickname property + * @param bot Bot to update */ - protected shouldSimulatePlayerScavName(botRole: string): boolean { - return botRole === "assault" && this.randomUtil.getChance100(this.botConfig.chanceAssaultScavHasPlayerScavName); + public addRandomPmcNameToBotMainProfileNicknameProperty(bot: IBotBase): void { + // Simulate bot looking like a player scav with the PMC name in brackets. + // E.g. "ScavName (PMC Name)" + bot.Info.MainProfileNickname = this.getRandomPMCName(); } - protected addPlayerScavNameSimulationSuffix(nickname: string): string { - const pmcNames = [ - ...this.databaseService.getBots().types.usec.firstName, - ...this.databaseService.getBots().types.bear.firstName, - ]; - return `${nickname} (${this.randomUtil.getArrayValue(pmcNames)})`; + /** + * Choose a random PMC name from bear or usec bot jsons + * @returns PMC name as string + */ + protected getRandomPMCName(): string { + const bots = this.databaseService.getBots().types; + + const pmcNames = new Set([...bots.usec.firstName, ...bots.bear.firstName]); + return this.randomUtil.getArrayValue(Array.from(pmcNames)); } }