Updated various classes to make use of databaseService

This commit is contained in:
Dev 2024-05-28 14:52:22 +01:00
parent 584eade530
commit f56da3c1a8
12 changed files with 51 additions and 56 deletions

View File

@ -7,7 +7,6 @@ import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData";
import { ILocation } from "@spt/models/eft/common/ILocation";
import { ILooseLoot } from "@spt/models/eft/common/ILooseLoot";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { BodyPartHealth } from "@spt/models/eft/common/tables/IBotBase";
import { ICheckVersionResponse } from "@spt/models/eft/game/ICheckVersionResponse";
@ -357,7 +356,7 @@ export class GameController
continue;
}
const mapLooseLoot: ILooseLoot = this.databaseService.getLocation(mapId).looseLoot;
const mapLooseLoot = this.databaseService.getLocation(mapId).looseLoot;
if (!mapLooseLoot)
{
this.logger.warning(this.localisationService.getText("location-map_has_no_loose_loot_data", mapId));
@ -392,7 +391,7 @@ export class GameController
const adjustments = this.lootConfig.looseLootSpawnPointAdjustments;
for (const mapId in adjustments)
{
const mapLooseLootData: ILooseLoot = this.databaseService.getLocation(mapId).looseLoot;
const mapLooseLootData = this.databaseService.getLocation(mapId).looseLoot;
if (!mapLooseLootData)
{
this.logger.warning(this.localisationService.getText("location-map_has_no_loose_loot_data", mapId));

View File

@ -4,7 +4,6 @@ import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { QuestHelper } from "@spt/helpers/QuestHelper";
import { RepeatableQuestHelper } from "@spt/helpers/RepeatableQuestHelper";
import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData";
import { ILocationBase } from "@spt/models/eft/common/ILocationBase";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import {
IChangeRequirement,
@ -394,7 +393,7 @@ export class RepeatableQuestController
return true;
}
const locationBase: ILocationBase = this.databaseService.getLocation(location.toLowerCase()).base;
const locationBase = this.databaseService.getLocation(location.toLowerCase()).base;
if (!locationBase)
{
return true;

View File

@ -21,17 +21,17 @@ import { EquipmentFilterDetails, EquipmentFilters, IBotConfig } from "@spt/model
import { ExhaustableArray } from "@spt/models/spt/server/ExhaustableArray";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { BotEquipmentFilterService } from "@spt/services/BotEquipmentFilterService";
import { BotEquipmentModPoolService } from "@spt/services/BotEquipmentModPoolService";
import { BotWeaponModLimitService } from "@spt/services/BotWeaponModLimitService";
import { DatabaseService } from "@spt/services/DatabaseService";
import { ItemFilterService } from "@spt/services/ItemFilterService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { ICloner } from "@spt/utils/cloners/ICloner";
import { HashUtil } from "@spt/utils/HashUtil";
import { RandomUtil } from "@spt/utils/RandomUtil";
import { IFilterPlateModsForSlotByLevelResult, Result } from "../models/spt/bots/IFilterPlateModsForSlotByLevelResult";
import { IGenerateEquipmentProperties } from "./BotInventoryGenerator";
import { IFilterPlateModsForSlotByLevelResult, Result } from "./IFilterPlateModsForSlotByLevelResult";
@injectable()
export class BotEquipmentModGenerator
@ -43,7 +43,7 @@ export class BotEquipmentModGenerator
@inject("HashUtil") protected hashUtil: HashUtil,
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("ProbabilityHelper") protected probabilityHelper: ProbabilityHelper,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("DatabaseService") protected databaseService: DatabaseService,
@inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("BotEquipmentFilterService") protected botEquipmentFilterService: BotEquipmentFilterService,
@inject("ItemFilterService") protected itemFilterService: ItemFilterService,
@ -514,7 +514,7 @@ export class BotEquipmentModGenerator
// However, the recursion doesn't go over the slots of the parent mod but over the modPool which is given by the bot config
// where we decided to keep cartridges instead of camoras. And since a CylinderMagazine only has one cartridge entry and
// this entry is not to be filled, we need a special handling for the CylinderMagazine
const modParentItem = this.databaseServer.getTables().templates.items[modToAddTemplate._parent];
const modParentItem = this.databaseService.getItems()[modToAddTemplate._parent];
if (this.botWeaponGeneratorHelper.magazineIsCylinderRelated(modParentItem._name))
{
// We don't have child mods, we need to create the camoras for the magazines instead

View File

@ -25,8 +25,8 @@ import { IBotConfig } from "@spt/models/spt/config/IBotConfig";
import { IPmcConfig } from "@spt/models/spt/config/IPmcConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { BotEquipmentFilterService } from "@spt/services/BotEquipmentFilterService";
import { DatabaseService } from "@spt/services/DatabaseService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { SeasonalEventService } from "@spt/services/SeasonalEventService";
import { ICloner } from "@spt/utils/cloners/ICloner";
@ -46,7 +46,7 @@ export class BotGenerator
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("TimeUtil") protected timeUtil: TimeUtil,
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("DatabaseService") protected databaseService: DatabaseService,
@inject("BotInventoryGenerator") protected botInventoryGenerator: BotInventoryGenerator,
@inject("BotLevelGenerator") protected botLevelGenerator: BotLevelGenerator,
@inject("BotEquipmentFilterService") protected botEquipmentFilterService: BotEquipmentFilterService,
@ -124,7 +124,7 @@ export class BotGenerator
*/
protected getCloneOfBotBase(): IBotBase
{
return this.cloner.clone(this.databaseServer.getTables().bots.base);
return this.cloner.clone(this.databaseService.getBots().base);
}
/**
@ -243,9 +243,8 @@ export class BotGenerator
bot.Customization.Feet = this.weightedRandomHelper.getWeightedValue<string>(appearance.feet);
bot.Customization.Hands = this.weightedRandomHelper.getWeightedValue<string>(appearance.hands);
const tables = this.databaseServer.getTables();
const bodyGlobalDict = tables.globals.config.Customization.SavageBody;
const chosenBodyTemplate = tables.templates.customization[bot.Customization.Body];
const bodyGlobalDict = this.databaseService.getGlobals().config.Customization.SavageBody;
const chosenBodyTemplate = this.databaseService.getCustomization()[bot.Customization.Body];
// Find the body/hands mapping
const matchingBody: IWildBody = bodyGlobalDict[chosenBodyTemplate?._name];
@ -288,9 +287,10 @@ export class BotGenerator
return name;
}
const botTypes = this.databaseService.getBots().types; ;
const pmcNames = [
...this.databaseServer.getTables().bots.types.usec.firstName,
...this.databaseServer.getTables().bots.types.bear.firstName,
...botTypes.usec.firstName,
...botTypes.bear.firstName,
];
return `${name} (${this.randomUtil.getArrayValue(pmcNames)})`;

View File

@ -19,8 +19,8 @@ import {
} from "@spt/models/spt/config/IBotConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { BotEquipmentModPoolService } from "@spt/services/BotEquipmentModPoolService";
import { DatabaseService } from "@spt/services/DatabaseService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { HashUtil } from "@spt/utils/HashUtil";
import { RandomUtil } from "@spt/utils/RandomUtil";
@ -34,7 +34,7 @@ export class BotInventoryGenerator
@inject("WinstonLogger") protected logger: ILogger,
@inject("HashUtil") protected hashUtil: HashUtil,
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("DatabaseService") protected databaseService: DatabaseService,
@inject("BotWeaponGenerator") protected botWeaponGenerator: BotWeaponGenerator,
@inject("BotLootGenerator") protected botLootGenerator: BotLootGenerator,
@inject("BotGeneratorHelper") protected botGeneratorHelper: BotGeneratorHelper,

View File

@ -4,7 +4,7 @@ import { IRandomisedBotLevelResult } from "@spt/models/eft/bot/IRandomisedBotLev
import { IBotBase } from "@spt/models/eft/common/tables/IBotBase";
import { BotGenerationDetails } from "@spt/models/spt/bots/BotGenerationDetails";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { DatabaseService } from "@spt/services/DatabaseService";
import { RandomUtil } from "@spt/utils/RandomUtil";
@injectable()
@ -13,7 +13,7 @@ export class BotLevelGenerator
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("DatabaseService") protected databaseService: DatabaseService,
)
{}
@ -30,7 +30,7 @@ export class BotLevelGenerator
bot: IBotBase,
): IRandomisedBotLevelResult
{
const expTable = this.databaseServer.getTables().globals.config.exp.level.exp_table;
const expTable = this.databaseService.getGlobals().config.exp.level.exp_table;
const highestLevel = this.getHighestRelativeBotLevel(botGenerationDetails, levelDetails, expTable.length);
const lowestLevel = this.getLowestRelativeBotLevel(botGenerationDetails, levelDetails, expTable.length);

View File

@ -20,8 +20,8 @@ import { IBotConfig } from "@spt/models/spt/config/IBotConfig";
import { IPmcConfig } from "@spt/models/spt/config/IPmcConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { BotLootCacheService } from "@spt/services/BotLootCacheService";
import { DatabaseService } from "@spt/services/DatabaseService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { ICloner } from "@spt/utils/cloners/ICloner";
import { HashUtil } from "@spt/utils/HashUtil";
@ -39,7 +39,7 @@ export class BotLootGenerator
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("InventoryHelper") protected inventoryHelper: InventoryHelper,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("DatabaseService") protected databaseService: DatabaseService,
@inject("HandbookHelper") protected handbookHelper: HandbookHelper,
@inject("BotGeneratorHelper") protected botGeneratorHelper: BotGeneratorHelper,
@inject("BotWeaponGenerator") protected botWeaponGenerator: BotWeaponGenerator,

View File

@ -20,8 +20,8 @@ import { IPmcConfig } from "@spt/models/spt/config/IPmcConfig";
import { IRepairConfig } from "@spt/models/spt/config/IRepairConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { BotWeaponModLimitService } from "@spt/services/BotWeaponModLimitService";
import { DatabaseService } from "@spt/services/DatabaseService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { RepairService } from "@spt/services/RepairService";
import { ICloner } from "@spt/utils/cloners/ICloner";
@ -39,7 +39,7 @@ export class BotWeaponGenerator
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("HashUtil") protected hashUtil: HashUtil,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("DatabaseService") protected databaseService: DatabaseService,
@inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("WeightedRandomHelper") protected weightedRandomHelper: WeightedRandomHelper,
@inject("BotGeneratorHelper") protected botGeneratorHelper: BotGeneratorHelper,
@ -325,7 +325,7 @@ export class BotWeaponGenerator
// TODO: Right now, preset weapons trigger a lot of warnings regarding missing ammo in magazines & such
let preset: IPreset;
for (const presetObj of Object.values(this.databaseServer.getTables().globals.ItemPresets))
for (const presetObj of Object.values(this.databaseService.getGlobals().ItemPresets))
{
if (presetObj._items[0]._tpl === weaponTpl)
{

View File

@ -12,7 +12,7 @@ import { Traders } from "@spt/models/enums/Traders";
import { ITraderConfig } from "@spt/models/spt/config/ITraderConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { DatabaseService } from "@spt/services/DatabaseService";
import { FenceService } from "@spt/services/FenceService";
import { ItemFilterService } from "@spt/services/ItemFilterService";
import { LocalisationService } from "@spt/services/LocalisationService";
@ -27,7 +27,7 @@ export class FenceBaseAssortGenerator
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("HashUtil") protected hashUtil: HashUtil,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("DatabaseService") protected databaseService: DatabaseService,
@inject("HandbookHelper") protected handbookHelper: HandbookHelper,
@inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("PresetHelper") protected presetHelper: PresetHelper,
@ -47,7 +47,7 @@ export class FenceBaseAssortGenerator
public generateFenceBaseAssorts(): void
{
const blockedSeasonalItems = this.seasonalEventService.getInactiveSeasonalEventItems();
const baseFenceAssort = this.databaseServer.getTables().traders[Traders.FENCE].assort;
const baseFenceAssort = this.databaseService.getTrader(Traders.FENCE).assort;
for (const rootItemDb of this.itemHelper.getItems().filter((item) => this.isValidFenceItem(item)))
{

View File

@ -4,7 +4,6 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { PresetHelper } from "@spt/helpers/PresetHelper";
import {
IContainerMinMax,
ILocation,
IStaticAmmoDetails,
IStaticContainer,
IStaticContainerData,
@ -20,7 +19,7 @@ import { Money } from "@spt/models/enums/Money";
import { ILocationConfig } from "@spt/models/spt/config/ILocationConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { DatabaseService } from "@spt/services/DatabaseService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { SeasonalEventService } from "@spt/services/SeasonalEventService";
import { ICloner } from "@spt/utils/cloners/ICloner";
@ -50,7 +49,7 @@ export class LocationGenerator
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("DatabaseService") protected databaseService: DatabaseService,
@inject("ObjectId") protected objectId: ObjectId,
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("ItemHelper") protected itemHelper: ItemHelper,
@ -81,8 +80,7 @@ export class LocationGenerator
const result: SpawnpointTemplate[] = [];
const locationId = locationBase.Id.toLowerCase();
const db = this.databaseServer.getTables();
const mapData: ILocation = db.locations[locationId];
const mapData = this.databaseService.getLocation(locationId);
const staticWeaponsOnMapClone = this.cloner.clone(mapData.staticContainers.staticWeapons);
if (!staticWeaponsOnMapClone)
@ -165,14 +163,13 @@ export class LocationGenerator
}
// Group containers by their groupId
const staticContainerGroupData: IStaticContainer = db.locations[locationId].statics;
if (!staticContainerGroupData)
if (!mapData.statics)
{
this.logger.warning(this.localisationService.getText("location-unable_to_generate_static_loot", locationId));
return result;
}
const mapping = this.getGroupIdToContainerMappings(staticContainerGroupData, staticRandomisableContainersOnMap);
const mapping = this.getGroupIdToContainerMappings(mapData.statics, staticRandomisableContainersOnMap);
// For each of the container groups, choose from the pool of containers, hydrate container with loot and add to result array
for (const groupId in mapping)

View File

@ -11,7 +11,7 @@ import { ISealedAirdropContainerSettings, RewardDetails } from "@spt/models/spt/
import { LootItem } from "@spt/models/spt/services/LootItem";
import { LootRequest } from "@spt/models/spt/services/LootRequest";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { DatabaseService } from "@spt/services/DatabaseService";
import { ItemFilterService } from "@spt/services/ItemFilterService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { RagfairLinkedItemService } from "@spt/services/RagfairLinkedItemService";
@ -26,7 +26,7 @@ export class LootGenerator
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("HashUtil") protected hashUtil: HashUtil,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("DatabaseService") protected databaseService: DatabaseService,
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("PresetHelper") protected presetHelper: PresetHelper,
@ -49,7 +49,7 @@ export class LootGenerator
const itemTypeCounts = this.initItemLimitCounter(options.itemLimits);
const tables = this.databaseServer.getTables();
const itemsDb = this.databaseService.getItems();
const itemBlacklist = new Set<string>([
...this.itemFilterService.getBlacklistedItems(),
...options.itemBlacklist,
@ -70,8 +70,8 @@ export class LootGenerator
if (desiredWeaponCrateCount > 0)
{
// Get list of all sealed containers from db
const sealedWeaponContainerPool = Object.values(tables.templates.items).filter((x) =>
x._name.includes("event_container_airdrop"),
const sealedWeaponContainerPool = Object.values(itemsDb).filter((item) =>
item._name.includes("event_container_airdrop"),
);
for (let index = 0; index < desiredWeaponCrateCount; index++)
@ -88,12 +88,12 @@ export class LootGenerator
}
// Get items from items.json that have a type of item + not in global blacklist + basetype is in whitelist
const items = Object.entries(tables.templates.items).filter(
(x) =>
!itemBlacklist.has(x[1]._id)
&& x[1]._type.toLowerCase() === "item"
&& !x[1]._props.QuestItem
&& options.itemTypeWhitelist.includes(x[1]._parent),
const items = Object.entries(itemsDb).filter(
(item) =>
!itemBlacklist.has(item[1]._id)
&& item[1]._type.toLowerCase() === "item"
&& !item[1]._props.QuestItem
&& options.itemTypeWhitelist.includes(item[1]._parent),
);
if (items.length > 0)
@ -490,13 +490,13 @@ export class LootGenerator
}
// Get all items of the desired type + not quest items + not globally blacklisted
const rewardItemPool = Object.values(this.databaseServer.getTables().templates.items).filter(
(x) =>
x._parent === rewardTypeId
&& x._type.toLowerCase() === "item"
&& !this.itemFilterService.isItemBlacklisted(x._id)
&& !(containerSettings.allowBossItems || this.itemFilterService.isBossItem(x._id))
&& !x._props.QuestItem,
const rewardItemPool = Object.values(this.databaseService.getItems()).filter(
(item) =>
item._parent === rewardTypeId
&& item._type.toLowerCase() === "item"
&& !this.itemFilterService.isItemBlacklisted(item._id)
&& !(containerSettings.allowBossItems || this.itemFilterService.isBossItem(item._id))
&& !item._props.QuestItem,
);
if (rewardItemPool.length === 0)