Cache bots sent to client to spawn in raid, cleared post-raid
This commit is contained in:
parent
456220767e
commit
0fb0d0bd60
@ -314,7 +314,10 @@ export class BotController
|
||||
);
|
||||
}
|
||||
|
||||
return [this.botGenerationCacheService.getBot(cacheKey)];
|
||||
const desiredBot = this.botGenerationCacheService.getBot(cacheKey);
|
||||
this.botGenerationCacheService.storeUsedBot(desiredBot);
|
||||
|
||||
return [desiredBot];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,7 @@ import { RandomUtil } from "@spt-aki/utils/RandomUtil";
|
||||
export class BotGenerationCacheService
|
||||
{
|
||||
protected storedBots: Map<string, IBotBase[]> = new Map();
|
||||
protected activeBotsInRaid: IBotBase[] = [];
|
||||
|
||||
constructor(
|
||||
@inject("WinstonLogger") protected logger: ILogger,
|
||||
@ -64,12 +65,33 @@ export class BotGenerationCacheService
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache a bot that has been sent to the client in memory for later use post-raid to determine if player killed a traitor scav
|
||||
* @param botToStore Bot object to store
|
||||
*/
|
||||
public storeUsedBot(botToStore: IBotBase): void
|
||||
{
|
||||
this.activeBotsInRaid.push(botToStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bot by its profileId that has been generated and sent to client for current raid
|
||||
* Cache is wiped post-raid in client/match/offline/end endOfflineRaid()
|
||||
* @param profileId Id of bot to get
|
||||
* @returns IBotBase
|
||||
*/
|
||||
public getUsedBot(profileId: string): IBotBase
|
||||
{
|
||||
return this.activeBotsInRaid.find((x) => x._id === profileId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all cached bot profiles from memory
|
||||
*/
|
||||
public clearStoredBots(): void
|
||||
{
|
||||
this.storedBots = new Map();
|
||||
this.activeBotsInRaid = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user