Fix sealed weapon crates when bad mod data exists (!416)

If a modded weapon includes non-existant items in some of its fields, sealed weapon crates had the potential to throw an exception on open due to not validating that all `LinkedDbItems` existed. This filters the list to only items that are found in the item DB

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT/Server/pulls/416
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-10-04 15:21:44 +00:00 committed by chomp
parent e3cdd26d0d
commit f650bb6be5

View File

@ -1,6 +1,7 @@
import { ItemHelper } from "@spt/helpers/ItemHelper"; import { ItemHelper } from "@spt/helpers/ItemHelper";
import { ITemplateItem } from "@spt/models/eft/common/tables/ITemplateItem"; import { ITemplateItem } from "@spt/models/eft/common/tables/ITemplateItem";
import { BaseClasses } from "@spt/models/enums/BaseClasses"; import { BaseClasses } from "@spt/models/enums/BaseClasses";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { DatabaseService } from "@spt/services/DatabaseService"; import { DatabaseService } from "@spt/services/DatabaseService";
import { inject, injectable } from "tsyringe"; import { inject, injectable } from "tsyringe";
@ -11,6 +12,7 @@ export class RagfairLinkedItemService {
constructor( constructor(
@inject("DatabaseService") protected databaseService: DatabaseService, @inject("DatabaseService") protected databaseService: DatabaseService,
@inject("ItemHelper") protected itemHelper: ItemHelper, @inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("PrimaryLogger") protected logger: ILogger,
) {} ) {}
public getLinkedItems(linkedSearchId: string): Set<string> { public getLinkedItems(linkedSearchId: string): Set<string> {
@ -28,10 +30,15 @@ export class RagfairLinkedItemService {
*/ */
public getLinkedDbItems(itemTpl: string): ITemplateItem[] { public getLinkedDbItems(itemTpl: string): ITemplateItem[] {
const linkedItemsToWeaponTpls = this.getLinkedItems(itemTpl); const linkedItemsToWeaponTpls = this.getLinkedItems(itemTpl);
return [...linkedItemsToWeaponTpls].map((x) => { return [...linkedItemsToWeaponTpls].reduce((result, linkedTpl) => {
const itemDetails = this.itemHelper.getItem(x); const itemDetails = this.itemHelper.getItem(linkedTpl);
return itemDetails[1]; if (itemDetails[0]) {
}); result.push(itemDetails[1]);
} else {
this.logger.warning(`Item ${itemTpl} has invalid linked item ${linkedTpl}`);
}
return result;
}, []);
} }
/** /**