From bd5d4bfb666f9a90c6226c34e9278cfbb7789bfe Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Mon, 19 Aug 2024 08:02:06 +0000 Subject: [PATCH] Fix fuel ticks returning fuel to the player instead of removing it (!397) Resolves the issue of incorrect fuel usage by using relative percentages for both the profile bonus and hideout management bonus Add a sanity check to make sure we never return fuel to the player (No negative fuel consumption) --- project/src/helpers/HideoutHelper.ts | 16 +++++++++++----- project/src/services/InsuranceService.ts | 9 ++++++--- project/src/services/RagfairTaxService.ts | 3 ++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/project/src/helpers/HideoutHelper.ts b/project/src/helpers/HideoutHelper.ts index 0576da77..4c8edb67 100644 --- a/project/src/helpers/HideoutHelper.ts +++ b/project/src/helpers/HideoutHelper.ts @@ -425,13 +425,19 @@ export class HideoutHelper { BonusType.FUEL_CONSUMPTION, ); - // 0 to 1 - const fuelConsumptionBonusMultipler = (profileFuelConsomptionBonusSum + 100) / 100; + // An increase in "bonus" consumption is actually an increase in consumption, so invert this for later use + const fuelConsumptionBonusRate = -(profileFuelConsomptionBonusSum / 100); - // 0 to 1 - const hideoutManagementConsumptionBonusMultipler = this.getHideoutManagementConsumptionBonus(pmcData); + // An increase in hideout management bonus is a decrease in consumption + const hideoutManagementConsumptionBonusRate = this.getHideoutManagementConsumptionBonus(pmcData); + + let combinedBonus = 1.0 - (fuelConsumptionBonusRate + hideoutManagementConsumptionBonusRate); + + // Sanity check, never let fuel consumption go negative, otherwise it returns fuel to the player + if (combinedBonus < 0) { + combinedBonus = 0; + } - const combinedBonus = 1.0 - (fuelConsumptionBonusMultipler + hideoutManagementConsumptionBonusMultipler); fuelUsedSinceLastTick *= combinedBonus; let hasFuelRemaining = false; diff --git a/project/src/services/InsuranceService.ts b/project/src/services/InsuranceService.ts index ce6b668e..aaa714e5 100644 --- a/project/src/services/InsuranceService.ts +++ b/project/src/services/InsuranceService.ts @@ -144,7 +144,9 @@ export class InsuranceService { pmcData, BonusType.INSURANCE_RETURN_TIME, ); - const insuranceReturnTimeBonusPercent = 1.0 - (insuranceReturnTimeBonusSum + 100) / 100; + + // A negative bonus implies a faster return, since we subtract later, invert the value here + const insuranceReturnTimeBonusPercent = -(insuranceReturnTimeBonusSum / 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; @@ -168,8 +170,9 @@ export class InsuranceService { randomisedReturnTimeSeconds *= editionModifier.multiplier; } - // Current time + randomised time calculated above - return this.timeUtil.getTimestamp() + randomisedReturnTimeSeconds * insuranceReturnTimeBonusPercent; + // Calculate the final return time based on our bonus percent + const finalReturnTimeSeconds = randomisedReturnTimeSeconds * (1.0 - insuranceReturnTimeBonusPercent); + return this.timeUtil.getTimestamp() + finalReturnTimeSeconds; } /** diff --git a/project/src/services/RagfairTaxService.ts b/project/src/services/RagfairTaxService.ts index 896ae2e5..c2322c77 100644 --- a/project/src/services/RagfairTaxService.ts +++ b/project/src/services/RagfairTaxService.ts @@ -86,7 +86,8 @@ export class RagfairTaxService { pmcData, BonusType.RAGFAIR_COMMISSION, ); - const taxDiscountPercent = (hideoutFleaTaxDiscountBonusSum + 100) / 100.0; + // A negative bonus implies a lower discount, since we subtract later, invert the value here + const taxDiscountPercent = -(hideoutFleaTaxDiscountBonusSum / 100.0); const tax = itemWorth * itemTaxMult * itemPriceMult + requirementsPrice * requirementTaxMult * requirementPriceMult;