2024-09-24 11:26:45 +01:00
import { IBossLocationSpawn , IWave } 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" ;
2024-07-23 11:12:53 -04:00
import { inject , injectable } from "tsyringe" ;
2023-03-03 15:23:46 +00:00
@injectable ( )
2024-07-23 11:12:53 -04:00
export class CustomLocationWaveService {
2023-03-03 15:23:46 +00:00
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 ,
2024-07-23 11:12:53 -04:00
) {
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
* /
2024-09-24 11:26:45 +01:00
public addBossWaveToMap ( locationId : string , waveToAdd : IBossLocationSpawn ) : void {
2023-03-03 15:23:46 +00:00
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
* /
2024-09-24 11:26:45 +01:00
public addNormalWaveToMap ( locationId : string , waveToAdd : IWave ) : void {
2023-03-03 15:23:46 +00:00
this . locationConfig . customWaves . normal [ locationId ] . push ( waveToAdd ) ;
}
/ * *
* Clear all custom boss waves from a map
* @param locationId e . g . factory4_day , bigmap
* /
2024-07-23 11:12:53 -04:00
public clearBossWavesForMap ( locationId : string ) : void {
2023-03-03 15:23:46 +00:00
this . locationConfig . customWaves . boss [ locationId ] = [ ] ;
}
/ * *
* Clear all custom normal waves from a map
* @param locationId e . g . factory4_day , bigmap
* /
2024-07-23 11:12:53 -04:00
public clearNormalWavesForMap ( locationId : string ) : void {
2023-03-03 15:23:46 +00:00
this . locationConfig . customWaves . normal [ locationId ] = [ ] ;
}
/ * *
* Add custom boss and normal waves to maps found in config / location . json to db
* /
2024-07-23 11:12:53 -04:00
public applyWaveChangesToAllMaps ( ) : void {
2023-03-03 15:23:46 +00:00
const bossWavesToApply = this . locationConfig . customWaves . boss ;
const normalWavesToApply = this . locationConfig . customWaves . normal ;
2024-07-23 11:12:53 -04:00
for ( const mapKey in bossWavesToApply ) {
2024-05-29 15:15:45 +01:00
const locationBase = this . databaseService . getLocation ( mapKey ) . base ;
2024-07-23 11:12:53 -04:00
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 ;
}
2024-07-23 11:12:53 -04:00
for ( const bossWave of bossWavesToApply [ mapKey ] ) {
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
}
}
2024-07-23 11:12:53 -04:00
for ( const mapKey in normalWavesToApply ) {
2024-05-29 15:15:45 +01:00
const locationBase = this . databaseService . getLocation ( mapKey ) . base ;
2024-07-23 11:12:53 -04:00
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 ;
}
2024-07-23 11:12:53 -04:00
for ( const normalWave of normalWavesToApply [ mapKey ] ) {
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
}