2024-05-28 11:13:27 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
import { IGlobals } from "@spt/models/eft/common/IGlobals";
|
2024-05-28 14:28:26 +01:00
|
|
|
import { ILocation } from "@spt/models/eft/common/ILocation";
|
2024-05-28 12:27:46 +01:00
|
|
|
import { IAchievement } from "@spt/models/eft/common/tables/IAchievement";
|
2024-05-28 13:59:19 +01:00
|
|
|
import { ICustomizationItem } from "@spt/models/eft/common/tables/ICustomizationItem";
|
|
|
|
import { IHandbookBase } from "@spt/models/eft/common/tables/IHandbookBase";
|
2024-05-28 11:13:27 +01:00
|
|
|
import { IMatch } from "@spt/models/eft/common/tables/IMatch";
|
2024-05-28 13:59:19 +01:00
|
|
|
import { IProfileTemplates } from "@spt/models/eft/common/tables/IProfileTemplate";
|
2024-05-28 12:27:46 +01:00
|
|
|
import { IQuest } from "@spt/models/eft/common/tables/IQuest";
|
2024-05-28 11:13:27 +01:00
|
|
|
import { ITemplateItem } from "@spt/models/eft/common/tables/ITemplateItem";
|
|
|
|
import { ITrader } from "@spt/models/eft/common/tables/ITrader";
|
|
|
|
import { IBots } from "@spt/models/spt/bots/IBots";
|
|
|
|
import { ILocationConfig } from "@spt/models/spt/config/ILocationConfig";
|
|
|
|
import { IHideout } from "@spt/models/spt/hideout/IHideout";
|
|
|
|
import { IDatabaseTables } from "@spt/models/spt/server/IDatabaseTables";
|
|
|
|
import { ILocaleBase } from "@spt/models/spt/server/ILocaleBase";
|
|
|
|
import { ILocations } from "@spt/models/spt/server/ILocations";
|
|
|
|
import { IServerBase } from "@spt/models/spt/server/IServerBase";
|
|
|
|
import { ISettingsBase } from "@spt/models/spt/server/ISettingsBase";
|
|
|
|
import { ITemplates } from "@spt/models/spt/templates/ITemplates";
|
|
|
|
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
|
|
|
import { DatabaseServer } from "@spt/servers/DatabaseServer";
|
|
|
|
import { LocalisationService } from "./LocalisationService";
|
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class DatabaseService
|
|
|
|
{
|
|
|
|
protected locationConfig: ILocationConfig;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
|
|
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
|
|
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
|
|
|
)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/
|
|
|
|
*/
|
|
|
|
public getTables(): IDatabaseTables
|
|
|
|
{
|
|
|
|
return this.databaseServer.getTables();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/bots/
|
|
|
|
*/
|
|
|
|
public getBots(): IBots
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().bots)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/bots"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().bots!;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/globals.json
|
|
|
|
*/
|
|
|
|
public getGlobals(): IGlobals
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().globals)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/globals.json"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().globals!;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/hideout/
|
|
|
|
*/
|
|
|
|
public getHideout(): IHideout
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().hideout)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/hideout"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().hideout!;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/locales/
|
|
|
|
*/
|
|
|
|
public getLocales(): ILocaleBase
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().locales)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/locales"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().locales!;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/locations
|
|
|
|
*/
|
|
|
|
public getLocations(): ILocations
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().locales)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/locales"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().locations!;
|
|
|
|
}
|
|
|
|
|
2024-05-28 14:28:26 +01:00
|
|
|
/**
|
|
|
|
* Get specific location by its Id
|
|
|
|
* @param locationId Desired trader id
|
|
|
|
* @returns assets/database/locations/
|
|
|
|
*/
|
|
|
|
public getLocation(locationId: string): ILocation
|
|
|
|
{
|
|
|
|
const locations = this.getLocations();
|
|
|
|
const desiredLocation = locations[locationId];
|
|
|
|
if (!desiredLocation)
|
|
|
|
{
|
|
|
|
throw new Error(this.localisationService.getText("database-no_location_found_with_id", locationId));
|
|
|
|
}
|
|
|
|
|
|
|
|
return desiredLocation!;
|
|
|
|
}
|
|
|
|
|
2024-05-28 11:13:27 +01:00
|
|
|
/**
|
|
|
|
* @returns assets/database/match/
|
|
|
|
*/
|
|
|
|
public getMatch(): IMatch
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().locales)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/locales"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().match!;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/server.json
|
|
|
|
*/
|
|
|
|
public getServer(): IServerBase
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().locales)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/locales"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().server!;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/settings.json
|
|
|
|
*/
|
|
|
|
public getSettings(): ISettingsBase
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().locales)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/locales"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().settings!;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/templates/
|
|
|
|
*/
|
|
|
|
public getTemplates(): ITemplates
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().templates)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/templates"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().templates!;
|
|
|
|
}
|
|
|
|
|
2024-05-28 12:27:46 +01:00
|
|
|
/**
|
|
|
|
* @returns assets/database/templates/achievements.json
|
|
|
|
*/
|
|
|
|
public getAchievements(): IAchievement[]
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().templates!.achievements)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/templates/achievements.json"));
|
2024-05-28 12:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().templates!.achievements!;
|
|
|
|
}
|
|
|
|
|
2024-05-28 13:59:19 +01:00
|
|
|
/**
|
|
|
|
* @returns assets/database/templates/customisation.json
|
|
|
|
*/
|
|
|
|
public getCustomization(): Record<string, ICustomizationItem>
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().templates!.customization)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/templates/customization.json"));
|
2024-05-28 13:59:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().templates!.customization!;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/templates/items.json
|
|
|
|
*/
|
|
|
|
public getHandbook(): IHandbookBase
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().templates!.handbook)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/templates/handbook.json"));
|
2024-05-28 13:59:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().templates!.handbook!;
|
|
|
|
}
|
|
|
|
|
2024-05-28 11:13:27 +01:00
|
|
|
/**
|
|
|
|
* @returns assets/database/templates/items.json
|
|
|
|
*/
|
|
|
|
public getItems(): Record<string, ITemplateItem>
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().templates!.items)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/templates/items.json"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().templates!.items!;
|
|
|
|
}
|
|
|
|
|
2024-05-28 13:59:19 +01:00
|
|
|
/**
|
|
|
|
* @returns assets/database/templates/prices.json
|
|
|
|
*/
|
|
|
|
public getPrices(): Record<string, number>
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().templates!.prices)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/templates/prices.json"));
|
2024-05-28 13:59:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().templates!.prices!;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns assets/database/templates/profiles.json
|
|
|
|
*/
|
|
|
|
public getProfiles(): IProfileTemplates
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().templates!.profiles)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/templates/profiles.json"));
|
2024-05-28 13:59:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().templates!.profiles!;
|
|
|
|
}
|
|
|
|
|
2024-05-28 12:27:46 +01:00
|
|
|
/**
|
|
|
|
* @returns assets/database/templates/items.json
|
|
|
|
*/
|
|
|
|
public getQuests(): Record<string, IQuest>
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().templates!.quests)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/templates/quests.json"));
|
2024-05-28 12:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().templates!.quests!;
|
|
|
|
}
|
|
|
|
|
2024-05-28 11:13:27 +01:00
|
|
|
/**
|
|
|
|
* @returns assets/database/traders/
|
|
|
|
*/
|
|
|
|
public getTraders(): Record<string, ITrader>
|
|
|
|
{
|
|
|
|
if (!this.databaseServer.getTables().traders)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-data_at_path_missing", "assets/database/traders"));
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.databaseServer.getTables().traders!;
|
|
|
|
}
|
2024-05-28 14:13:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get specific trader by their Id
|
|
|
|
* @param traderId Desired trader id
|
|
|
|
* @returns assets/database/traders/
|
|
|
|
*/
|
|
|
|
public getTrader(traderId: string): ITrader
|
|
|
|
{
|
|
|
|
const traders = this.getTraders();
|
|
|
|
const desiredTrader = traders[traderId];
|
|
|
|
if (!desiredTrader)
|
|
|
|
{
|
2024-05-28 14:23:01 +01:00
|
|
|
throw new Error(this.localisationService.getText("database-no_trader_found_with_id", traderId));
|
2024-05-28 14:13:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return desiredTrader!;
|
|
|
|
}
|
2024-05-28 11:13:27 +01:00
|
|
|
}
|