From cc2e8202905d4bfa11e2e590649cd66e34f92bf0 Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 7 Feb 2024 20:51:12 +0000 Subject: [PATCH] Move ammo stack size calcualtion into its own function --- .../generators/RepeatableQuestGenerator.ts | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/project/src/generators/RepeatableQuestGenerator.ts b/project/src/generators/RepeatableQuestGenerator.ts index 1cdd8a05..7247803f 100644 --- a/project/src/generators/RepeatableQuestGenerator.ts +++ b/project/src/generators/RepeatableQuestGenerator.ts @@ -1020,19 +1020,12 @@ export class RepeatableQuestGenerator continue; } - // The budget for this ammo stack - const stackRoubleBudget = roublesBudget / rewardNumItems; - - const singleCartridgePrice = this.handbookHelper.getTemplatePrice(itemSelected._id); - - // Get a stack size of ammo that fits rouble budget - const stackSizeThatFitsBudget = Math.round(stackRoubleBudget / singleCartridgePrice); - - // Get itemDbs max stack size for ammo - don't go above 100 (some mods mess around with stack sizes) - const stackMaxCount = Math.min(itemSelected._props.StackMaxSize, 100); - // Choose smallest value between budget fitting size and stack max - rewardItemStackCount = Math.min(stackSizeThatFitsBudget, stackMaxCount); + rewardItemStackCount = this.calculateAmmoStackSizeThatFitsBudget( + itemSelected, + roublesBudget, + rewardNumItems, + ); } // 25% chance to double, triple quadruple reward stack (Only occurs when item is stackable and not weapon or ammo) @@ -1094,6 +1087,26 @@ export class RepeatableQuestGenerator return rewards; } + protected calculateAmmoStackSizeThatFitsBudget( + itemSelected: ITemplateItem, + roublesBudget: number, + rewardNumItems: number, + ): number + { + // The budget for this ammo stack + const stackRoubleBudget = roublesBudget / rewardNumItems; + + const singleCartridgePrice = this.handbookHelper.getTemplatePrice(itemSelected._id); + + // Get a stack size of ammo that fits rouble budget + const stackSizeThatFitsBudget = Math.round(stackRoubleBudget / singleCartridgePrice); + + // Get itemDbs max stack size for ammo - don't go above 100 (some mods mess around with stack sizes) + const stackMaxCount = Math.min(itemSelected._props.StackMaxSize, 100); + + return Math.min(stackSizeThatFitsBudget, stackMaxCount); + } + /** * Should reward item have stack size increased (25% chance) * @param item Item to possibly increase stack size of