diff --git a/project/src/controllers/BotController.ts b/project/src/controllers/BotController.ts index 63727671..5252856e 100644 --- a/project/src/controllers/BotController.ts +++ b/project/src/controllers/BotController.ts @@ -314,7 +314,10 @@ export class BotController ); } - return [this.botGenerationCacheService.getBot(cacheKey)]; + const desiredBot = this.botGenerationCacheService.getBot(cacheKey); + this.botGenerationCacheService.storeUsedBot(desiredBot); + + return [desiredBot]; } /** diff --git a/project/src/services/BotGenerationCacheService.ts b/project/src/services/BotGenerationCacheService.ts index 4445c1c4..76486f4e 100644 --- a/project/src/services/BotGenerationCacheService.ts +++ b/project/src/services/BotGenerationCacheService.ts @@ -11,6 +11,7 @@ import { RandomUtil } from "@spt-aki/utils/RandomUtil"; export class BotGenerationCacheService { protected storedBots: Map = 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 = []; } /**