Fixed PlayerService.calculateLevel

This commit is contained in:
TheSparta 2023-11-04 14:53:08 +00:00
parent 6ca19150bc
commit 45dad54e3e
2 changed files with 20 additions and 6 deletions

View File

@ -60,17 +60,18 @@ export class PlayerService
*/ */
public calculateLevel(pmcData: IPmcData): number public calculateLevel(pmcData: IPmcData): number
{ {
let exp = 0; let accExp = 0;
for (const level in this.databaseServer.getTables().globals.config.exp.level.exp_table) for (const [level, { exp }] of this.databaseServer.getTables().globals.config.exp.level.exp_table.entries())
{ {
if (pmcData.Info.Experience < exp) accExp += exp;
if (pmcData.Info.Experience < accExp)
{ {
break; break;
} }
pmcData.Info.Level = parseInt(level); pmcData.Info.Level = level + 1;
exp += this.databaseServer.getTables().globals.config.exp.level.exp_table[level].exp;
} }
return pmcData.Info.Level; return pmcData.Info.Level;

View File

@ -21,6 +21,19 @@ describe("PlayerService", () =>
describe("calculateLevel", () => describe("calculateLevel", () =>
{ {
it("should return 1 when player xp is 0", () =>
{
const playerProfile = {
Info: {
Experience: 0 // Via wiki: https://escapefromtarkov.fandom.com/wiki/Character_skills#Levels
}
};
const result = playerService.calculateLevel(playerProfile as IPmcData);
expect(result).toBe(1);
});
it("should return 1 when player xp is 999", () => it("should return 1 when player xp is 999", () =>
{ {
const playerProfile = { const playerProfile = {