From b766fa1220935fb047ffb882c1e236bdb63caf9f Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 23 Jan 2024 12:46:29 +0000 Subject: [PATCH] Allow armor items without plates to be listed on flea --- .../src/generators/RagfairAssortGenerator.ts | 71 ++++++++++++------- .../src/generators/RagfairOfferGenerator.ts | 2 +- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/project/src/generators/RagfairAssortGenerator.ts b/project/src/generators/RagfairAssortGenerator.ts index fe8cbefe..a874a26c 100644 --- a/project/src/generators/RagfairAssortGenerator.ts +++ b/project/src/generators/RagfairAssortGenerator.ts @@ -19,6 +19,16 @@ export class RagfairAssortGenerator protected generatedAssortItems: Item[] = []; protected ragfairConfig: IRagfairConfig; + protected ragfairItemInvalidBaseTypes: string[] = [ + BaseClasses.LOOT_CONTAINER, // Safe, barrel cache etc + BaseClasses.STASH, // Player inventory stash + BaseClasses.SORTING_TABLE, + BaseClasses.INVENTORY, + BaseClasses.STATIONARY_CONTAINER, + BaseClasses.POCKETS, + BaseClasses.BUILT_IN_INSERTS, + ]; + constructor( @inject("JsonUtil") protected jsonUtil: JsonUtil, @inject("HashUtil") protected hashUtil: HashUtil, @@ -62,34 +72,34 @@ export class RagfairAssortGenerator protected generateRagfairAssortItems(): Item[] { const results: Item[] = []; - const items = this.itemHelper.getItems().filter(item => item._type !== "Node"); - const presets = (this.ragfairConfig.dynamic.showDefaultPresetsOnly) - ? Object.values(this.presetHelper.getDefaultPresets()) - : this.presetHelper.getAllPresets() - - const ragfairItemInvalidBaseTypes: string[] = [ - BaseClasses.LOOT_CONTAINER, // safe, barrel cache etc - BaseClasses.STASH, // player inventory stash - BaseClasses.SORTING_TABLE, - BaseClasses.INVENTORY, - BaseClasses.STATIONARY_CONTAINER, - BaseClasses.POCKETS, - BaseClasses.BUILT_IN_INSERTS, - BaseClasses.ARMOR, // Handled by presets - BaseClasses.VEST, // Handled by presets - BaseClasses.HEADWEAR, // Handled by presets - ]; + /** Get cloned items from db */ + const dbItemsClone = this.itemHelper.getItems().filter(item => item._type !== "Node"); + const processedArmorItems: string[] = []; const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled(); const seasonalItemTplBlacklist = this.seasonalEventService.getInactiveSeasonalEventItems(); - for (const item of items) + + const presets = this.getPresetsToAdd(); + for (const preset of presets) { - if (!this.itemHelper.isValidItem(item._id, ragfairItemInvalidBaseTypes)) + const presetItemTpl = preset._items[0]._tpl; + + // Add presets base item tpl to the processed list so its skipped later on when processing items + processedArmorItems.push(presetItemTpl) + + // Preset id must be passed through to ensure flea shows preset + results.push(this.createRagfairAssortItem(presetItemTpl, preset._id)); + } + + for (const item of dbItemsClone) + { + if (!this.itemHelper.isValidItem(item._id, this.ragfairItemInvalidBaseTypes)) { continue; } + // Skip seasonal items when not in-season if ( this.ragfairConfig.dynamic.removeSeasonalItemsWhenNotInEvent && !seasonalEventActive && seasonalItemTplBlacklist.includes(item._id) @@ -98,17 +108,30 @@ export class RagfairAssortGenerator continue; } + if (processedArmorItems.includes(item._id)) + { + // Already processed + continue; + } + results.push(this.createRagfairAssortItem(item._id, item._id)); // tplid and id must be the same so hideout recipe rewards work } - for (const preset of presets) - { - results.push(this.createRagfairAssortItem(preset._items[0]._tpl, preset._id)); // Preset id must be passed through to ensure flea shows preset - } - return results; } + /** + * Get presets from globals to add to flea + * ragfairConfig.dynamic.showDefaultPresetsOnly decides if its all presets or just defaults + * @returns IPreset array + */ + protected getPresetsToAdd(): IPreset[] + { + return (this.ragfairConfig.dynamic.showDefaultPresetsOnly) + ? Object.values(this.presetHelper.getDefaultPresets()) + : this.presetHelper.getAllPresets() + } + /** * Create a base assort item and return it with populated values + 999999 stack count + unlimited count = true * @param tplId tplid to add to item diff --git a/project/src/generators/RagfairOfferGenerator.ts b/project/src/generators/RagfairOfferGenerator.ts index 145f240b..813b13a4 100644 --- a/project/src/generators/RagfairOfferGenerator.ts +++ b/project/src/generators/RagfairOfferGenerator.ts @@ -757,7 +757,7 @@ export class RagfairOfferGenerator for (const item of armorWithMods) { const itemDbDetails = this.itemHelper.getItem(item._tpl)[1]; - if ((parseInt(itemDbDetails._props.armorClass)) > 0) + if ((parseInt(itemDbDetails._props.armorClass)) > 1) { if (!item.upd) {