[ad_1]
I am developing mobile game and I am stuck on an issue regarding proper player stats scaling based on level.
As a parameters for the computation we have:
- base XP value
- multiple increment values (for example one increment for levels 1-5, another one for 6-10 and so on…)
We are using this formula:
current level XP = previous Level XP + (previous level XP ^ increment)
.
Let’s break it down on an example:
We want to get the XP threshold to graduate from level 3. The base XP value is 100, increment for levels 1-5 is 0.5.
To get the needed XP, we first need to get the value for level 2:
level2Value = 100 + 100^0.5
Now we have stat value for level 2 and we are able to get level3Value
like this:
level3Value = level2Value + level2Value^0.5.
If we had to calculate values for some high levels, this seems like a rather inefficient way to do things, as values for all previous levels must be computed prior, and in addition we are changing the increment value based on level – we cannot simple have one line of formula which gets us the number that we wan; all is dependent on previous values.
Of course we can compute all previous values, cache it on the server and then do the lookup to the data, but we would like to avoid it if possible – still I have a feeling that there must be better way to deal with this problem.
My question is the following:
Can you suggest some other (similar) formulas or ways to compute this? Ideally just one line of code should do the trick (something like `level X XP = X * baseXp * increment|, but more complex which allows usage of different increment values)
[ad_2]