From 96382883810493f02162fdbd468b6fb069c98cff Mon Sep 17 00:00:00 2001 From: TheSparta Date: Sat, 4 Nov 2023 14:53:08 +0000 Subject: [PATCH] Fix level calcualtion function --- project/src/services/PlayerService.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/project/src/services/PlayerService.ts b/project/src/services/PlayerService.ts index 99594998..190ce346 100644 --- a/project/src/services/PlayerService.ts +++ b/project/src/services/PlayerService.ts @@ -60,19 +60,20 @@ export class PlayerService */ 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; } - pmcData.Info.Level = parseInt(level); - exp += this.databaseServer.getTables().globals.config.exp.level.exp_table[level].exp; + pmcData.Info.Level = level + 1; } return pmcData.Info.Level; } -} \ No newline at end of file +}