Converted CalculateLevel to extension method
Removed `PlayerService`
This commit is contained in:
@@ -171,5 +171,34 @@ namespace SPTarkov.Server.Core.Extensions
|
||||
b.BanType == BanType.RagFair && currentTimestamp < b.DateTime
|
||||
) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the current level of a player based on their accumulated experience points.
|
||||
/// This method iterates through an experience table to determine the highest level achieved
|
||||
/// by comparing the player's experience against cumulative thresholds.
|
||||
/// </summary>
|
||||
/// <param name="pmcData"> Player profile </param>
|
||||
/// <param name="expTable">Experience table from globals.json</param>
|
||||
/// <returns>
|
||||
/// The calculated level of the player as an integer, or null if the level cannot be determined.
|
||||
/// This value is also assigned to <see cref="PmcData.Info.Level" /> within the provided profile.
|
||||
/// </returns>
|
||||
public static int? CalculateLevel(this PmcData pmcData, ExpTable[] expTable)
|
||||
{
|
||||
var accExp = 0;
|
||||
for (var i = 0; i < expTable.Length; i++)
|
||||
{
|
||||
accExp += expTable[i].Experience ?? 0;
|
||||
|
||||
if (pmcData.Info.Experience < accExp)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pmcData.Info.Level = i + 1;
|
||||
}
|
||||
|
||||
return pmcData.Info.Level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user