@@ -390,24 +390,26 @@ export class BotController {
390
390
* @param request Bot generation request object
391
391
* @returns An array of IBotBase objects as requested by request
392
392
*/
393
- protected async returnBotsFromCache (
394
- request : IGenerateBotsRequestData ,
395
- ) : Promise < IBotBase [ ] > {
393
+ protected async returnBotsFromCache ( request : IGenerateBotsRequestData ) : Promise < IBotBase [ ] > {
396
394
const desiredBots : IBotBase [ ] = [ ] ;
397
395
398
396
// We can assume that during this call, we have enough bots cached to cover the request
399
397
request . conditions . map ( ( requestedBot ) => {
400
398
// Create a compound key to store bots in cache against
401
- const cacheKey = this . botGenerationCacheService . createCacheKey (
402
- requestedBot . Role ,
403
- requestedBot . Difficulty ,
404
- ) ;
399
+ const cacheKey = this . botGenerationCacheService . createCacheKey ( requestedBot . Role , requestedBot . Difficulty ) ;
405
400
406
401
// Fetch enough bots to satisfy the request
407
- for ( let i = 0 ; i < requestedBot . Limit ; i ++ )
408
- {
402
+ for ( let i = 0 ; i < requestedBot . Limit ; i ++ ) {
403
+ // Pull bot out of generation cache
409
404
const desiredBot = this . botGenerationCacheService . getBot ( cacheKey ) ;
405
+ if ( ! desiredBot ) {
406
+ continue ;
407
+ }
408
+
409
+ // Store bot inside cache to be referenced after raid
410
410
this . botGenerationCacheService . storeUsedBot ( desiredBot ) ;
411
+
412
+ // Add bot to returned array
411
413
desiredBots . push ( desiredBot ) ;
412
414
}
413
415
} ) ;
0 commit comments