Add AdjustSkillExpForLowLevels to AddSkillPointsToPlayer (#738)

* Add AdjustSkillExpForLowLevels to AddSkillPointsToPlayer

* remove unused AdjustSkillExpForLowLevels

* format unit tests

* fix suggestions

* Revert "remove unused AdjustSkillExpForLowLevels"

This reverts commit 43e0ab654378ca7ba1140648b1624730d637073b.

* mark as obsolete

* fix log message

---------

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
rootdarkarchon
2026-02-13 13:59:45 +01:00
committed by GitHub
parent c4082321e9
commit effb5cc0e4
3 changed files with 146 additions and 5 deletions
@@ -494,30 +494,103 @@ public class ProfileHelper(
return;
}
// already max level, no need to do any further calculations
if (profileSkill.Progress >= 5100)
{
if (logger.IsLogEnabled(LogLevel.Debug))
{
logger.Debug($"Player already has max level in skill: {skill}, not adding points");
}
profileSkill.LastAccess = timeUtil.GetTimeStamp();
return;
}
if (useSkillProgressRateMultiplier)
{
var skillProgressRate = databaseService.GetGlobals().Configuration.SkillsSettings.SkillProgressRate;
pointsToAddToSkill *= skillProgressRate;
}
if (InventoryConfig.SkillGainMultipliers.TryGetValue(skill.ToString(), out _))
if (InventoryConfig.SkillGainMultipliers.TryGetValue(skill.ToString(), out var multiplier))
{
pointsToAddToSkill *= InventoryConfig.SkillGainMultipliers[skill.ToString()];
pointsToAddToSkill *= multiplier;
}
profileSkill.Progress += pointsToAddToSkill;
var adjustedSkillProgress = AdjustSkillExpForLowLevels(profileSkill.Progress, pointsToAddToSkill);
profileSkill.Progress += adjustedSkillProgress;
profileSkill.Progress = Math.Min(profileSkill.Progress, 5100); // Prevent skill from ever going above level 51 (5100)
profileSkill.PointsEarnedDuringSession += pointsToAddToSkill;
profileSkill.PointsEarnedDuringSession += adjustedSkillProgress;
if (logger.IsLogEnabled(LogLevel.Debug))
{
logger.Debug($"Added: {pointsToAddToSkill} points to skill: {skill}, new progress value is: {profileSkill.Progress}");
logger.Debug($"Added: {adjustedSkillProgress} points to skill: {skill}, new progress value is: {profileSkill.Progress}");
}
profileSkill.LastAccess = timeUtil.GetTimeStamp();
}
/// <summary>
/// This method calculates the adjusted skill progression for lower levels.
/// </summary>
/// <param name="currentProgress">Current internal progress value of the skill, used to determine current level</param>
/// <param name="visualProgressAmount">The amount of visual progress to add</param>
/// <returns>Scaled skill progress according to level</returns>
/// <remarks>
/// It expects to be passed on a value as expected per the visual progress on the UI.
/// It will return scaled internal progress according to the current skill level, to match Tarkovs skill progression curve.
/// So passing on "0.4" will always yield +0.4 progress on the UI for the player.
/// </remarks>
public double AdjustSkillExpForLowLevels(double currentProgress, double visualProgressAmount)
{
var level = Math.Floor(currentProgress / 100d);
if (level >= 9)
{
return visualProgressAmount;
}
double internalAdded = 0;
// See "CalculateExpOnFirstLevels" in client for original logic
// loop until all visual progress has been used up
while (visualProgressAmount > 0)
{
// scale to apply for levels 1-10, decreasing as level goes higher
var uiMax = 10d * (level + 1d);
var factor = 100d / uiMax;
// remaining internal points in this level
var inLevel = currentProgress % 100d;
var internalRemaining = 100d - inLevel;
if (logger.IsLogEnabled(LogLevel.Debug))
{
logger.Debug($"currentLevelRemainingProgress: {internalRemaining}");
}
// visual needed to fill the rest of this internal level
var visualToLevelUp = internalRemaining / factor;
var spendVisual = Math.Min(visualProgressAmount, visualToLevelUp);
var addInternal = spendVisual * factor;
if (logger.IsLogEnabled(LogLevel.Debug))
{
logger.Debug($"Progress To Add Adjusted For Level: {addInternal}");
}
internalAdded += addInternal;
currentProgress += addInternal;
visualProgressAmount -= spendVisual;
level = Math.Floor(currentProgress / 100d);
}
return internalAdded;
}
/// <summary>
/// Is the provided session id for a developer account
/// </summary>
@@ -110,6 +110,7 @@ public class QuestHelper(
/// <param name="profileSkill">the skill experience is being added to</param>
/// <param name="progressAmount">the amount of experience being added to the skill</param>
/// <returns>the adjusted skill progress gain</returns>
[Obsolete("Will be removed in 4.1: Use ProfileHelper.AdjustSkillExpForLowLevels instead.")]
public int AdjustSkillExpForLowLevels(CommonSkill profileSkill, int progressAmount)
{
// TODO: what used this? can't find any uses in node