0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-12 15:50:42 -05:00

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`
This commit is contained in:
Chomp 2024-12-22 16:35:15 +00:00
parent e04fa4d8fe
commit 30d620d346
3 changed files with 35 additions and 20 deletions

View File

@ -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

View File

@ -66,6 +66,7 @@ export interface IUnlockedInfo {
export interface IInfo {
EntryPoint: string;
Nickname: string;
MainProfileNickname?: string;
LowerNickname: string;
Side: string;
SquadInviteRestriction: boolean;

View File

@ -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));
}
}