Added system to set min level for PMCs spawned on sandbox_high to 20

This commit is contained in:
Dev 2024-04-30 21:52:26 +01:00
parent a63f1c3890
commit 297e35a1ff
4 changed files with 52 additions and 13 deletions

View File

@ -17,6 +17,7 @@ import { WildSpawnTypeNumber } from "@spt-aki/models/enums/WildSpawnTypeNumber";
import { BotGenerationDetails } from "@spt-aki/models/spt/bots/BotGenerationDetails";
import { IBotConfig } from "@spt-aki/models/spt/config/IBotConfig";
import { IPmcConfig } from "@spt-aki/models/spt/config/IPmcConfig";
import { IRaidChanges } from "@spt-aki/models/spt/location/IRaidChanges";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
@ -208,6 +209,12 @@ export class BotController
// Clear bot cache before any work starts
this.botGenerationCacheService.clearStoredBots();
const minimumPmcLevel = this.getMinimumPmcLevelForRaid(
this.applicationContext.getLatestValue(ContextVariableType.RAID_CONFIGURATION)?.getValue<
IGetRaidConfigurationRequestData
>(),
);
const allPmcsHaveSameNameAsPlayer = this.randomUtil.getChance100(
this.pmcConfig.allPMCsHavePlayerNameWithRandomPrefixChance,
);
@ -224,6 +231,7 @@ export class BotController
botRelativeLevelDeltaMin: this.pmcConfig.botRelativeLevelDeltaMin,
botCountToGenerate: this.botConfig.presetBatch[condition.Role],
botDifficulty: condition.Difficulty,
minimumPmcLevel: minimumPmcLevel,
isPlayerScav: false,
allPmcsHaveSameNameAsPlayer: allPmcsHaveSameNameAsPlayer,
};
@ -236,6 +244,21 @@ export class BotController
return [];
}
/**
* Get the lowest level a bot can be generated with
* @param raidConfig IGetRaidConfigurationRequestData from applicationContext.getLatestValue(ContextVariableType.RAID_CONFIGURATION)
* @returns Number
*/
protected getMinimumPmcLevelForRaid(raidConfig: IGetRaidConfigurationRequestData): number
{
if (raidConfig?.location.toLowerCase() === "sandbox_high")
{
return 20;
}
return 1;
}
/**
* Generate many bots and store then on the cache
* @param condition the condition details to generate the bots with
@ -315,6 +338,12 @@ export class BotController
const pmcProfile = this.profileHelper.getPmcProfile(sessionId);
const requestedBot = request.conditions[0];
const minimumPmcLevel = this.getMinimumPmcLevelForRaid(
this.applicationContext.getLatestValue(ContextVariableType.RAID_CONFIGURATION)?.getValue<
IGetRaidConfigurationRequestData
>(),
);
// Create gen request for when cache is empty
const botGenerationDetails: BotGenerationDetails = {
isPmc: false,
@ -326,6 +355,7 @@ export class BotController
botRelativeLevelDeltaMin: this.pmcConfig.botRelativeLevelDeltaMin,
botCountToGenerate: this.botConfig.presetBatch[requestedBot.Role],
botDifficulty: requestedBot.Difficulty,
minimumPmcLevel: minimumPmcLevel,
isPlayerScav: false,
};

View File

@ -86,6 +86,7 @@ export class BotGenerator
botRelativeLevelDeltaMin: 0,
botCountToGenerate: 1,
botDifficulty: difficulty,
minimumPmcLevel: 1, // unused here
isPlayerScav: true,
};

View File

@ -21,9 +21,9 @@ export class BotLevelGenerator
/**
* Return a randomised bot level and exp value
* @param levelDetails min and max of level for bot
* @param levelDetails Min and max of level for bot
* @param botGenerationDetails Deatils to help generate a bot
* @param bot being level is being generated for
* @param bot Bot the level is being generated for
* @returns IRandomisedBotLevelResult object
*/
public generateBotLevel(
@ -39,12 +39,7 @@ export class BotLevelGenerator
levelDetails,
expTable,
);
const lowestLevel = this.getLowestRelativeBotLevel(
botGenerationDetails.playerLevel,
botGenerationDetails.botRelativeLevelDeltaMin,
levelDetails,
expTable,
);
const lowestLevel = this.getLowestRelativeBotLevel(botGenerationDetails, levelDetails, expTable);
// Get random level based on the exp table.
let exp = 0;
@ -93,19 +88,30 @@ export class BotLevelGenerator
* Get the lowest level a bot can be relative to the players level, but no lower than 1
* @param playerLevel Players current level
* @param relativeDeltaMin Min delta below player level to go
* @param expTable exp table to calculate level
* @returns lowest level possible for bot
*/
protected getLowestRelativeBotLevel(
playerLevel: number,
relativeDeltaMin: number,
botGenerationDetails: BotGenerationDetails,
levelDetails: MinMax,
expTable: IExpTable[],
): number
{
// Some bots have a max level of 1
const minPossibleLevel = Math.min(levelDetails.min, expTable.length);
let minPossibleLevel: number;
if (botGenerationDetails.isPmc)
{
minPossibleLevel = Math.min(
Math.max(levelDetails.min, botGenerationDetails.minimumPmcLevel),
expTable.length,
);
}
else
{
// Some bots have a max level of 1
minPossibleLevel = Math.min(levelDetails.min, expTable.length);
}
let level = playerLevel - relativeDeltaMin;
let level = botGenerationDetails.playerLevel - botGenerationDetails.botRelativeLevelDeltaMin;
if (level < minPossibleLevel)
{
level = minPossibleLevel;

View File

@ -9,6 +9,8 @@ export interface BotGenerationDetails
/** Active players current level */
playerLevel?: number;
playerName?: string;
/** Lowest level a PMC can be generated with */
minimumPmcLevel: number;
/** Delta of highest level of bot e.g. 50 means 50 levels above player */
botRelativeLevelDeltaMax: number;
/** Delta of lowest level of bot e.g. 50 means 50 levels below player */