Added getLocation() to databaseService and made use of it across various classes

This commit is contained in:
Dev 2024-05-28 14:28:26 +01:00
parent c710169e3d
commit 584eade530
6 changed files with 24 additions and 6 deletions

View File

@ -357,7 +357,7 @@ export class GameController
continue; continue;
} }
const mapLooseLoot: ILooseLoot = this.databaseService.getLocations()[mapId]?.looseLoot; const mapLooseLoot: ILooseLoot = this.databaseService.getLocation(mapId).looseLoot;
if (!mapLooseLoot) if (!mapLooseLoot)
{ {
this.logger.warning(this.localisationService.getText("location-map_has_no_loose_loot_data", mapId)); 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; const adjustments = this.lootConfig.looseLootSpawnPointAdjustments;
for (const mapId in adjustments) for (const mapId in adjustments)
{ {
const mapLooseLootData: ILooseLoot = this.databaseService.getLocations()[mapId]?.looseLoot; const mapLooseLootData: ILooseLoot = this.databaseService.getLocation(mapId).looseLoot;
if (!mapLooseLootData) if (!mapLooseLootData)
{ {
this.logger.warning(this.localisationService.getText("location-map_has_no_loose_loot_data", mapId)); this.logger.warning(this.localisationService.getText("location-map_has_no_loose_loot_data", mapId));

View File

@ -153,7 +153,7 @@ export class InraidController
const locationName = serverProfile.inraid.location.toLowerCase(); 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 serverPmcProfile = serverProfile.characters.pmc;
const serverScavProfile = serverProfile.characters.scav; const serverScavProfile = serverProfile.characters.scav;

View File

@ -591,7 +591,7 @@ export class InsuranceController
// Map is labs + insurance is disabled in base.json // Map is labs + insurance is disabled in base.json
if ( if (
insurance.systemData?.location?.toLowerCase() === labsId insurance.systemData?.location?.toLowerCase() === labsId
&& !(this.databaseServer.getLocations()[labsId].base.Insurance) && !(this.databaseServer.getLocation(labsId).base.Insurance)
) )
{ {
// Trader has labs-specific messages // Trader has labs-specific messages

View File

@ -78,7 +78,7 @@ export class LocationController
*/ */
protected generate(name: string): ILocationBase 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); const locationBaseClone: ILocationBase = this.cloner.clone(location.base);
// Update datetime property to now // Update datetime property to now

View File

@ -394,7 +394,7 @@ export class RepeatableQuestController
return true; return true;
} }
const locationBase: ILocationBase = this.databaseService.getLocations()[location.toLowerCase()]?.base; const locationBase: ILocationBase = this.databaseService.getLocation(location.toLowerCase()).base;
if (!locationBase) if (!locationBase)
{ {
return true; return true;

View File

@ -1,5 +1,6 @@
import { inject, injectable } from "tsyringe"; import { inject, injectable } from "tsyringe";
import { IGlobals } from "@spt/models/eft/common/IGlobals"; 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 { IAchievement } from "@spt/models/eft/common/tables/IAchievement";
import { ICustomizationItem } from "@spt/models/eft/common/tables/ICustomizationItem"; import { ICustomizationItem } from "@spt/models/eft/common/tables/ICustomizationItem";
import { IHandbookBase } from "@spt/models/eft/common/tables/IHandbookBase"; import { IHandbookBase } from "@spt/models/eft/common/tables/IHandbookBase";
@ -107,6 +108,23 @@ export class DatabaseService
return this.databaseServer.getTables().locations!; 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/ * @returns assets/database/match/
*/ */