Reworked getBotCap() to use data from url instead of appContext

This commit is contained in:
Dev 2024-05-31 22:01:48 +01:00
parent 0864b0074b
commit f20ffe286b
3 changed files with 10 additions and 20 deletions

View File

@ -74,9 +74,11 @@ export class BotCallbacks
* Handle singleplayer/settings/bot/maxCap
* @returns string
*/
public getBotCap(): string
public getBotCap(url: string, info: any, sessionID: string): string
{
return this.httpResponse.noBody(this.botController.getBotCap());
const splitUrl = url.split("/");
const location = splitUrl[splitUrl.length - 1];
return this.httpResponse.noBody(this.botController.getBotCap(location));
}
/**

View File

@ -487,32 +487,20 @@ export class BotController
/**
* Get the max number of bots allowed on a map
* Looks up location player is entering when getting cap value
* @param location The map location cap was requested for
* @returns cap number
*/
public getBotCap(): number
public getBotCap(location: string): number
{
const defaultMapCapId = "default";
const raidConfig = this.applicationContext
.getLatestValue(ContextVariableType.RAID_CONFIGURATION)
?.getValue<IGetRaidConfigurationRequestData>();
if (!raidConfig)
{
this.logger.warning(this.localisationService.getText("bot-missing_saved_match_info"));
}
const mapName = raidConfig ? raidConfig.location : defaultMapCapId;
let botCap = this.botConfig.maxBotCap[mapName.toLowerCase()];
if (!botCap)
const botCap = this.botConfig.maxBotCap[location.toLowerCase()];
if (location === "default")
{
this.logger.warning(
this.localisationService.getText(
"bot-no_bot_cap_found_for_location",
raidConfig?.location.toLowerCase(),
location.toLowerCase(),
),
);
botCap = this.botConfig.maxBotCap[defaultMapCapId];
}
return botCap;

View File

@ -39,7 +39,7 @@ export class BotDynamicRouter extends DynamicRouter
"/singleplayer/settings/bot/maxCap",
async (url: string, info: any, sessionID: string, output: string): Promise<string> =>
{
return this.botCallbacks.getBotCap();
return this.botCallbacks.getBotCap(url, info, sessionID);
},
),
new RouteAction(