Server/project/src/generators/BotLevelGenerator.ts
Refringe 4ac12ef70a Formatting/Linting Changes (!168)
These are the formatting & linting configuration changes from the `3.8.0` branch and the changes that they make to the overall project.

The majority of these changes are from running two commands:

`npm run lint:fix`
`npm run style:fix`

This has already been run on the `3.8.0` branch and this PR should make `master` play nicer when it comes to merges going forward.

There are now four VSCode plugins recommended for server development. They've been added to the workspace file and a user should get a UI notification when the workspace is opened if they're not installed.

The four plugins are:
https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
https://marketplace.visualstudio.com/items?itemName=dprint.dprint
https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
https://marketplace.visualstudio.com/items?itemName=biomejs.biome

Once installed they should just work within the workspace.

Also, be sure to `npm i` to get the new dprint application.

Co-authored-by: Refringe <brownelltyler@gmail.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/168
2023-11-16 21:42:06 +00:00

86 lines
2.9 KiB
TypeScript

import { inject, injectable } from "tsyringe";
import { MinMax } from "@spt-aki/models/common/MinMax";
import { IRandomisedBotLevelResult } from "@spt-aki/models/eft/bot/IRandomisedBotLevelResult";
import { IExpTable } from "@spt-aki/models/eft/common/IGlobals";
import { IBotBase } from "@spt-aki/models/eft/common/tables/IBotBase";
import { BotGenerationDetails } from "@spt-aki/models/spt/bots/BotGenerationDetails";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
import { RandomUtil } from "@spt-aki/utils/RandomUtil";
@injectable()
export class BotLevelGenerator
{
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
)
{}
/**
* Return a randomised bot level and exp value
* @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
* @returns IRandomisedBotLevelResult object
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public generateBotLevel(
levelDetails: MinMax,
botGenerationDetails: BotGenerationDetails,
bot: IBotBase,
): IRandomisedBotLevelResult
{
const expTable = this.databaseServer.getTables().globals.config.exp.level.exp_table;
const highestLevel = this.getHighestRelativeBotLevel(
botGenerationDetails.playerLevel,
botGenerationDetails.botRelativeLevelDeltaMax,
levelDetails,
expTable,
);
// Get random level based on the exp table.
let exp = 0;
const level = this.randomUtil.getInt(1, highestLevel);
for (let i = 0; i < level; i++)
{
exp += expTable[i].exp;
}
// Sprinkle in some random exp within the level, unless we are at max level.
if (level < expTable.length - 1)
{
exp += this.randomUtil.getInt(0, expTable[level].exp - 1);
}
return { level, exp };
}
/**
* Get the highest level a bot can be relative to the players level, but no futher than the max size from globals.exp_table
* @param playerLevel Players current level
* @param relativeDeltaMax max delta above player level to go
* @returns highest level possible for bot
*/
protected getHighestRelativeBotLevel(
playerLevel: number,
relativeDeltaMax: number,
levelDetails: MinMax,
expTable: IExpTable[],
): number
{
const maxPossibleLevel = Math.min(levelDetails.max, expTable.length);
let level = playerLevel + relativeDeltaMax;
if (level > maxPossibleLevel)
{
level = maxPossibleLevel;
}
return level;
}
}