From de106bb23746538aed6e5a0bf06b2d72deffd342 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Fri, 15 Jul 2022 18:24:53 +0200 Subject: Use actual math instead of loops (#62) --- src/lib/models/instance/Level.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/lib/models/instance/Level.ts b/src/lib/models/instance/Level.ts index 77bc3d4..d8d16f0 100644 --- a/src/lib/models/instance/Level.ts +++ b/src/lib/models/instance/Level.ts @@ -57,19 +57,11 @@ export class Level extends BaseModel i } public static convertXpToLevel(xp: number): number { - let i = 0; - while (Level.convertLevelToXp(i + 1) < xp) { - i++; - } - return i; + return Math.floor((-25 + Math.sqrt(625 + 200 * xp)) / 100); } public static convertLevelToXp(level: number): number { - let xp = 0; - for (let i = 0; i < level; i++) { - xp += 100 * i + 75; - } - return xp; + return 50 * level * level + 25 * level; // 50x² + 25x } public static genRandomizedXp(): number { -- cgit