(xp)
| 23 | } |
| 24 | |
| 25 | export 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 | |
| 50 | export function calculateTotalXp(level, currentXp = 0) { |
| 51 | let total = currentXp; |
nothing calls this directly
no test coverage detected