From 1066a138ac8b51f21a3087b270f5a6065ffe24c1 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 8 Aug 2024 18:30:07 +0100 Subject: [PATCH] Added function `getBonusValueFromProfile` to `profileHelper` (cherry picked from commit d97e717f7645d42c00e3f84b6d08b53109fef71b) --- project/src/helpers/ProfileHelper.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/project/src/helpers/ProfileHelper.ts b/project/src/helpers/ProfileHelper.ts index 8b799884..71b46a73 100644 --- a/project/src/helpers/ProfileHelper.ts +++ b/project/src/helpers/ProfileHelper.ts @@ -501,6 +501,19 @@ export class ProfileHelper { } } + /** + * Iterate over all bonuses and sum up all bonuses of desired type in provided profile + * @param pmcProfile Player profile + * @param desiredBonus Bonus to sum up + * @returns Summed bonus value or 0 if no bonus found + */ + public getBonusValueFromProfile(pmcProfile: IPmcData, desiredBonus: BonusType): number { + const bonuses = pmcProfile.Bonuses.filter((bonus) => bonus.type === desiredBonus); + + // Sum all bonuses found above + return bonuses?.reduce((sum, curr) => sum + (curr.value ?? 0), 100) ?? 0; + } + public playerIsFleaBanned(pmcProfile: IPmcData): boolean { const currentTimestamp = this.timeUtil.getTimestamp(); return pmcProfile.Info.Bans.some((ban) => ban.banType === BanType.RAGFAIR && currentTimestamp < ban.dateTime);