From 915c96d40cc41523ac87e6392c6f9386bd7be4bd Mon Sep 17 00:00:00 2001 From: TetrisGG Date: Fri, 9 Aug 2024 08:50:57 +0000 Subject: [PATCH] Fix Bonuses in various Services using Find and not filter. (!393) Fix for SPT/Issues#743 FuelConsumptionBonus only looked for the first value, not all Bonuses a PMC has. TODO: Find a way for the Broken Wall to not give too much bonus when a player mops the floor in between the stages. Resulting with too much negative bonus once the broken wall is completed. Co-authored-by: Dev Reviewed-on: https://dev.sp-tarkov.com/SPT/Server/pulls/393 Co-authored-by: TetrisGG Co-committed-by: TetrisGG --- project/src/controllers/HideoutController.ts | 7 ++++--- project/src/helpers/HideoutHelper.ts | 6 +++--- project/src/services/InsuranceService.ts | 9 ++++----- project/src/services/RagfairTaxService.ts | 8 +++++--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index 484b6fd7..04608714 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -225,11 +225,12 @@ export class HideoutController { this.checkAndUpgradeWall(pmcData); } - // Cleanup temporary fuel usage debuffs if wall is complete + // Cleanup temporary fuel usage buffs from mopping floor if wall is complete as it would result in too many bonuses + // TODO: Clean up all buffs from mopping floor. if (profileHideoutArea.type === HideoutAreas.EMERGENCY_WALL && profileHideoutArea.level === 6) { - // Get everything except specific fuel consumption debuffs - pmcData.Bonuses = pmcData.Bonuses.filter(bonus => bonus.type !== BonusType.FUEL_CONSUMPTION && bonus.value === 5); + // Get everything except specific fuel consumption buffs + pmcData.Bonuses = pmcData.Bonuses.filter(bonus => bonus.type !== BonusType.FUEL_CONSUMPTION && bonus.value >= -10 && bonus.value <= 0); } // Add Skill Points Per Area Upgrade diff --git a/project/src/helpers/HideoutHelper.ts b/project/src/helpers/HideoutHelper.ts index 4312fe27..a6b16922 100644 --- a/project/src/helpers/HideoutHelper.ts +++ b/project/src/helpers/HideoutHelper.ts @@ -419,11 +419,11 @@ export class HideoutHelper { this.databaseService.getHideout().settings.generatorFuelFlowRate * this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn); - const profileFuelConsumptionBonus = pmcData.Bonuses.find((bonus) => bonus.type === BonusType.FUEL_CONSUMPTION); + // Get all fuel consumption bonuses, returns an empty array if none found + const profileFuelConsomptionBonusSum = this.profileHelper.getBonusValueFromProfile(pmcData,BonusType.FUEL_CONSUMPTION) // 0 to 1 - const fuelConsumptionBonusMultipler = - (profileFuelConsumptionBonus ? Math.abs(profileFuelConsumptionBonus.value) : 0) / 100; + const fuelConsumptionBonusMultipler = (profileFuelConsomptionBonusSum + 100) / 100; // 0 to 1 const hideoutManagementConsumptionBonusMultipler = this.getHideoutManagementConsumptionBonus(pmcData); diff --git a/project/src/services/InsuranceService.ts b/project/src/services/InsuranceService.ts index 50bd82b3..6d1202bd 100644 --- a/project/src/services/InsuranceService.ts +++ b/project/src/services/InsuranceService.ts @@ -27,6 +27,7 @@ import { RandomUtil } from "@spt/utils/RandomUtil"; import { TimeUtil } from "@spt/utils/TimeUtil"; import { ICloner } from "@spt/utils/cloners/ICloner"; import { inject, injectable } from "tsyringe"; +import { ProfileHelper } from "@spt/helpers/ProfileHelper"; @injectable() export class InsuranceService { @@ -51,6 +52,7 @@ export class InsuranceService { @inject("MailSendService") protected mailSendService: MailSendService, @inject("ConfigServer") protected configServer: ConfigServer, @inject("PrimaryCloner") protected cloner: ICloner, + @inject("ProfileHelper") protected profileHelper: ProfileHelper, ) { this.insuranceConfig = this.configServer.getConfig(ConfigTypes.INSURANCE); this.lostOnDeathConfig = this.configServer.getConfig(ConfigTypes.LOST_ON_DEATH); @@ -179,11 +181,8 @@ export class InsuranceService { return this.timeUtil.getTimestamp() + this.insuranceConfig.returnTimeOverrideSeconds; } - const insuranceReturnTimeBonus = pmcData.Bonuses.find( - (bonus) => bonus.type === BonusType.INSURANCE_RETURN_TIME, - ); - const insuranceReturnTimeBonusPercent = - 1.0 - (insuranceReturnTimeBonus ? Math.abs(insuranceReturnTimeBonus!.value ?? 0) : 0) / 100; + const insuranceReturnTimeBonusSum = this.profileHelper.getBonusValueFromProfile(pmcData,BonusType.INSURANCE_RETURN_TIME); + const insuranceReturnTimeBonusPercent = 1.0 - ((insuranceReturnTimeBonusSum + 100) / 100); const traderMinReturnAsSeconds = trader.insurance.min_return_hour * TimeUtil.ONE_HOUR_AS_SECONDS; const traderMaxReturnAsSeconds = trader.insurance.max_return_hour * TimeUtil.ONE_HOUR_AS_SECONDS; diff --git a/project/src/services/RagfairTaxService.ts b/project/src/services/RagfairTaxService.ts index 77b884ef..cfb6e111 100644 --- a/project/src/services/RagfairTaxService.ts +++ b/project/src/services/RagfairTaxService.ts @@ -8,6 +8,7 @@ import { ILogger } from "@spt/models/spt/utils/ILogger"; import { DatabaseService } from "@spt/services/DatabaseService"; import { RagfairPriceService } from "@spt/services/RagfairPriceService"; import { inject, injectable } from "tsyringe"; +import { ProfileHelper } from "@spt/helpers/ProfileHelper"; @injectable() export class RagfairTaxService { @@ -18,6 +19,7 @@ export class RagfairTaxService { @inject("DatabaseService") protected databaseService: DatabaseService, @inject("RagfairPriceService") protected ragfairPriceService: RagfairPriceService, @inject("ItemHelper") protected itemHelper: ItemHelper, + @inject("ProfileHelper") protected profileHelper: ProfileHelper, ) {} public storeClientOfferTaxValue(sessionId: string, offer: IStorePlayerOfferTaxAmountRequestData): void { @@ -78,12 +80,12 @@ export class RagfairTaxService { itemPriceMult = 4 ** itemPriceMult; requirementPriceMult = 4 ** requirementPriceMult; - const hideoutFleaTaxDiscountBonus = pmcData.Bonuses.find((b) => b.type === BonusType.RAGFAIR_COMMISSION); - const taxDiscountPercent = hideoutFleaTaxDiscountBonus ? Math.abs(hideoutFleaTaxDiscountBonus!.value ?? 0) : 0; + const hideoutFleaTaxDiscountBonusSum = this.profileHelper.getBonusValueFromProfile(pmcData,BonusType.RAGFAIR_COMMISSION); + const taxDiscountPercent = (hideoutFleaTaxDiscountBonusSum + 100) / 100.0; const tax = itemWorth * itemTaxMult * itemPriceMult + requirementsPrice * requirementTaxMult * requirementPriceMult; - const discountedTax = tax * (1.0 - taxDiscountPercent / 100.0); + const discountedTax = tax * (1.0 - taxDiscountPercent); const itemComissionMult = itemTemplate._props.RagFairCommissionModifier ? itemTemplate._props.RagFairCommissionModifier : 1;