From c097914e459342bf7278ad5272480ef64b5a3b75 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 8 Feb 2024 16:53:14 +0000 Subject: [PATCH] Add system to ignore armor plate slots when removing plates not suitable for flea --- project/assets/configs/ragfair.json | 5 ++- .../src/generators/RagfairOfferGenerator.ts | 32 ++++++++++++------- project/src/helpers/ItemHelper.ts | 2 +- .../src/models/spt/config/IRagfairConfig.ts | 10 +++++- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/project/assets/configs/ragfair.json b/project/assets/configs/ragfair.json index 84ed77ee..2f513c0b 100644 --- a/project/assets/configs/ragfair.json +++ b/project/assets/configs/ragfair.json @@ -292,7 +292,10 @@ "enableBsgList": true, "enableQuestList": true, "traderItems": false, - "armorPlateMaxProtectionLevel": 4 + "armorPlate": { + "maxProtectionLevel": 4, + "ignoreSlots": ["right_side_plate", "left_side_plate"] + } }, "unreasonableModPrices": { "5448fe124bdc2da5018b4567": { diff --git a/project/src/generators/RagfairOfferGenerator.ts b/project/src/generators/RagfairOfferGenerator.ts index e912e8c4..e9df073d 100644 --- a/project/src/generators/RagfairOfferGenerator.ts +++ b/project/src/generators/RagfairOfferGenerator.ts @@ -14,7 +14,12 @@ import { BaseClasses } from "@spt-aki/models/enums/BaseClasses"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; import { MemberCategory } from "@spt-aki/models/enums/MemberCategory"; import { Money } from "@spt-aki/models/enums/Money"; -import { Condition, Dynamic, IRagfairConfig } from "@spt-aki/models/spt/config/IRagfairConfig"; +import { + Condition, + Dynamic, + IArmorPlateBlacklistSettings, + IRagfairConfig, +} from "@spt-aki/models/spt/config/IRagfairConfig"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { ConfigServer } from "@spt-aki/servers/ConfigServer"; import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; @@ -358,10 +363,7 @@ export class RagfairOfferGenerator // Armor presets can hold plates above the allowed flea level, remove if necessary if (isPreset && this.ragfairConfig.dynamic.blacklist.enableBsgList) { - this.removeBannedPlatesFromPreset( - assortItemWithChildren, - this.ragfairConfig.dynamic.blacklist.armorPlateMaxProtectionLevel, - ); + this.removeBannedPlatesFromPreset(assortItemWithChildren, this.ragfairConfig.dynamic.blacklist.armorPlate); } // Get number of offers to create @@ -394,10 +396,13 @@ export class RagfairOfferGenerator /** * iterate over an items chidren and look for plates above desired level and remove them * @param presetWithChildren preset to check for plates - * @param plateProtectionLimit Max level of plates an armor can have without being removed + * @param plateSettings Settings * @returns True if plate removed */ - protected removeBannedPlatesFromPreset(presetWithChildren: Item[], plateProtectionLimit: number): boolean + protected removeBannedPlatesFromPreset( + presetWithChildren: Item[], + plateSettings: IArmorPlateBlacklistSettings, + ): boolean { if (!this.itemHelper.armorItemCanHoldMods(presetWithChildren[0]._tpl)) { @@ -410,16 +415,21 @@ export class RagfairOfferGenerator ); if (plateSlots.length === 0) { - // Has no plate slots e.g. "left_side_plate", exit + // Has no plate slots e.g. "front_plate", exit return false; } let removedPlate = false; for (const plateSlot of plateSlots) { - const plateArmorLevel = - Number.parseInt(this.itemHelper.getItem(plateSlot._tpl)[1]._props.armorClass) ?? 0; - if (plateArmorLevel > plateProtectionLimit) + const plateDetails = this.itemHelper.getItem(plateSlot._tpl)[1]; + if (plateSettings.ignoreSlots.includes(plateSlot.slotId.toLowerCase())) + { + continue; + } + + const plateArmorLevel = Number.parseInt(plateDetails._props.armorClass) ?? 0; + if (plateArmorLevel > plateSettings.maxProtectionLevel) { presetWithChildren.splice(presetWithChildren.indexOf(plateSlot), 1); removedPlate = true; diff --git a/project/src/helpers/ItemHelper.ts b/project/src/helpers/ItemHelper.ts index 48c0ee73..1266e8ee 100644 --- a/project/src/helpers/ItemHelper.ts +++ b/project/src/helpers/ItemHelper.ts @@ -1426,7 +1426,7 @@ export class ItemHelper */ public getRemovablePlateSlotIds(): string[] { - return ["front_plate", "back_plate", "side_plate", "left_side_plate", "right_side_plate"]; + return ["front_plate", "back_plate", "left_side_plate", "right_side_plate"]; } /** diff --git a/project/src/models/spt/config/IRagfairConfig.ts b/project/src/models/spt/config/IRagfairConfig.ts index 1601c391..f0e0799d 100644 --- a/project/src/models/spt/config/IRagfairConfig.ts +++ b/project/src/models/spt/config/IRagfairConfig.ts @@ -162,7 +162,15 @@ export interface Blacklist /** Should trader items that are blacklisted by bsg be listed on flea */ traderItems: boolean; /** Maximum level an armor plate can be found in a flea-listed armor item */ - armorPlateMaxProtectionLevel: number; + armorPlate: IArmorPlateBlacklistSettings; +} + +export interface IArmorPlateBlacklistSettings +{ + /** Max level of plates an armor can have without being removed */ + maxProtectionLevel: number; + /** Item slots to NOT remove from items on flea */ + ignoreSlots: string[]; } export interface IUnreasonableModPrices