2023-03-22 11:25:34 +01:00
import { inject , injectable } from "tsyringe" ;
import { IBotBase } from "../models/eft/common/tables/IBotBase" ;
import { ILogger } from "../models/spt/utils/ILogger" ;
2023-07-19 14:16:45 +02:00
import { LocalisationService } from "./LocalisationService" ;
2023-03-22 11:25:34 +01:00
/** Cache bots in a dictionary, keyed by the bots name, keying by name isnt idea as its not unique but this is used by the post-raid system which doesnt have any bot ids, only name */
@injectable ( )
export class MatchBotDetailsCacheService
{
protected botDetailsCache : Record < string , IBotBase > = { } ;
constructor (
2023-07-19 14:16:45 +02:00
@inject ( "WinstonLogger" ) protected logger : ILogger ,
@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
{
this . botDetailsCache [ botToCache . Info . Nickname . trim ( ) ] = botToCache ;
}
/ * *
* Clean the cache of all bot details
* /
public clearCache ( ) : void
{
this . botDetailsCache = { } ;
}
/ * *
* Find a bot in the cache by its name
* @param botName Name of bot to find
* @returns Bot details
* /
public getBotByName ( botName : string ) : IBotBase
{
const botInCache = this . botDetailsCache [ botName ] ;
if ( ! botInCache )
{
2023-07-19 14:16:45 +02:00
this . logger . warning ( this . localisationService . getText ( "" , botName ) ) ;
2023-03-22 11:25:34 +01:00
}
return botInCache ;
}
}