2023-03-22 11:25:34 +01:00
import { inject , injectable } from "tsyringe" ;
2023-10-19 19:21:17 +02:00
import { IBotBase } from "@spt-aki/models/eft/common/tables/IBotBase" ;
import { ILogger } from "@spt-aki/models/spt/utils/ILogger" ;
import { LocalisationService } from "@spt-aki/services/LocalisationService" ;
2023-03-22 11:25:34 +01:00
2023-10-10 13:03:20 +02:00
/** Cache bots in a dictionary, keyed by the bots name, keying by name isnt ideal as its not unique but this is used by the post-raid system which doesnt have any bot ids, only name */
2023-03-22 11:25:34 +01:00
@injectable ( )
export class MatchBotDetailsCacheService
{
protected botDetailsCache : Record < string , IBotBase > = { } ;
constructor (
2023-07-19 14:16:45 +02:00
@inject ( "WinstonLogger" ) protected logger : ILogger ,
2023-11-16 22:42:06 +01:00
@inject ( "LocalisationService" ) protected localisationService : LocalisationService ,
2023-03-22 11:25:34 +01:00
)
{ }
/ * *
* Store a bot in the cache , keyed by its name
* @param botToCache Bot details to cache
* /
public cacheBot ( botToCache : IBotBase ) : void
{
2023-10-10 13:03:20 +02:00
this . botDetailsCache [ ` ${ botToCache . Info . Nickname . trim ( ) } ${ botToCache . Info . Side } ` ] = botToCache ;
2023-03-22 11:25:34 +01:00
}
/ * *
* Clean the cache of all bot details
* /
public clearCache ( ) : void
{
this . botDetailsCache = { } ;
}
/ * *
2023-10-10 13:03:20 +02:00
* Find a bot in the cache by its name and side
2023-03-22 11:25:34 +01:00
* @param botName Name of bot to find
* @returns Bot details
* /
2023-10-10 13:03:20 +02:00
public getBotByNameAndSide ( botName : string , botSide : string ) : IBotBase
2023-03-22 11:25:34 +01:00
{
2023-10-10 13:03:20 +02:00
const botInCache = this . botDetailsCache [ ` ${ botName } ${ botSide } ` ] ;
2023-03-22 11:25:34 +01:00
if ( ! botInCache )
{
2023-10-10 13:03:20 +02:00
this . logger . warning ( ` bot not found in match bot cache: ${ botName } ${ botSide } ` ) ;
2023-03-22 11:25:34 +01:00
}
return botInCache ;
}
2023-11-16 22:42:06 +01:00
}