diff --git a/project/assets/database/locales/server/en.json b/project/assets/database/locales/server/en.json index d1ac906f..0e099a38 100644 --- a/project/assets/database/locales/server/en.json +++ b/project/assets/database/locales/server/en.json @@ -665,6 +665,7 @@ "trader-missing_trader_details_using_default_refresh_time": "Trader: {{traderId}} not found, generating temp entry with default refresh time of: {{updateTime}}", "trader-price_multipler_is_zero_use_default": "traderPriceMultipler was 0, this is invalid, setting to 0.01", "trader-unable_to_delete_stale_purchases": "Unable to process trader purchases in profile: {{profileId}} as trader: {{traderId}} cannot be found, skipping", + "trader-unable_to_find_profile_by_id": "Unable to find a profile with the id: %s", "trader-unable_to_find_profile_with_id": "Unable to find profile with sessionId: %s", "trader-unable_to_find_trader_by_id": "Unable to find trader with Id: %s", "trader-unable_to_find_trader_in_enum": "Unable to find trader: %s in Traders enum", diff --git a/project/src/helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.ts b/project/src/helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.ts index d721b7d6..9de6ffe2 100644 --- a/project/src/helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.ts +++ b/project/src/helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.ts @@ -147,8 +147,8 @@ export class GiveSptCommand implements ISptCommand } const localizedGlobal - = this.databaseServer.getTables().locales.global[locale] - ?? this.databaseServer.getTables().locales.global.en; + = this.databaseServer.getTables().locales!.global[locale] + ?? this.databaseServer.getTables().locales!.global.en; const closestItemsMatchedByName = this.itemHelper .getItems() @@ -191,8 +191,8 @@ export class GiveSptCommand implements ISptCommand } } - const localizedGlobal = this.databaseServer.getTables().locales.global[locale] - ?? this.databaseServer.getTables().locales.global.en; + const localizedGlobal = this.databaseServer.getTables().locales!.global[locale] + ?? this.databaseServer.getTables().locales!.global.en; // If item is an item name, we need to search using that item name and the locale which one we want otherwise // item is just the tplId. const tplId = isItemName diff --git a/project/src/helpers/Dialogue/Commando/SptCommands/TraderCommand/TraderSptCommand.ts b/project/src/helpers/Dialogue/Commando/SptCommands/TraderCommand/TraderSptCommand.ts index 9c5daf41..ac0c48c8 100644 --- a/project/src/helpers/Dialogue/Commando/SptCommands/TraderCommand/TraderSptCommand.ts +++ b/project/src/helpers/Dialogue/Commando/SptCommands/TraderCommand/TraderSptCommand.ts @@ -63,7 +63,7 @@ export class TraderSptCommand implements ISptCommand const command: string = result.groups.command; const quantity: number = +result.groups.quantity; - const dbTrader = Object.values(this.databaseServer.getTables().traders).find( + const dbTrader = Object.values(this.databaseServer.getTables().traders!).find( (t) => t.base.nickname.toLocaleLowerCase() === trader.toLocaleLowerCase(), ); if (dbTrader === undefined) diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index df50d985..50e8574a 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -453,7 +453,7 @@ export class InRaidHelper */ public removeSpawnedInSessionPropertyFromItems(postRaidProfile: IPostRaidPmcData): IPostRaidPmcData { - const dbItems = this.databaseServer.getTables().templates.items; + const dbItems = this.databaseServer.getTables().templates!.items; const itemsToRemovePropertyFrom = postRaidProfile.Inventory.items.filter((x) => { // Has upd object + upd.SpawnedInSession property + not a quest item diff --git a/project/src/helpers/ItemHelper.ts b/project/src/helpers/ItemHelper.ts index af9d0a73..cc9b8982 100644 --- a/project/src/helpers/ItemHelper.ts +++ b/project/src/helpers/ItemHelper.ts @@ -398,7 +398,7 @@ export class ItemHelper */ public getDynamicItemPrice(tpl: string): number { - const dynamicPrice = this.databaseServer.getTables().templates.prices[tpl]; + const dynamicPrice = this.databaseServer.getTables().templates!.prices[tpl]; if (dynamicPrice) { return dynamicPrice; @@ -432,7 +432,7 @@ export class ItemHelper */ public getItems(): ITemplateItem[] { - return this.cloner.clone(Object.values(this.databaseServer.getTables().templates.items)); + return this.cloner.clone(Object.values(this.databaseServer.getTables().templates!.items)); } /** @@ -443,9 +443,9 @@ export class ItemHelper public getItem(tpl: string): [boolean, ITemplateItem] { // -> Gets item from - if (tpl in this.databaseServer.getTables().templates.items) + if (tpl in this.databaseServer.getTables().templates!.items) { - return [true, this.databaseServer.getTables().templates.items[tpl]]; + return [true, this.databaseServer.getTables().templates!.items[tpl]]; } return [false, undefined]; @@ -709,7 +709,7 @@ export class ItemHelper */ public isItemTplStackable(tpl: string): boolean { - const item = this.databaseServer.getTables().templates.items[tpl]; + const item = this.databaseServer.getTables().templates!.items[tpl]; if (!item) { return undefined; @@ -1565,7 +1565,7 @@ export class ItemHelper public getItemTplsOfBaseType(desiredBaseType: string): string[] { - return Object.values(this.databaseServer.getTables().templates.items) + return Object.values(this.databaseServer.getTables().templates!.items) .filter((x) => x._parent === desiredBaseType) .map((x) => x._id); } diff --git a/project/src/helpers/PresetHelper.ts b/project/src/helpers/PresetHelper.ts index 7132b7b8..3d4e0c6e 100644 --- a/project/src/helpers/PresetHelper.ts +++ b/project/src/helpers/PresetHelper.ts @@ -44,7 +44,7 @@ export class PresetHelper { if (!this.defaultWeaponPresets) { - this.defaultWeaponPresets = Object.values(this.databaseServer.getTables().globals.ItemPresets) + this.defaultWeaponPresets = Object.values(this.databaseServer.getTables().globals!.ItemPresets) .filter( (preset) => preset._encyclopedia !== undefined @@ -68,7 +68,7 @@ export class PresetHelper { if (!this.defaultEquipmentPresets) { - this.defaultEquipmentPresets = Object.values(this.databaseServer.getTables().globals.ItemPresets) + this.defaultEquipmentPresets = Object.values(this.databaseServer.getTables().globals!.ItemPresets) .filter( (preset) => preset._encyclopedia !== undefined @@ -86,7 +86,7 @@ export class PresetHelper public isPreset(id: string): boolean { - return id in this.databaseServer.getTables().globals.ItemPresets; + return id in this.databaseServer.getTables().globals!.ItemPresets; } /** @@ -107,12 +107,12 @@ export class PresetHelper public getPreset(id: string): IPreset { - return this.cloner.clone(this.databaseServer.getTables().globals.ItemPresets[id]); + return this.cloner.clone(this.databaseServer.getTables().globals!.ItemPresets[id]); } public getAllPresets(): IPreset[] { - return this.cloner.clone(Object.values(this.databaseServer.getTables().globals.ItemPresets)); + return this.cloner.clone(Object.values(this.databaseServer.getTables().globals!.ItemPresets)); } public getPresets(templateId: string): IPreset[] diff --git a/project/src/helpers/ProfileHelper.ts b/project/src/helpers/ProfileHelper.ts index 236780b9..43c68b4f 100644 --- a/project/src/helpers/ProfileHelper.ts +++ b/project/src/helpers/ProfileHelper.ts @@ -482,7 +482,7 @@ export class ProfileHelper if (useSkillProgressRateMultipler) { - const globals = this.databaseServer.getTables().globals; + const globals = this.databaseServer.getTables().globals!; const skillProgressRate = globals.config.SkillsSettings.SkillProgressRate; pointsToAddToSkill *= skillProgressRate; } diff --git a/project/src/helpers/QuestHelper.ts b/project/src/helpers/QuestHelper.ts index f115e5cd..4f30e9ff 100644 --- a/project/src/helpers/QuestHelper.ts +++ b/project/src/helpers/QuestHelper.ts @@ -770,7 +770,7 @@ export class QuestHelper */ public getQuestsFromDb(): IQuest[] { - return Object.values(this.databaseServer.getTables().templates.quests); + return Object.values(this.databaseServer.getTables().templates!.quests); } /** @@ -781,7 +781,7 @@ export class QuestHelper */ public getQuestFromDb(questId: string, pmcData: IPmcData): IQuest { - let quest = this.databaseServer.getTables().templates.quests[questId]; + let quest = this.databaseServer.getTables().templates!.quests[questId]; // May be a repeatable quest if (!quest) @@ -1001,7 +1001,7 @@ export class QuestHelper ): void { // Get hideout crafts and find those that match by areatype/required level/end product tpl - hope for just one match - const hideoutProductions = this.databaseServer.getTables().hideout.production; + const hideoutProductions = this.databaseServer.getTables().hideout!.production; const matchingProductions = hideoutProductions.filter( (x) => x.areaType === Number.parseInt(craftUnlockReward.traderId) @@ -1099,7 +1099,7 @@ export class QuestHelper public addAllQuestsToProfile(pmcProfile: IPmcData, statuses: QuestStatus[]): void { // Iterate over all quests in db - const quests = this.databaseServer.getTables().templates.quests; + const quests = this.databaseServer.getTables().templates!.quests; for (const questIdKey in quests) { // Quest from db matches quests in profile, skip diff --git a/project/src/helpers/RagfairOfferHelper.ts b/project/src/helpers/RagfairOfferHelper.ts index 0a8d3039..0c5438ca 100644 --- a/project/src/helpers/RagfairOfferHelper.ts +++ b/project/src/helpers/RagfairOfferHelper.ts @@ -355,7 +355,7 @@ export class RagfairOfferHelper */ public increaseProfileRagfairRating(profile: ISptProfile, amountToIncrementBy: number): void { - const ragfairConfig = this.databaseServer.getTables().globals.config.RagFair; + const ragfairConfig = this.databaseServer.getTables().globals!.config.RagFair; profile.characters.pmc.RagfairInfo.isRatingGrowing = true; if (Number.isNaN(amountToIncrementBy)) @@ -572,7 +572,7 @@ export class RagfairOfferHelper const isTraderOffer = offer.user.memberType === MemberCategory.TRADER; if ( - pmcData.Info.Level < this.databaseServer.getTables().globals.config.RagFair.minUserLevel + pmcData.Info.Level < this.databaseServer.getTables().globals!.config.RagFair.minUserLevel && isDefaultUserOffer ) { @@ -762,7 +762,7 @@ export class RagfairOfferHelper // handle trader items to remove items that are not available to the user right now // required search for "lamp" shows 4 items, 3 of which are not available to a new player // filter those out - if (offer.user.id in this.databaseServer.getTables().traders) + if (offer.user.id in this.databaseServer.getTables().traders!) { if (!(offer.user.id in traderAssorts)) { diff --git a/project/src/helpers/RagfairSellHelper.ts b/project/src/helpers/RagfairSellHelper.ts index 27d7ecfd..a0361750 100644 --- a/project/src/helpers/RagfairSellHelper.ts +++ b/project/src/helpers/RagfairSellHelper.ts @@ -75,7 +75,7 @@ export class RagfairSellHelper const endTime = startTime + this.timeUtil.getHoursAsSeconds( - this.databaseServer.getTables().globals.config.RagFair.offerDurationTimeInHour, + this.databaseServer.getTables().globals!.config.RagFair.offerDurationTimeInHour, ); let sellTime = startTime; diff --git a/project/src/helpers/RagfairServerHelper.ts b/project/src/helpers/RagfairServerHelper.ts index c4f7436d..ff3803b9 100644 --- a/project/src/helpers/RagfairServerHelper.ts +++ b/project/src/helpers/RagfairServerHelper.ts @@ -144,7 +144,7 @@ export class RagfairServerHelper */ public isTrader(traderId: string): boolean { - return traderId in this.databaseServer.getTables().traders; + return traderId in this.databaseServer.getTables().traders!; } /** @@ -161,7 +161,7 @@ export class RagfairServerHelper RagfairServerHelper.goodsReturnedTemplate, returnedItems, this.timeUtil.getHoursAsSeconds( - this.databaseServer.getTables().globals.config.RagFair.yourOfferDidNotSellMaxStorageTimeInHour, + this.databaseServer.getTables().globals!.config.RagFair.yourOfferDidNotSellMaxStorageTimeInHour, ), ); } diff --git a/project/src/helpers/RepairHelper.ts b/project/src/helpers/RepairHelper.ts index 14f41975..291bb280 100644 --- a/project/src/helpers/RepairHelper.ts +++ b/project/src/helpers/RepairHelper.ts @@ -120,7 +120,7 @@ export class RepairHelper ): number { // Degradation value is based on the armor material - const armorMaterialSettings = this.databaseServer.getTables().globals.config.ArmorMaterials[armorMaterial]; + const armorMaterialSettings = this.databaseServer.getTables().globals!.config.ArmorMaterials[armorMaterial]; const minMultiplier = isRepairKit ? armorMaterialSettings.MinRepairKitDegradation diff --git a/project/src/helpers/TraderAssortHelper.ts b/project/src/helpers/TraderAssortHelper.ts index 0345675b..5c791286 100644 --- a/project/src/helpers/TraderAssortHelper.ts +++ b/project/src/helpers/TraderAssortHelper.ts @@ -68,7 +68,7 @@ export class TraderAssortHelper return this.getRagfairDataAsTraderAssort(); } - const traderClone = this.cloner.clone(this.databaseServer.getTables().traders[traderId]); + const traderClone = this.cloner.clone(this.databaseServer.getTables().traders![traderId]); const fullProfile = this.profileHelper.getFullProfile(sessionId); const pmcProfile = fullProfile.characters.pmc; @@ -245,7 +245,7 @@ export class TraderAssortHelper public traderAssortsHaveExpired(traderID: string): boolean { const time = this.timeUtil.getTimestamp(); - const trader = this.databaseServer.getTables().traders[traderID]; + const trader = this.databaseServer.getTables().traders![traderID]; return trader.base.nextResupply <= time; } diff --git a/project/src/helpers/TraderHelper.ts b/project/src/helpers/TraderHelper.ts index 5c580971..9d1b4127 100644 --- a/project/src/helpers/TraderHelper.ts +++ b/project/src/helpers/TraderHelper.ts @@ -1,3 +1,4 @@ +import { error } from "node:console"; import { inject, injectable } from "tsyringe"; import { HandbookHelper } from "@spt/helpers/HandbookHelper"; import { ItemHelper } from "@spt/helpers/ItemHelper"; @@ -59,7 +60,7 @@ export class TraderHelper const pmcData = this.profileHelper.getPmcProfile(sessionID); if (!pmcData) { - this.logger.error(this.localisationService.getText("trader-unable_to_find_profile_with_id", sessionID)); + throw new error(this.localisationService.getText("trader-unable_to_find_profile_with_id", sessionID)); } // Profile has traderInfo dict (profile beyond creation stage) but no requested trader in profile @@ -129,6 +130,11 @@ export class TraderHelper { const db = this.databaseServer.getTables(); const fullProfile = this.profileHelper.getFullProfile(sessionID); + if (!fullProfile) + { + throw new error(this.localisationService.getText("trader-unable_to_find_profile_by_id", sessionID)); + } + const pmcData = fullProfile.characters.pmc; const rawProfileTemplate: ProfileTraderTemplate = db.templates!.profiles[fullProfile.info.edition][pmcData.Info.Side.toLowerCase()] diff --git a/project/src/services/BotEquipmentModPoolService.ts b/project/src/services/BotEquipmentModPoolService.ts index f9ba2c14..709bdd6b 100644 --- a/project/src/services/BotEquipmentModPoolService.ts +++ b/project/src/services/BotEquipmentModPoolService.ts @@ -96,8 +96,8 @@ export class BotEquipmentModPoolService pool[item._id][slot._name].push(itemToAdd); // Check item added into array for slots, need to iterate over those - const subItemDetails = this.databaseServer.getTables().templates.items[itemToAdd]; - const hasSubItemsToAdd = subItemDetails?._props?.Slots?.length > 0; + const subItemDetails = this.databaseServer.getTables().templates!.items[itemToAdd]; + const hasSubItemsToAdd = subItemDetails?._props?.Slots?.length ?? 0 > 0; if (hasSubItemsToAdd && !pool[subItemDetails._id]) { // Recursive call @@ -185,7 +185,7 @@ export class BotEquipmentModPoolService */ protected generateWeaponPool(): void { - const weapons = Object.values(this.databaseServer.getTables().templates.items).filter( + const weapons = Object.values(this.databaseServer.getTables().templates!.items).filter( (x) => x._type === "Item" && this.itemHelper.isOfBaseclass(x._id, BaseClasses.WEAPON), ); this.generatePool(weapons, "weapon"); @@ -199,7 +199,7 @@ export class BotEquipmentModPoolService */ protected generateGearPool(): void { - const gear = Object.values(this.databaseServer.getTables().templates.items).filter( + const gear = Object.values(this.databaseServer.getTables().templates!.items).filter( (x) => x._type === "Item" && this.itemHelper.isOfBaseclasses(x._id, [ diff --git a/project/src/services/CustomLocationWaveService.ts b/project/src/services/CustomLocationWaveService.ts index e6efe6cf..5a917499 100644 --- a/project/src/services/CustomLocationWaveService.ts +++ b/project/src/services/CustomLocationWaveService.ts @@ -70,7 +70,14 @@ export class CustomLocationWaveService for (const mapKey in bossWavesToApply) { - const location: ILocationBase = this.databaseServer.getTables().locations[mapKey].base; + const location: ILocationBase = this.databaseServer.getTables().locations![mapKey]?.base; + if (!location) + { + this.logger.warning(`Unable to add custom boss wave to location: ${mapKey}, location not found`); + + continue; + } + for (const bossWave of bossWavesToApply[mapKey]) { if (location.BossLocationSpawn.find((x) => x.sptId === bossWave.sptId)) @@ -87,7 +94,14 @@ export class CustomLocationWaveService for (const mapKey in normalWavesToApply) { - const location: ILocationBase = this.databaseServer.getTables().locations[mapKey].base; + const location: ILocationBase = this.databaseServer.getTables().locations![mapKey]?.base; + if (!location) + { + this.logger.warning(`Unable to add custom wave to location: ${mapKey}, location not found`); + + continue; + } + for (const normalWave of normalWavesToApply[mapKey]) { if (location.waves.find((x) => x.sptId === normalWave.sptId)) diff --git a/project/src/services/mod/CustomItemService.ts b/project/src/services/mod/CustomItemService.ts index 25b2bc01..a639e9e6 100644 --- a/project/src/services/mod/CustomItemService.ts +++ b/project/src/services/mod/CustomItemService.ts @@ -266,8 +266,8 @@ export class CustomItemService } // Get PMCs - const usec = this.databaseServer.getTables().bots.types.usec; - const bear = this.databaseServer.getTables().bots.types.bear; + const usec = this.databaseServer.getTables().bots!.types.usec; + const bear = this.databaseServer.getTables().bots!.types.bear; // Add weapon base+mods into bear/usec data usec.inventory.mods[weaponTpl] = baseWeaponModObject;