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