4ac12ef70a
These are the formatting & linting configuration changes from the `3.8.0` branch and the changes that they make to the overall project. The majority of these changes are from running two commands: `npm run lint:fix` `npm run style:fix` This has already been run on the `3.8.0` branch and this PR should make `master` play nicer when it comes to merges going forward. There are now four VSCode plugins recommended for server development. They've been added to the workspace file and a user should get a UI notification when the workspace is opened if they're not installed. The four plugins are: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig https://marketplace.visualstudio.com/items?itemName=dprint.dprint https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint https://marketplace.visualstudio.com/items?itemName=biomejs.biome Once installed they should just work within the workspace. Also, be sure to `npm i` to get the new dprint application. Co-authored-by: Refringe <brownelltyler@gmail.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/168
108 lines
3.8 KiB
TypeScript
108 lines
3.8 KiB
TypeScript
import { inject, injectable } from "tsyringe";
|
|
|
|
import { BossLocationSpawn, ILocationBase, Wave } from "@spt-aki/models/eft/common/ILocationBase";
|
|
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
|
import { ILocationConfig } from "@spt-aki/models/spt/config/ILocationConfig";
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
|
|
import { RandomUtil } from "@spt-aki/utils/RandomUtil";
|
|
|
|
@injectable()
|
|
export class CustomLocationWaveService
|
|
{
|
|
protected locationConfig: ILocationConfig;
|
|
|
|
constructor(
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
|
@inject("RandomUtil") protected randomUtil: RandomUtil,
|
|
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
|
)
|
|
{
|
|
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)
|
|
{
|
|
const location: ILocationBase = this.databaseServer.getTables().locations[mapKey].base;
|
|
for (const bossWave of bossWavesToApply[mapKey])
|
|
{
|
|
if (location.BossLocationSpawn.find((x) => x.sptId === bossWave.sptId))
|
|
{
|
|
// Already exists, skip
|
|
continue;
|
|
}
|
|
location.BossLocationSpawn.push(bossWave);
|
|
this.logger.debug(
|
|
`Added custom boss wave to ${mapKey} of type ${bossWave.BossName}, time: ${bossWave.Time}, chance: ${bossWave.BossChance}, zone: ${bossWave.BossZone}`,
|
|
);
|
|
}
|
|
}
|
|
|
|
for (const mapKey in normalWavesToApply)
|
|
{
|
|
const location: ILocationBase = this.databaseServer.getTables().locations[mapKey].base;
|
|
for (const normalWave of normalWavesToApply[mapKey])
|
|
{
|
|
if (location.waves.find((x) => x.sptId === normalWave.sptId))
|
|
{
|
|
// Already exists, skip
|
|
continue;
|
|
}
|
|
|
|
normalWave.number = location.waves.length;
|
|
location.waves.push(normalWave);
|
|
}
|
|
}
|
|
}
|
|
}
|