From e176b0ae45bd41f33ac36c18fd9d221fb991497a Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 17 Jun 2024 17:45:48 +0100 Subject: [PATCH] Refactored `applyMoneyBoost()` to improve readability + apply alteration to `reward.value` --- project/src/helpers/QuestHelper.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/project/src/helpers/QuestHelper.ts b/project/src/helpers/QuestHelper.ts index c02ccff6..8d302eac 100644 --- a/project/src/helpers/QuestHelper.ts +++ b/project/src/helpers/QuestHelper.ts @@ -587,24 +587,27 @@ export class QuestHelper /** * Adjust quest money rewards by passed in multiplier * @param quest Quest to multiple money rewards - * @param multiplier Value to adjust money rewards by + * @param bonusPercent Value to adjust money rewards by * @param questStatus Status of quest to apply money boost to rewards of * @returns Updated quest */ - public applyMoneyBoost(quest: IQuest, multiplier: number, questStatus: QuestStatus): IQuest + public applyMoneyBoost(quest: IQuest, bonusPercent: number, questStatus: QuestStatus): IQuest { const rewards: IQuestReward[] = quest.rewards?.[QuestStatus[questStatus]] ?? []; + const multipler = (bonusPercent / 100) + 1; for (const reward of rewards) { - if (reward.type === "Item") + // Skip non-money items + if (reward.type !== "Item" || !this.paymentHelper.isMoneyTpl(reward.items[0]._tpl)) { - if (this.paymentHelper.isMoneyTpl(reward.items[0]._tpl)) - { - reward.items[0].upd.StackObjectsCount += Math.round( - (reward.items[0].upd.StackObjectsCount * multiplier) / 100, - ); - } + continue; } + + // Add % bonus to existing StackObjectsCount + const rewardItem = reward.items[0]; + const newCurrencyAmount = Math.floor(rewardItem.upd.StackObjectsCount * multipler); + rewardItem.upd.StackObjectsCount = newCurrencyAmount; + reward.value = newCurrencyAmount; } return quest; @@ -916,11 +919,11 @@ export class QuestHelper } // Check for and apply intel center money bonus if it exists - const questMoneyRewardBonus = this.getQuestMoneyRewardBonus(pmcProfile); - if (questMoneyRewardBonus > 0) + const questMoneyRewardBonusPercent = this.getQuestMoneyRewardBonus(pmcProfile); + if (questMoneyRewardBonusPercent > 0) { // Apply additional bonus from hideout skill - questDetails = this.applyMoneyBoost(questDetails, questMoneyRewardBonus, state); // money = money + (money * intelCenterBonus / 100) + questDetails = this.applyMoneyBoost(questDetails, questMoneyRewardBonusPercent, state); // money = money + (money * intelCenterBonus / 100) } // e.g. 'Success' or 'AvailableForFinish'