From 27bc7cfa6e067b1fa02c32f56242c0fdadf4e4b0 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 23 Jan 2024 11:42:47 +0000 Subject: [PATCH] Fixed armors being listed with plates above the allowed level on flea --- project/assets/configs/ragfair.json | 3 +- .../src/generators/RagfairAssortGenerator.ts | 6 +-- .../src/generators/RagfairOfferGenerator.ts | 51 ++++++++++++++++--- project/src/helpers/ItemHelper.ts | 4 +- .../src/models/spt/config/IRagfairConfig.ts | 2 + 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/project/assets/configs/ragfair.json b/project/assets/configs/ragfair.json index 787a0500..dc258145 100644 --- a/project/assets/configs/ragfair.json +++ b/project/assets/configs/ragfair.json @@ -201,7 +201,8 @@ "custom": [], "enableBsgList": true, "enableQuestList": true, - "traderItems": false + "traderItems": false, + "armorPlateMaxProtectionLevel": 4 }, "unreasonableModPrices": { "5448fe124bdc2da5018b4567": { diff --git a/project/src/generators/RagfairAssortGenerator.ts b/project/src/generators/RagfairAssortGenerator.ts index 269fd0b0..fe8cbefe 100644 --- a/project/src/generators/RagfairAssortGenerator.ts +++ b/project/src/generators/RagfairAssortGenerator.ts @@ -98,12 +98,12 @@ export class RagfairAssortGenerator continue; } - results.push(this.createRagfairAssortItem(item._id, item._id)); // tplid and id must be the same so hideout recipe reworks work + results.push(this.createRagfairAssortItem(item._id, item._id)); // tplid and id must be the same so hideout recipe rewards work } - for (const weapon of presets) + for (const preset of presets) { - results.push(this.createRagfairAssortItem(weapon._items[0]._tpl, weapon._id)); // Preset id must be passed through to ensure flea shows presets + results.push(this.createRagfairAssortItem(preset._items[0]._tpl, preset._id)); // Preset id must be passed through to ensure flea shows preset } return results; diff --git a/project/src/generators/RagfairOfferGenerator.ts b/project/src/generators/RagfairOfferGenerator.ts index 1d8bbc8f..145f240b 100644 --- a/project/src/generators/RagfairOfferGenerator.ts +++ b/project/src/generators/RagfairOfferGenerator.ts @@ -357,7 +357,7 @@ export class RagfairOfferGenerator return; } - // Get item + sub-items if preset, otherwise just get item + // Get item + sub-items (weapons + armors), otherwise just get item const itemWithChildren: Item[] = isPreset ? this.ragfairServerHelper.getPresetItems(assortItem) : [ @@ -366,6 +366,12 @@ 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(itemWithChildren, this.ragfairConfig.dynamic.blacklist.armorPlateMaxProtectionLevel); + } + // Get number of offers to create // Limit to 1 offer when processing expired const offerCount = expiredOffers @@ -376,16 +382,14 @@ export class RagfairOfferGenerator const assortSingleOfferProcesses = []; for (let index = 0; index < offerCount; index++) { - delete itemWithChildren[0].parentId; - delete itemWithChildren[0].slotId; - if (!isPreset) { - // presets get unique id generated during getPresetItems() earlier + // Presets get unique id generated during getPresetItems() earlier + would require regenerating all children to match itemWithChildren[0]._id = this.hashUtil.generate(); } - + delete itemWithChildren[0].parentId; + delete itemWithChildren[0].slotId; assortSingleOfferProcesses.push(this.createSingleOfferForItem(itemWithChildren, isPreset, itemDetails)); } @@ -393,6 +397,41 @@ export class RagfairOfferGenerator await Promise.all(assortSingleOfferProcesses); } + /** + * 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 + * @returns True if plate removed + */ + protected removeBannedPlatesFromPreset(presetWithChildren: Item[], plateProtectionLimit: number): boolean + { + if (!this.itemHelper.armorItemCanHoldMods(presetWithChildren[0]._tpl)) + { + // Cant hold armor inserts, skip + return false; + } + + const plateSlots = presetWithChildren.filter(item => this.itemHelper.getRemovablePlateSlotIds().includes(item.slotId?.toLowerCase())); + if (plateSlots.length === 0) + { + // Has no plate slots e.g. "left_side_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) + { + presetWithChildren.splice(presetWithChildren.indexOf(plateSlot), 1); + removedPlate = true; + } + } + + return removedPlate + } + /** * Create one flea offer for a specific item * @param itemWithChildren Item to create offer for diff --git a/project/src/helpers/ItemHelper.ts b/project/src/helpers/ItemHelper.ts index 6d167c7f..d158f0cf 100644 --- a/project/src/helpers/ItemHelper.ts +++ b/project/src/helpers/ItemHelper.ts @@ -1332,14 +1332,14 @@ export class ItemHelper */ public isRemovablePlateSlot(slotName: string): boolean { - return this.getRevovablePlateSlotIds().includes(slotName.toLowerCase()); + return this.getRemovablePlateSlotIds().includes(slotName.toLowerCase()); } /** * Get a list of slot names that hold removable plates * @returns Array of slot ids (e.g. front_plate) */ - public getRevovablePlateSlotIds(): string[] + public getRemovablePlateSlotIds(): string[] { return ["front_plate", "back_plate", "side_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 f0887460..067140a0 100644 --- a/project/src/models/spt/config/IRagfairConfig.ts +++ b/project/src/models/spt/config/IRagfairConfig.ts @@ -159,6 +159,8 @@ export interface Blacklist enableQuestList: boolean; /** 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; } export interface IUnreasonableModPrices