Last active
July 15, 2020 18:52
-
-
Save bbSnavy/eaed3a7b8e2592b43befe9625e5d8c1e to your computer and use it in GitHub Desktop.
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
import numpy, math, random | |
class ILeveling(): | |
def __init__(self): | |
self.EXP_FIELD = "networkExp" | |
self.LVL_FIELD = "networkLevel" | |
self.BASE = 10_000 | |
self.GROWTH = 2_500 | |
# Constants to generate the total amount of XP to complete a level | |
self.HALF_GROWTH = 0.5 * self.GROWTH | |
# Constants to look up the level from the total amount of XP | |
self.REVERSE_PQ_PREFIX = -(self.BASE - 0.5 * self.GROWTH) / self.GROWTH | |
self.REVERSE_CONST = self.REVERSE_PQ_PREFIX * self.REVERSE_PQ_PREFIX | |
self.GROWTH_DIVIDES_2 = 2 / self.GROWTH | |
def getLevel(self, exp): | |
return math.floor(1 + self.REVERSE_PQ_PREFIX + math.sqrt(self.REVERSE_CONST + 0.0008 * exp)) if exp > 0 else 1 | |
def getExactLevel(self, exp): | |
return self.getLevel(exp) + self.getPercentageToNextLevel(exp) | |
def getExpFromLevelToNext(self, level): | |
return self.BASE if level < 1 else self.GROWTH * (level - 1) + self.BASE | |
def getTotalExpToLevel(self, level): | |
lv = math.floor(level) | |
x0 = self.getTotalExpToFullLevel(lv) | |
if level == lv: | |
return x0 | |
return (self.getTotalExpToFullLevel(lv + 1) - x0) * (level % 1) + x0 | |
def getTotalExpToFullLevel(self, level): | |
return (self.HALF_GROWTH * (level - 2) + self.BASE) * (level - 1) | |
def getPercentageToNextLevel(self, exp): | |
lv = self.getLevel(exp) | |
x0 = self.getTotalExpToLevel(lv) | |
return (exp - x0) / (self.getTotalExpToLevel(lv + 1) - x0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment