2023-03-03 15:23:46 +00:00
import { inject , injectable } from "tsyringe" ;
2024-05-29 15:15:45 +01:00
import { BossLocationSpawn , Wave } from "@spt/models/eft/common/ILocationBase" ;
2024-05-21 17:59:04 +00:00
import { ConfigTypes } from "@spt/models/enums/ConfigTypes" ;
import { ILocationConfig } from "@spt/models/spt/config/ILocationConfig" ;
import { ILogger } from "@spt/models/spt/utils/ILogger" ;
import { ConfigServer } from "@spt/servers/ConfigServer" ;
2024-05-29 15:15:45 +01:00
import { DatabaseService } from "@spt/services/DatabaseService" ;
2024-05-21 17:59:04 +00:00
import { RandomUtil } from "@spt/utils/RandomUtil" ;
2023-03-03 15:23:46 +00:00
@injectable ( )
export class CustomLocationWaveService
{
protected locationConfig : ILocationConfig ;
constructor (
2024-05-28 14:04:20 +00:00
@inject ( "PrimaryLogger" ) protected logger : ILogger ,
2023-03-03 15:23:46 +00:00
@inject ( "RandomUtil" ) protected randomUtil : RandomUtil ,
2024-05-29 15:15:45 +01:00
@inject ( "DatabaseService" ) protected databaseService : DatabaseService ,
2023-11-15 20:35:05 -05:00
@inject ( "ConfigServer" ) protected configServer : ConfigServer ,
2023-03-03 15:23:46 +00:00
)
{
this . locationConfig = this . configServer . getConfig ( ConfigTypes . LOCATION ) ;
}
/ * *
* Add a boss wave to a map
* @param locationId e . g . factory4_day , bigmap
* @param waveToAdd Boss wave to add to map
* /
public addBossWaveToMap ( locationId : string , waveToAdd : BossLocationSpawn ) : void
{
this . locationConfig . customWaves . boss [ locationId ] . push ( waveToAdd ) ;
}
/ * *
* Add a normal bot wave to a map
* @param locationId e . g . factory4_day , bigmap
* @param waveToAdd Wave to add to map
* /
public addNormalWaveToMap ( locationId : string , waveToAdd : Wave ) : void
{
this . locationConfig . customWaves . normal [ locationId ] . push ( waveToAdd ) ;
}
/ * *
* Clear all custom boss waves from a map
* @param locationId e . g . factory4_day , bigmap
* /
public clearBossWavesForMap ( locationId : string ) : void
{
this . locationConfig . customWaves . boss [ locationId ] = [ ] ;
}
/ * *
* Clear all custom normal waves from a map
* @param locationId e . g . factory4_day , bigmap
* /
public clearNormalWavesForMap ( locationId : string ) : void
{
this . locationConfig . customWaves . normal [ locationId ] = [ ] ;
}
/ * *
* Add custom boss and normal waves to maps found in config / location . json to db
* /
public applyWaveChangesToAllMaps ( ) : void
{
const bossWavesToApply = this . locationConfig . customWaves . boss ;
const normalWavesToApply = this . locationConfig . customWaves . normal ;
for ( const mapKey in bossWavesToApply )
{
2024-05-29 15:15:45 +01:00
const locationBase = this . databaseService . getLocation ( mapKey ) . base ;
if ( ! locationBase )
2024-05-28 10:25:23 +01:00
{
this . logger . warning ( ` Unable to add custom boss wave to location: ${ mapKey } , location not found ` ) ;
continue ;
}
2023-03-03 15:23:46 +00:00
for ( const bossWave of bossWavesToApply [ mapKey ] )
{
2024-06-13 13:41:29 +01:00
if ( locationBase . BossLocationSpawn . some ( ( x ) = > x . sptId === bossWave . sptId ) )
2023-03-03 15:23:46 +00:00
{
// Already exists, skip
continue ;
}
2024-05-29 15:15:45 +01:00
locationBase . BossLocationSpawn . push ( bossWave ) ;
2023-11-15 20:35:05 -05:00
this . logger . debug (
` Added custom boss wave to ${ mapKey } of type ${ bossWave . BossName } , time: ${ bossWave . Time } , chance: ${ bossWave . BossChance } , zone: ${ bossWave . BossZone } ` ,
) ;
2023-03-03 15:23:46 +00:00
}
}
for ( const mapKey in normalWavesToApply )
{
2024-05-29 15:15:45 +01:00
const locationBase = this . databaseService . getLocation ( mapKey ) . base ;
if ( ! locationBase )
2024-05-28 10:25:23 +01:00
{
this . logger . warning ( ` Unable to add custom wave to location: ${ mapKey } , location not found ` ) ;
continue ;
}
2023-03-03 15:23:46 +00:00
for ( const normalWave of normalWavesToApply [ mapKey ] )
{
2024-06-13 13:41:29 +01:00
if ( locationBase . waves . some ( ( x ) = > x . sptId === normalWave . sptId ) )
2023-03-03 15:23:46 +00:00
{
// Already exists, skip
continue ;
}
2024-05-29 15:15:45 +01:00
normalWave . number = locationBase . waves . length ;
locationBase . waves . push ( normalWave ) ;
2023-03-03 15:23:46 +00:00
}
}
}
2023-11-15 20:35:05 -05:00
}