MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / getLevelFromXp

Function getLevelFromXp

src/services/leveling.js:25–48  ·  view source on GitHub ↗
(xp)

Source from the content-addressed store, hash-verified

23}
24
25export function getLevelFromXp(xp) {
26 if (!Number.isInteger(xp) || xp < 0) {
27 throw new TitanBotError(
28 `Invalid XP: ${xp}`,
29 ErrorTypes.VALIDATION,
30 'XP must be a non-negative number.'
31 );
32 }
33
34 let level = 0;
35 let xpNeeded = 0;
36
37 while (xp >= getXpForLevel(level) && level < MAX_LEVEL) {
38 xpNeeded = getXpForLevel(level);
39 xp -= xpNeeded;
40 level++;
41 }
42
43 return {
44 level: Math.min(level, MAX_LEVEL),
45 currentXp: xp,
46 xpNeeded: getXpForLevel(Math.min(level, MAX_LEVEL))
47 };
48}
49
50export function calculateTotalXp(level, currentXp = 0) {
51 let total = currentXp;

Callers

nothing calls this directly

Calls 1

getXpForLevelFunction · 0.70

Tested by

no test coverage detected