2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 19:21:17 +02:00
|
|
|
import { BotHelper } from "@spt-aki/helpers/BotHelper";
|
|
|
|
import { Difficulty } from "@spt-aki/models/eft/common/tables/IBotType";
|
|
|
|
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
|
|
|
import { IPmcConfig } from "@spt-aki/models/spt/config/IPmcConfig";
|
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
|
|
import { LocalisationService } from "@spt-aki/services/LocalisationService";
|
|
|
|
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
|
|
|
|
import { RandomUtil } from "@spt-aki/utils/RandomUtil";
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class BotDifficultyHelper
|
|
|
|
{
|
2023-10-10 13:03:20 +02:00
|
|
|
protected pmcConfig: IPmcConfig;
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
|
|
|
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
|
|
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
|
|
|
@inject("RandomUtil") protected randomUtil: RandomUtil,
|
|
|
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
|
|
|
@inject("BotHelper") protected botHelper: BotHelper,
|
2023-11-16 02:35:05 +01:00
|
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
2023-03-03 16:23:46 +01:00
|
|
|
)
|
|
|
|
{
|
2023-10-10 13:03:20 +02:00
|
|
|
this.pmcConfig = this.configServer.getConfig(ConfigTypes.PMC);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
2023-11-16 02:35:05 +01:00
|
|
|
public getPmcDifficultySettings(
|
|
|
|
pmcType: "bear" | "usec",
|
|
|
|
difficulty: string,
|
|
|
|
usecType: string,
|
|
|
|
bearType: string,
|
|
|
|
): Difficulty
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
const difficultySettings = this.getDifficultySettings(pmcType, difficulty);
|
|
|
|
|
2023-11-16 02:35:05 +01:00
|
|
|
const friendlyType = pmcType === "bear" ? bearType : usecType;
|
|
|
|
const enemyType = pmcType === "bear" ? usecType : bearType;
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2023-10-10 13:03:20 +02:00
|
|
|
this.botHelper.addBotToEnemyList(difficultySettings, this.pmcConfig.enemyTypes, friendlyType); // Add generic bot types to enemy list
|
2023-03-03 16:23:46 +01:00
|
|
|
this.botHelper.addBotToEnemyList(difficultySettings, [enemyType, friendlyType], ""); // add same/opposite side to enemy list
|
|
|
|
|
|
|
|
this.botHelper.randomizePmcHostility(difficultySettings);
|
|
|
|
|
|
|
|
return difficultySettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get difficulty settings for desired bot type, if not found use assault bot types
|
|
|
|
* @param type bot type to retrieve difficulty of
|
|
|
|
* @param difficulty difficulty to get settings for (easy/normal etc)
|
|
|
|
* @returns Difficulty object
|
|
|
|
*/
|
|
|
|
public getBotDifficultySettings(type: string, difficulty: string): Difficulty
|
|
|
|
{
|
|
|
|
const bot = this.databaseServer.getTables().bots.types[type];
|
|
|
|
if (!bot)
|
|
|
|
{
|
|
|
|
// get fallback
|
|
|
|
this.logger.warning(this.localisationService.getText("bot-unable_to_get_bot_fallback_to_assault", type));
|
2023-11-16 02:35:05 +01:00
|
|
|
this.databaseServer.getTables().bots.types[type] = this.jsonUtil.clone(
|
|
|
|
this.databaseServer.getTables().bots.types.assault,
|
|
|
|
);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const difficultySettings = this.botHelper.getBotTemplate(type).difficulty[difficulty];
|
|
|
|
if (!difficultySettings)
|
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
this.logger.warning(
|
|
|
|
this.localisationService.getText("bot-unable_to_get_bot_difficulty_fallback_to_assault", {
|
|
|
|
botType: type,
|
|
|
|
difficulty: difficulty,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
this.databaseServer.getTables().bots.types[type].difficulty[difficulty] = this.jsonUtil.clone(
|
|
|
|
this.databaseServer.getTables().bots.types.assault.difficulty[difficulty],
|
|
|
|
);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.jsonUtil.clone(difficultySettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get difficulty settings for a PMC
|
|
|
|
* @param type "usec" / "bear"
|
2023-11-16 02:35:05 +01:00
|
|
|
* @param difficulty what difficulty to retrieve
|
2023-03-03 16:23:46 +01:00
|
|
|
* @returns Difficulty object
|
|
|
|
*/
|
|
|
|
protected getDifficultySettings(type: string, difficulty: string): Difficulty
|
|
|
|
{
|
2023-10-10 13:03:20 +02:00
|
|
|
let difficultySetting = this.pmcConfig.difficulty.toLowerCase() === "asonline"
|
2023-03-03 16:23:46 +01:00
|
|
|
? difficulty
|
2023-10-10 13:03:20 +02:00
|
|
|
: this.pmcConfig.difficulty.toLowerCase();
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
difficultySetting = this.convertBotDifficultyDropdownToBotDifficulty(difficultySetting);
|
|
|
|
|
|
|
|
return this.jsonUtil.clone(this.databaseServer.getTables().bots.types[type].difficulty[difficultySetting]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translate chosen value from pre-raid difficulty dropdown into bot difficulty value
|
|
|
|
* @param dropDownDifficulty Dropdown difficulty value to convert
|
|
|
|
* @returns bot difficulty
|
|
|
|
*/
|
|
|
|
public convertBotDifficultyDropdownToBotDifficulty(dropDownDifficulty: string): string
|
|
|
|
{
|
2023-05-18 18:23:28 +02:00
|
|
|
switch (dropDownDifficulty.toLowerCase())
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
2023-05-18 18:23:28 +02:00
|
|
|
case "medium":
|
|
|
|
return "normal";
|
|
|
|
case "random":
|
|
|
|
return this.chooseRandomDifficulty();
|
|
|
|
default:
|
|
|
|
return dropDownDifficulty.toLowerCase();
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Choose a random difficulty from - easy/normal/hard/impossible
|
|
|
|
* @returns random difficulty
|
|
|
|
*/
|
|
|
|
public chooseRandomDifficulty(): string
|
|
|
|
{
|
|
|
|
return this.randomUtil.getArrayValue(["easy", "normal", "hard", "impossible"]);
|
|
|
|
}
|
2023-11-16 02:35:05 +01:00
|
|
|
}
|