From 5d93d1cd6d1bf2607c53cae6188b6086a0c136b9 Mon Sep 17 00:00:00 2001 From: Chomp Date: Mon, 8 Sep 2025 13:04:11 +0100 Subject: [PATCH] Converted `GetSkillBonusMultipliedBySkillLevel` into extension method --- .../Controllers/TradeController.cs | 2 +- .../Extensions/ProfileExtensions.cs | 24 ++++++++++++++ .../Helpers/HideoutHelper.cs | 32 ++----------------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Controllers/TradeController.cs b/Libraries/SPTarkov.Server.Core/Controllers/TradeController.cs index 33783568..facb74ae 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/TradeController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/TradeController.cs @@ -138,7 +138,7 @@ public class TradeController( ) { // Skip buying items when player doesn't have needed loyalty - if (!pmcData.PlayerMeetsTraderLoyaltyLevelToBuyOffer(fleaOffer)) + if (!pmcData.ProfileMeetsTraderLoyaltyLevelToBuyOffer(fleaOffer)) { var errorMessage = $"Unable to buy item: {fleaOffer.Items[0].Template} from trader: {fleaOffer.User.Id} as loyalty level too low, skipping"; diff --git a/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs index 0075f49b..0197a519 100644 --- a/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs +++ b/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs @@ -69,6 +69,30 @@ public static class ProfileExtensions return profile?.Skills?.Common?.FirstOrDefault(s => s.Id == skill); } + /// + /// Get a multiplier based on player's skill level and value per level + /// + /// Player profile + /// Player skill from profile + /// Value from globals.config.SkillsSettings - `PerLevel` + /// Multiplier from 0 to 1 + public static double GetSkillBonusMultipliedBySkillLevel(this PmcData pmcData, SkillTypes skill, double valuePerLevel) + { + var profileSkill = pmcData.GetSkillFromProfile(skill); + if (profileSkill is null || profileSkill.Progress == 0) + { + return 0; + } + + // If the level is 51 we need to round it at 50 so on elite you dont get 25.5% + // at level 1 you already get 0.5%, so it goes up until level 50. For some reason the wiki + // says that it caps at level 51 with 25% but as per dump data that is incorrect apparently + var roundedLevel = Math.Floor(profileSkill.Progress / 100); + roundedLevel = roundedLevel.Approx(51d) ? roundedLevel - 1 : roundedLevel; + + return roundedLevel * valuePerLevel / 100; + } + /// /// Get the scav karma level for a profile /// Is also the fence trader rep level diff --git a/Libraries/SPTarkov.Server.Core/Helpers/HideoutHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/HideoutHelper.cs index 3b3503b5..c6ed88d9 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/HideoutHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/HideoutHelper.cs @@ -991,13 +991,11 @@ public class HideoutHelper( // 100 resources last 8 hrs 20 min, 100/8.33/60/60 = 0.00333 const double filterDrainRate = 0.00333d; - var hideoutManagementConsumptionBonus = GetSkillBonusMultipliedBySkillLevel( - pmcData, + var hideoutManagementConsumptionBonus = pmcData.GetSkillBonusMultipliedBySkillLevel( SkillTypes.HideoutManagement, globalSkillsDb.HideoutManagement.ConsumptionReductionPerLevel ); - var craftSkillTimeReductionMultiplier = GetSkillBonusMultipliedBySkillLevel( - pmcData, + var craftSkillTimeReductionMultiplier = pmcData.GetSkillBonusMultipliedBySkillLevel( SkillTypes.Crafting, globalSkillsDb.Crafting.CraftTimeReductionPerLevel ); @@ -1324,30 +1322,6 @@ public class HideoutHelper( / 100; } - /// - /// Get a multiplier based on player's skill level and value per level - /// - /// Player profile - /// Player skill from profile - /// Value from globals.config.SkillsSettings - `PerLevel` - /// Multiplier from 0 to 1 - protected double GetSkillBonusMultipliedBySkillLevel(PmcData pmcData, SkillTypes skill, double valuePerLevel) - { - var profileSkill = pmcData.GetSkillFromProfile(skill); - if (profileSkill is null || profileSkill.Progress == 0) - { - return 0; - } - - // If the level is 51 we need to round it at 50 so on elite you dont get 25.5% - // at level 1 you already get 0.5%, so it goes up until level 50. For some reason the wiki - // says that it caps at level 51 with 25% but as per dump data that is incorrect apparently - var roundedLevel = Math.Floor(profileSkill.Progress / 100); - roundedLevel = roundedLevel.Approx(51d) ? roundedLevel - 1 : roundedLevel; - - return roundedLevel * valuePerLevel / 100; - } - /// /// /// Player profile @@ -1357,7 +1331,7 @@ public class HideoutHelper( /// Seconds to reduce craft time by public double GetSkillProductionTimeReduction(PmcData pmcData, double productionTime, SkillTypes skill, double amountPerLevel) { - var skillTimeReductionMultiplier = GetSkillBonusMultipliedBySkillLevel(pmcData, skill, amountPerLevel); + var skillTimeReductionMultiplier = pmcData.GetSkillBonusMultipliedBySkillLevel(skill, amountPerLevel); return productionTime * skillTimeReductionMultiplier; }