Let's break it down to simple English, shall we?
$level = pow (log10 ($post[posts]), 3);
This is a simple logarithm that will calculate the how much post a member needs in order to get to the next level. This is the engine that will control all other calculations. Now, I've cubed it so leveling resembles Final Fantasy; where the max level is 99. If you are into D&D, squaring the formula would be best, requiring a lot of post before a user can reach level 20. In short, the higher the exponent, the quicker it is to level up.
$ep = floor (100 * ($level - floor ($level)));
This is the basis for the Experience system. What i did here, was take the remainder (or mod) from the Level logarithm and converted it to a percentage. I wasnt sure if PHP had a MOD function, so I did it the hard way.
$showlevel = floor ($level + 1);
I cant have a user with level zero, but i didnt want to affect the engine with a false number either. So, I created another variable $showlevel and added 1, which will only be used to show users, and wont affect the calculations.
$hpmulti =round ($postsperday / 6, 1);
if ($hpmulti > 1.5) {
$hpmulti = 1.5;
}
if ($hpmulti < 1) {
$hpmulti = 1;
}
This code here was to add to the randomness. This is my HP bonus multiplier. I took the post per day and divided by six and rounded it to the tenths decimal. I use a few IF functions to prevent it from being too high and too low.
$maxhp = $level * 25 * $hpmulti;
Determins the Max HP. Not much to be said here, 25 just seem to be a nice number.
$hp= $postsperday / 10;
If a person couldnt perform a ten post per day average, HP will drop.
if ($hp >= 1) {
$hp= $maxhp;
} else {
$hp= floor ($hp * $maxhp);
}
Sets the limit on how high your HP will go. Keeps it at or under the Max HP
$hp= floor ($hp);
$maxhp= floor ($maxhp);
HP calcualations are down. Rounding down for viewing sake.
if ($maxhp <= 0) {
$zhp = 1;
} else {
$zhp = $maxhp;
}
Debugs the Divide by Zero error.
$hpf= floor (100 * ($hp / $zhp)) - 1;
Is used in the templates.
$maxmp= ($jointime * $level) / 5;
Determins Max MP. Again, the 5 just seems right.
$mp= $post[posts] / 3;
Determins MP, not sure why I chose to do what I did, but it works. This is the reason why MP is still a mystery to my members and even to me.
if ($mp >= $maxmp) {
$mp = $maxmp;
}
Keeps MP from going above its max.
$maxmp = floor ($maxmp);
$mp = floor ($mp);
MP calculations done. Rounding down.
if ($maxmp <= 0) {
$zmp = 1;
} else {
$zmp = $maxmp;
}
Debugs the divide by zero error.
$mpf= floor (100 * ($mp / $zmp)) - 1;
Is used in the templates.
|