diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-07-15 18:24:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-15 12:24:53 -0400 |
commit | de106bb23746538aed6e5a0bf06b2d72deffd342 (patch) | |
tree | 1670e76a825227941827779f51309af8aaf4f04f /src/lib/models/instance/Level.ts | |
parent | f19070f7bdd61f0cc1c74858624b0f34b6dc7074 (diff) | |
download | tanzanite-de106bb23746538aed6e5a0bf06b2d72deffd342.tar.gz tanzanite-de106bb23746538aed6e5a0bf06b2d72deffd342.tar.bz2 tanzanite-de106bb23746538aed6e5a0bf06b2d72deffd342.zip |
Use actual math instead of loops (#62)
Diffstat (limited to 'src/lib/models/instance/Level.ts')
-rw-r--r-- | src/lib/models/instance/Level.ts | 12 |
1 files changed, 2 insertions, 10 deletions
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<LevelModel, LevelModelCreationAttributes> 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 { |