From 7b835f150168b01db903fa2c62f37665eb6f76c6 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. --- project/src/controllers/HideoutController.ts | 9 ++++ project/src/helpers/HideoutHelper.ts | 6 +-- project/src/services/InsuranceService.ts | 10 ++-- project/src/services/RagfairTaxService.ts | 48 ++++++++++---------- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index 117d73e8..04608714 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -28,6 +28,7 @@ import { IAddItemDirectRequest } from "@spt/models/eft/inventory/IAddItemDirectR import { IAddItemsDirectRequest } from "@spt/models/eft/inventory/IAddItemsDirectRequest"; import { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse"; import { BackendErrorCodes } from "@spt/models/enums/BackendErrorCodes"; +import { BonusType } from "@spt/models/enums/BonusType"; import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; import { HideoutAreas } from "@spt/models/enums/HideoutAreas"; import { SkillTypes } from "@spt/models/enums/SkillTypes"; @@ -224,6 +225,14 @@ export class HideoutController { this.checkAndUpgradeWall(pmcData); } + // 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 buffs + pmcData.Bonuses = pmcData.Bonuses.filter(bonus => bonus.type !== BonusType.FUEL_CONSUMPTION && bonus.value >= -10 && bonus.value <= 0); + } + // Add Skill Points Per Area Upgrade this.profileHelper.addSkillPointsToPlayer( pmcData, 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 87024940..ce6b668e 100644 --- a/project/src/services/InsuranceService.ts +++ b/project/src/services/InsuranceService.ts @@ -1,4 +1,5 @@ import { ItemHelper } from "@spt/helpers/ItemHelper"; +import { ProfileHelper } from "@spt/helpers/ProfileHelper"; import { TraderHelper } from "@spt/helpers/TraderHelper"; import { IPmcData } from "@spt/models/eft/common/IPmcData"; import { Item } from "@spt/models/eft/common/tables/IItem"; @@ -35,6 +36,7 @@ export class InsuranceService { @inject("TimeUtil") protected timeUtil: TimeUtil, @inject("SaveServer") protected saveServer: SaveServer, @inject("TraderHelper") protected traderHelper: TraderHelper, + @inject("ProfileHelper") protected profileHelper: ProfileHelper, @inject("LocalisationService") protected localisationService: LocalisationService, @inject("MailSendService") protected mailSendService: MailSendService, @inject("ConfigServer") protected configServer: ConfigServer, @@ -138,11 +140,11 @@ export class InsuranceService { return this.timeUtil.getTimestamp() + this.insuranceConfig.returnTimeOverrideSeconds; } - const insuranceReturnTimeBonus = pmcData.Bonuses.find( - (bonus) => bonus.type === BonusType.INSURANCE_RETURN_TIME, + const insuranceReturnTimeBonusSum = this.profileHelper.getBonusValueFromProfile( + pmcData, + BonusType.INSURANCE_RETURN_TIME, ); - const insuranceReturnTimeBonusPercent = - 1.0 - (insuranceReturnTimeBonus ? Math.abs(insuranceReturnTimeBonus.value ?? 0) : 0) / 100; + 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 ddfc4e39..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 { @@ -64,7 +66,7 @@ export class RagfairTaxService { const requirementsPrice = requirementsValue * (sellInOnePiece ? 1 : offerItemCount); const itemTaxMult = globals.config.RagFair.communityItemTax / 100.0; - const requirementTaxMult = globals.config.RagFair.communityRequirementTax / 100.0; + const requirementTaxMult = globals!.config.RagFair.communityRequirementTax / 100.0; let itemPriceMult = Math.log10(itemWorth / requirementsPrice); let requirementPriceMult = Math.log10(requirementsPrice / itemWorth); @@ -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; @@ -123,7 +125,7 @@ export class RagfairTaxService { worth += this.calculateItemWorth( child, this.itemHelper.getItem(child._tpl)[1], - child.upd.StackObjectsCount, + child.upd!.StackObjectsCount!, pmcData, false, ); @@ -131,39 +133,39 @@ export class RagfairTaxService { } } - if ("Dogtag" in item.upd) { - worth *= item.upd.Dogtag.Level; + if ("Dogtag" in item.upd!) { + worth *= item.upd!.Dogtag!.Level; } - if ("Key" in item.upd && (itemTemplate._props.MaximumNumberOfUsage ?? 0) > 0) { + if ("Key" in item.upd! && (itemTemplate._props.MaximumNumberOfUsage ?? 0) > 0) { worth = - (worth / itemTemplate._props.MaximumNumberOfUsage) * - (itemTemplate._props.MaximumNumberOfUsage - item.upd.Key.NumberOfUsages); + (worth / itemTemplate._props.MaximumNumberOfUsage!) * + (itemTemplate._props.MaximumNumberOfUsage! - item.upd!.Key!.NumberOfUsages); } - if ("Resource" in item.upd && itemTemplate._props.MaxResource > 0) { - worth = worth * 0.1 + ((worth * 0.9) / itemTemplate._props.MaxResource) * item.upd.Resource.Value; + if ("Resource" in item.upd! && itemTemplate._props.MaxResource! > 0) { + worth = worth * 0.1 + ((worth * 0.9) / itemTemplate._props.MaxResource!) * item.upd.Resource!.Value; } - if ("SideEffect" in item.upd && itemTemplate._props.MaxResource > 0) { - worth = worth * 0.1 + ((worth * 0.9) / itemTemplate._props.MaxResource) * item.upd.SideEffect.Value; + if ("SideEffect" in item.upd! && itemTemplate._props.MaxResource! > 0) { + worth = worth * 0.1 + ((worth * 0.9) / itemTemplate._props.MaxResource!) * item.upd.SideEffect!.Value; } - if ("MedKit" in item.upd && itemTemplate._props.MaxHpResource > 0) { - worth = (worth / itemTemplate._props.MaxHpResource) * item.upd.MedKit.HpResource; + if ("MedKit" in item.upd! && itemTemplate._props.MaxHpResource! > 0) { + worth = (worth / itemTemplate._props.MaxHpResource!) * item.upd.MedKit!.HpResource; } - if ("FoodDrink" in item.upd && itemTemplate._props.MaxResource > 0) { - worth = (worth / itemTemplate._props.MaxResource) * item.upd.FoodDrink.HpPercent; + if ("FoodDrink" in item.upd! && itemTemplate._props.MaxResource! > 0) { + worth = (worth / itemTemplate._props.MaxResource!) * item.upd.FoodDrink!.HpPercent; } - if ("Repairable" in item.upd && itemTemplate._props.armorClass > 0) { - const num2 = 0.01 * 0.0 ** item.upd.Repairable.MaxDurability; + if ("Repairable" in item.upd! && itemTemplate._props.armorClass > 0) { + const num2 = 0.01 * 0.0 ** item.upd.Repairable!.MaxDurability; worth = - worth * (item.upd.Repairable.MaxDurability / itemTemplate._props.Durability - num2) - + worth * (item.upd.Repairable!.MaxDurability / itemTemplate._props.Durability! - num2) - Math.floor( - itemTemplate._props.RepairCost * - (item.upd.Repairable.MaxDurability - item.upd.Repairable.Durability), + itemTemplate._props.RepairCost! * + (item.upd.Repairable!.MaxDurability - item.upd.Repairable!.Durability), ); }