Move trader enum checking logic into traderHelper

This commit is contained in:
Dev 2023-08-04 11:19:27 +01:00
parent 07217e9ed0
commit 2a98b0a1b9
2 changed files with 14 additions and 2 deletions

View File

@ -416,4 +416,14 @@ export class TraderHelper
return keys[0] as Traders; return keys[0] as Traders;
} }
/**
* Does the 'Traders' enum has a value that matches the passed in parameter
* @param value Value to check for
* @returns True, values exists in Traders enum as a value
*/
public traderEnumHasValue(value: string): boolean
{
return Object.values(Traders).some((x) => x === value);
}
} }

View File

@ -3,6 +3,7 @@ import { inject, injectable } from "tsyringe";
import { HideoutHelper } from "../helpers/HideoutHelper"; import { HideoutHelper } from "../helpers/HideoutHelper";
import { InventoryHelper } from "../helpers/InventoryHelper"; import { InventoryHelper } from "../helpers/InventoryHelper";
import { ItemHelper } from "../helpers/ItemHelper"; import { ItemHelper } from "../helpers/ItemHelper";
import { TraderHelper } from "../helpers/TraderHelper";
import { IPmcData } from "../models/eft/common/IPmcData"; import { IPmcData } from "../models/eft/common/IPmcData";
import { Bonus, HideoutSlot } from "../models/eft/common/tables/IBotBase"; import { Bonus, HideoutSlot } from "../models/eft/common/tables/IBotBase";
import { import {
@ -35,6 +36,7 @@ export class ProfileFixerService
@inject("Watermark") protected watermark: Watermark, @inject("Watermark") protected watermark: Watermark,
@inject("HideoutHelper") protected hideoutHelper: HideoutHelper, @inject("HideoutHelper") protected hideoutHelper: HideoutHelper,
@inject("InventoryHelper") protected inventoryHelper: InventoryHelper, @inject("InventoryHelper") protected inventoryHelper: InventoryHelper,
@inject("TraderHelper") protected traderHelper: TraderHelper,
@inject("ItemHelper") protected itemHelper: ItemHelper, @inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("LocalisationService") protected localisationService: LocalisationService, @inject("LocalisationService") protected localisationService: LocalisationService,
@inject("TimeUtil") protected timeUtil: TimeUtil, @inject("TimeUtil") protected timeUtil: TimeUtil,
@ -740,7 +742,7 @@ export class ProfileFixerService
{ {
for (const activeQuest of repeatable.activeQuests ?? []) for (const activeQuest of repeatable.activeQuests ?? [])
{ {
if (!Object.values(Traders).some((x) => x === activeQuest.traderId)) if (!this.traderHelper.traderEnumHasValue(activeQuest.traderId))
{ {
this.logger.error(this.localisationService.getText("fixer-mod_item_found", activeQuest.traderId)); this.logger.error(this.localisationService.getText("fixer-mod_item_found", activeQuest.traderId));
if (this.coreConfig.fixes.removeModItemsFromProfile) if (this.coreConfig.fixes.removeModItemsFromProfile)
@ -779,7 +781,7 @@ export class ProfileFixerService
for (const traderId in fullProfile.traderPurchases) for (const traderId in fullProfile.traderPurchases)
{ {
if (!Object.values(Traders).some((x) => x === traderId)) if (!this.traderHelper.traderEnumHasValue(traderId))
{ {
this.logger.error(this.localisationService.getText("fixer-mod_item_found", traderId)); this.logger.error(this.localisationService.getText("fixer-mod_item_found", traderId));
if (this.coreConfig.fixes.removeModItemsFromProfile) if (this.coreConfig.fixes.removeModItemsFromProfile)