How to convert treasure wars xp to levels (using python)

So, while I was waiting for my account to get verified, I was making a hive API (discord) bot. I was looking through the forums and noticed no one had given an explanation on how to do this. So, I plan on making a post on how to do this in python (I’ll probably edit this to other languages later on.). The variable you are going to need for this is xp. Below is the code.

if xp >= 198900:
        exactlevel = (xp-198900)/7650 + 52
    else:
        xps = [0, 150]
        x = 150
        y = 150
        for i in range(50):
            x = x+150
            y = int(x + y)
            xps.append(y)
            i += 1
        for i in range(len(xps)):
            if xp > xps[i]:
                exactlevel = i + float(xp - xps[i-1]) / (xps[i] - xps[i-1])

I mean I might as well add java now that I’m here:

if xp >= 198900 {
    exactlevel = (xp-198900)/7650 + 52
}
else {
    int xps[] = new int[52]
    x = 150
    y = 150
    for (int i = 0 i =< 50; i++) {
        x += 150
        y = x+y
        xps.add(y)
    }
    for (int i = 0 i =< xps.size()) {
        exactlevel = i + (xp - xps[i-1]) / (xps[i] - xps[i-1])
    }
}

(If there’s something wrong with the java part please tell me I’m a little rusty and I coded this using the forums built in text)

3 Likes

I dont know python but if this is actually correct then good job!

1 Like