Created
June 27, 2021 20:29
-
-
Save jacc/7ecc831d70081516422792c370078e4c to your computer and use it in GitHub Desktop.
Function to convert Hypixel network experience to a level in JS/TS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code adapted from https://github.com/HypixelDev/PublicAPI/blob/master/Java/src/main/java/net/hypixel/api/util/ILeveling.java | |
const BASE = 10_000 | |
const GROWTH = 2_500 | |
console.log(BASE + GROWTH) | |
const REVERSE_PQ_PREFIX = -(BASE - 0.5 * GROWTH) / GROWTH; | |
const REVERSE_CONST = REVERSE_PQ_PREFIX * REVERSE_PQ_PREFIX; | |
const GROWTH_DIVIDES_2 = 2 / GROWTH; | |
function calculate(exp) { | |
return exp < 0 ? 1 : Math.floor(1 + REVERSE_PQ_PREFIX + Math.sqrt(REVERSE_CONST + GROWTH_DIVIDES_2 * exp)); | |
} | |
console.log(calculate("5094162")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment