From 575f467f78755715a97e475967e3b3994b83842d Mon Sep 17 00:00:00 2001 From: Dev Date: Sun, 11 Feb 2024 19:22:00 +0000 Subject: [PATCH] Tie random weapon reward to rouble reward Prevents daily quests from choosing high-level weapons as a reward for low level dailies --- .../generators/RepeatableQuestGenerator.ts | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/project/src/generators/RepeatableQuestGenerator.ts b/project/src/generators/RepeatableQuestGenerator.ts index 0396d947..4c3cd9d0 100644 --- a/project/src/generators/RepeatableQuestGenerator.ts +++ b/project/src/generators/RepeatableQuestGenerator.ts @@ -1,11 +1,13 @@ import { inject, injectable } from "tsyringe"; +import { ExhaustableArray } from "@spt-aki/helpers/BotGeneratorHelper"; import { HandbookHelper } from "@spt-aki/helpers/HandbookHelper"; import { ItemHelper } from "@spt-aki/helpers/ItemHelper"; import { PresetHelper } from "@spt-aki/helpers/PresetHelper"; import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper"; import { RagfairServerHelper } from "@spt-aki/helpers/RagfairServerHelper"; import { RepeatableQuestHelper } from "@spt-aki/helpers/RepeatableQuestHelper"; +import { IPreset } from "@spt-aki/models/eft/common/IGlobals"; import { Exit, ILocationBase } from "@spt-aki/models/eft/common/ILocationBase"; import { TraderInfo } from "@spt-aki/models/eft/common/tables/IBotBase"; import { Item } from "@spt-aki/models/eft/common/tables/IItem"; @@ -981,14 +983,32 @@ export class RepeatableQuestGenerator ) { // Add a random default preset weapon as reward - const defaultPresets = Object.values(this.presetHelper.getDefaultWeaponPresets()); - const defaultPresetClone = this.jsonUtil.clone(this.randomUtil.getArrayValue(defaultPresets)); - - // use _encyclopedia as its always the base items _tpl, items[0] isn't guaranteed to be base item - rewards.Success.push( - this.generateRewardItem(defaultPresetClone._encyclopedia, 1, rewardIndex, defaultPresetClone._items), + const defaultPresetPool = new ExhaustableArray( + Object.values(this.presetHelper.getDefaultWeaponPresets()), + this.randomUtil, + this.jsonUtil, ); - rewardIndex++; + let chosenPreset: IPreset; + while (defaultPresetPool.hasValues()) + { + const randomPreset = defaultPresetPool.getRandomValue(); + const tpls = randomPreset._items.map((item) => item._tpl); + const presetPrice = this.itemHelper.getItemAndChildrenPrice(tpls); + if (presetPrice <= roublesBudget) + { + chosenPreset = this.jsonUtil.clone(randomPreset); + break; + } + } + + if (chosenPreset) + { + // use _encyclopedia as its always the base items _tpl, items[0] isn't guaranteed to be base item + rewards.Success.push( + this.generateRewardItem(chosenPreset._encyclopedia, 1, rewardIndex, chosenPreset._items), + ); + rewardIndex++; + } } if (rewardItemPool.length > 0)