From aabd325804ffbf83a5ce6c7006f64c91b0c3d417 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Mon, 1 Apr 2024 08:38:23 +0000 Subject: [PATCH] Fix daily reward budget not being honored when filtering items (!277) Turns out `Array.filter` returns the filtered array, it doesn't modify the passed in array Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/277 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- .../RepeatableQuestRewardGenerator.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/project/src/generators/RepeatableQuestRewardGenerator.ts b/project/src/generators/RepeatableQuestRewardGenerator.ts index e3170aff..75b04926 100644 --- a/project/src/generators/RepeatableQuestRewardGenerator.ts +++ b/project/src/generators/RepeatableQuestRewardGenerator.ts @@ -116,7 +116,7 @@ export class RepeatableQuestRewardGenerator // Possible improvement -> draw trader-specific items e.g. with this.itemHelper.isOfBaseclass(val._id, ItemHelper.BASECLASS.FoodDrink) let roublesBudget = rewardRoubles; - const rewardItemPool = this.chooseRewardItemsWithinBudget(repeatableConfig, roublesBudget, traderId); + let rewardItemPool = this.chooseRewardItemsWithinBudget(repeatableConfig, roublesBudget, traderId); this.logger.debug( `Generating daily quest for ${traderId} with budget ${roublesBudget} for ${rewardNumItems} items`, ); @@ -213,7 +213,8 @@ export class RepeatableQuestRewardGenerator if (roublesBudget > 0) { // Filter possible reward items to only items with a price below the remaining budget - if (!this.filterRewardPoolWithinBudget(rewardItemPool, roublesBudget, 0)) + rewardItemPool = this.filterRewardPoolWithinBudget(rewardItemPool, roublesBudget, 0); + if (rewardItemPool.length === 0) { this.logger.debug(` Reward pool empty with ${roublesBudget} remaining`); break; // No reward items left, exit @@ -269,15 +270,13 @@ export class RepeatableQuestRewardGenerator rewardItems: ITemplateItem[], roublesBudget: number, minPrice: number, - ): boolean + ): ITemplateItem[] { - rewardItems.filter((item) => + return rewardItems.filter((item) => { const itemPrice = this.presetHelper.getDefaultPresetOrItemPrice(item._id); return itemPrice < roublesBudget && itemPrice > minPrice; }); - - return (rewardItems.length > 0); } /** @@ -357,7 +356,12 @@ export class RepeatableQuestRewardGenerator const minPrice = Math.min(25000, 0.5 * roublesBudget); let rewardableItemPoolWithinBudget = rewardableItemPool.map((x) => x[1]); - if (!this.filterRewardPoolWithinBudget(rewardableItemPoolWithinBudget, roublesBudget, minPrice)) + rewardableItemPoolWithinBudget = this.filterRewardPoolWithinBudget( + rewardableItemPoolWithinBudget, + roublesBudget, + minPrice, + ); + if (rewardableItemPoolWithinBudget.length === 0) { this.logger.warning( this.localisationService.getText("repeatable-no_reward_item_found_in_price_range", {