diff --git a/project/src/controllers/GameController.ts b/project/src/controllers/GameController.ts index b1de2d53..230b46d1 100644 --- a/project/src/controllers/GameController.ts +++ b/project/src/controllers/GameController.ts @@ -357,7 +357,7 @@ export class GameController continue; } - const mapLooseLoot: ILooseLoot = this.databaseService.getLocations()[mapId]?.looseLoot; + const mapLooseLoot: ILooseLoot = this.databaseService.getLocation(mapId).looseLoot; if (!mapLooseLoot) { this.logger.warning(this.localisationService.getText("location-map_has_no_loose_loot_data", mapId)); @@ -392,7 +392,7 @@ export class GameController const adjustments = this.lootConfig.looseLootSpawnPointAdjustments; for (const mapId in adjustments) { - const mapLooseLootData: ILooseLoot = this.databaseService.getLocations()[mapId]?.looseLoot; + const mapLooseLootData: ILooseLoot = this.databaseService.getLocation(mapId).looseLoot; if (!mapLooseLootData) { this.logger.warning(this.localisationService.getText("location-map_has_no_loose_loot_data", mapId)); diff --git a/project/src/controllers/InraidController.ts b/project/src/controllers/InraidController.ts index b2bc8d90..da32d3a0 100644 --- a/project/src/controllers/InraidController.ts +++ b/project/src/controllers/InraidController.ts @@ -153,7 +153,7 @@ export class InraidController const locationName = serverProfile.inraid.location.toLowerCase(); - const map: ILocationBase = this.databaseService.getLocations()[locationName].base; + const map: ILocationBase = this.databaseService.getLocation(locationName).base; const serverPmcProfile = serverProfile.characters.pmc; const serverScavProfile = serverProfile.characters.scav; diff --git a/project/src/controllers/InsuranceController.ts b/project/src/controllers/InsuranceController.ts index 90866d2f..3fe32df7 100644 --- a/project/src/controllers/InsuranceController.ts +++ b/project/src/controllers/InsuranceController.ts @@ -591,7 +591,7 @@ export class InsuranceController // Map is labs + insurance is disabled in base.json if ( insurance.systemData?.location?.toLowerCase() === labsId - && !(this.databaseServer.getLocations()[labsId].base.Insurance) + && !(this.databaseServer.getLocation(labsId).base.Insurance) ) { // Trader has labs-specific messages diff --git a/project/src/controllers/LocationController.ts b/project/src/controllers/LocationController.ts index 8e3e8e51..3dde896a 100644 --- a/project/src/controllers/LocationController.ts +++ b/project/src/controllers/LocationController.ts @@ -78,7 +78,7 @@ export class LocationController */ protected generate(name: string): ILocationBase { - const location: ILocation = this.databaseService.getLocations()[name]; + const location: ILocation = this.databaseService.getLocation(name); const locationBaseClone: ILocationBase = this.cloner.clone(location.base); // Update datetime property to now diff --git a/project/src/controllers/RepeatableQuestController.ts b/project/src/controllers/RepeatableQuestController.ts index cf6db58b..47d3ec77 100644 --- a/project/src/controllers/RepeatableQuestController.ts +++ b/project/src/controllers/RepeatableQuestController.ts @@ -394,7 +394,7 @@ export class RepeatableQuestController return true; } - const locationBase: ILocationBase = this.databaseService.getLocations()[location.toLowerCase()]?.base; + const locationBase: ILocationBase = this.databaseService.getLocation(location.toLowerCase()).base; if (!locationBase) { return true; diff --git a/project/src/services/DatabaseService.ts b/project/src/services/DatabaseService.ts index 7002ac54..8abe0088 100644 --- a/project/src/services/DatabaseService.ts +++ b/project/src/services/DatabaseService.ts @@ -1,5 +1,6 @@ import { inject, injectable } from "tsyringe"; import { IGlobals } from "@spt/models/eft/common/IGlobals"; +import { ILocation } from "@spt/models/eft/common/ILocation"; import { IAchievement } from "@spt/models/eft/common/tables/IAchievement"; import { ICustomizationItem } from "@spt/models/eft/common/tables/ICustomizationItem"; import { IHandbookBase } from "@spt/models/eft/common/tables/IHandbookBase"; @@ -107,6 +108,23 @@ export class DatabaseService return this.databaseServer.getTables().locations!; } + /** + * 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!; + } + /** * @returns assets/database/match/ */