aboutsummaryrefslogtreecommitdiff
path: root/src/lib/models/instance/Level.ts
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-07-15 18:24:53 +0200
committerGitHub <noreply@github.com>2022-07-15 12:24:53 -0400
commitde106bb23746538aed6e5a0bf06b2d72deffd342 (patch)
tree1670e76a825227941827779f51309af8aaf4f04f /src/lib/models/instance/Level.ts
parentf19070f7bdd61f0cc1c74858624b0f34b6dc7074 (diff)
downloadtanzanite-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.ts12
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 {