Untitled

mail@pastecode.io avatar
unknown
typescript
6 months ago
3.3 kB
9
Indexable
Never
import { DependencyContainer } from "tsyringe";

import { IPostDBLoadMod } from "@spt-aki/models/external/IPostDBLoadMod";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { IWeatherConfig } from "@spt-aki/models/spt/config/IWeatherConfig";
import { LogTextColor } from "@spt-aki/models/spt/logging/LogTextColor";

class RaidTimes implements IPostDBLoadMod 
{
    private modConfig = require("../config/config.json");

    public postDBLoad(container: DependencyContainer): void 
    {
        const logger = container.resolve<ILogger>("WinstonLogger");

        if (this.modConfig.modEnabled)
        {
            logger.logWithColor("RaidTimes mod ENABLED.", LogTextColor.BLUE);

            // ---- Change Time acceleration factor ----
            
            // get the config server
            const configServer = container.resolve<ConfigServer>("ConfigServer");

            // Request weather config
            const weatherConfig = configServer.getConfig<IWeatherConfig>(ConfigTypes.WEATHER);

            logger.logWithColor("RaidTimes: Changing time acceleration to " + this.modConfig.newAcceleration + ".", LogTextColor.WHITE);
            weatherConfig.acceleration = this.modConfig.newAcceleration;

            // ---- Change EscapeTimeLimit for selected locations ----

            const locations = container.resolve<DatabaseServer>("DatabaseServer").getTables().locations;
            for (const map in locations)            
            {
                if (map !== "base")                
                {
                    switch (locations[map].base.Name) 
                    {
                        case "Customs":
                        case "Factory":
                        case "Interchange":
                        case "Laboratory":
                        case "Lighthouse":
                        case "ReserveBase":
                        case "Shoreline":
                        case "Woods":
                        case "Streets of Tarkov":
                            logger.info("RaidTimes: Extending Raid time for " + locations[map].base.Name + " from " + locations[map].base.EscapeTimeLimit + " to " + this.modConfig.newTime + " minutes.");
                            //logger.logWithColor("           exit_access_time: " + locations[map].base.exit_access_time, LogTextColor.WHITE);
                            //logger.logWithColor("           EscapeTimeLimit : " + locations[map].base.EscapeTimeLimit, LogTextColor.WHITE);
                            locations[map].base.exit_access_time = this.modConfig.newTime
                            locations[map].base.EscapeTimeLimit = this.modConfig.newTime
                            break;
                        default:
                            logger.warning("RaidTimes: Skipping: " + locations[map].base.Name);
                            break;
                    }

                }
            }
        }
        else 
        {
            logger.error("RaidTimes mod DISABLED - use RaidTimes.exe to configure.");
        }
    }
}

module.exports = { mod: new RaidTimes() }