EXP Calculator

Here is an old project that I worked on a long while back when I was still teaching myself PHP/SQL. An MMO that I used to play, Ragnarok Online, changed the system for gaining Experience points. Your EXP gained was relative to the level of the enemy killed, which directed players to hunt certain monsters. Problem was, there was no list or direction of where to go. Countless players on forums asked questions "where do I level now?" so I ended up making this, purely for myself at the time, then showed a friend, who showed a friend and then almost everyone in the game started using it! It's nothing special but a lot of people found it very useful. I know it could be optimized a LOT and yes I know it uses an outdated method of SQL Injection prevention.. but I haven't played the game in nearly 10 years and to be honest I'm not sure how many people even use the site any more!

<?

//receive the level from the text box
$level=mysql_real_escape_string($_POST['level']);

//receive all the race stuff
$formless=$_POST['formless'];
$undead=$_POST['undead'];
$brute=$_POST['brute'];
$plant=$_POST['plant'];
$insect=$_POST['insect'];
$fish=$_POST['fish'];
$demon=$_POST['demon'];
$demihuman=$_POST['demihuman'];
$angel=$_POST['angel'];
$dragon=$_POST['dragon'];

//receive all the element stuff
$neutral=$_POST['neutral'];
$water=$_POST['water'];
$earth=$_POST['earth'];
$fire=$_POST['fire'];
$wind=$_POST['wind'];
$poison=$_POST['poison'];
$holy=$_POST['holy'];
$shadow=$_POST['shadow'];
$ghost=$_POST['ghost'];
$eundead=$_POST['eundead'];

$farmable=$_POST['farmable'];
$timed=$_POST['timed'];

$yellow=$_POST['yellow'];

//if we dont get any post info, we can assume its the first time loading the page. and we need to initiate the data
//initiate all the post stuff as true so it starts off checked
if(empty($formless))
{
$formless=true;
$undead=true;
$brute=true;
$plant=true;
$insect=true;
$fish=true;
$demon=true;
$demihuman=true;
$angel=true;
$dragon=true;
$neutral=true;
$water=true;
$earth=true;
$fire=true;
$wind=true;
$poison=true;
$holy=true;
$shadow=true;
$ghost=true;
$eundead=true;
$timed=false;
$farmable=false;
$yellow=false;
}

//this is all the search features
echo "\n";
if($formless == true)
echo " Formless \n";
else
echo " Formless \n";

if($undead == true)
echo " Undead \n";
else
echo " Undead \n";

if($brute == true)
echo " Brute \n";
else
echo " Brute \n";

if($plant == true)
echo " Plant \n";
else
echo " Plant \n";

if($insect == true)
echo " Insect \n";
else
echo " Insect \n";

if($fish == true)
echo " Fish \n";
else
echo " Fish \n";

if($demon == true)
echo " Demon \n";
else
echo " Demon \n";

if($demihuman == true)
echo " Demi-Human \n";
else
echo " Demi-Human \n";

if($angel == true)
echo " Angel \n";
else
echo " Angel \n";

if($dragon == true)
echo " Dragon \n";
else
echo " Dragon \n";

//more search functions
if($neutral == true)
echo " Neutral \n";
else
echo " Neutral \n";

if($water == true)
echo " Water \n";
else
echo " Water \n";

if($earth == true)
echo " Earth \n";
else
echo " Earth \n";

if($fire == true)
echo " Fire \n";
else
echo " Fire \n";

if($wind == true)
echo " Wind \n";
else
echo " Wind \n";

if($poison == true)
echo " Poison \n";
else
echo " Poison \n";

if($holy == true)
echo " Holy \n";
else
echo " Holy \n";

if($shadow == true)
echo " Shadow \n";
else
echo " Shadow \n";

if($ghost == true)
echo " Ghost \n";
else
echo " Ghost \n";

if($eundead == true)
echo " Undead \n";
else
echo "\n";

//misc features
if($farmable == true)
echo " Include MVPs/Plants/Ghosts \n";
else
echo " Include MVPs/Plants/Ghosts \n";

if($timed == true)
echo " Include Miniboss/Timed Spawn/Quest Monsters \n";
else
echo " Include Miniboss/Timed Spawn/Quest Monsters \n";

//exp multiplier
echo "EXP Modifiers";
echo " Premium\n";
echo " Battle Manual\n";
echo " HE Manual\n";

echo "Your Level: \n";
echo "Search Range: \n";

if($yellow == true)
echo " Include Low-End Monsters\n";
else
echo " Include Low-End Monsters\n";

echo "\n";

//get the exp modifiers
if ($_POST['premium']==true)
$premium=1.5;
else
$premium=1.0;

if ($_POST['manual']==bm)
$expmod=1.5;
else if ($_POST['manual']==he)
$expmod=2.0;
else
$expmod=1.0;

//insert values as min/max
$levelLimit=mysql_real_escape_string($_POST['levelLimit']);
$max_level=$level+$levelLimit;
$min_level=$level-$levelLimit;

if ($levelLimit==null)
{
$max_level=$level+150;
$min_level=$level-150;
}

//this determines if we want to include the non-farmable stuff
if ($farmable=="true")
$sql_farmable="AND (farmable='0' OR farmable='1')";
else
$sql_farmable="AND (farmable='1')";

//this determines if we want to include the timed spawn stuff
if ($timed=="true")
$sql_timed="AND (timed_spawn='0' OR timed_spawn='1')";
else
$sql_timed="AND (timed_spawn='0')";

$race = " AND (race='".$formless."' OR race='".$undead."' OR race='".$brute."' OR race='".$plant."' OR race='".$insect."' OR race='".$fish."' OR race='".$demon."' OR race='".$demihuman."' OR race='".$angel."' OR race='".$dragon."')";
$element = " AND (element='".$neutral."' OR element='".$water."' OR element='".$earth."' OR element='".$fire."' OR element='".$wind."' OR element='".$poison."' OR element='".$holy."' OR element='".$shadow."' OR element='".$ghost."' OR element='".$eundead."')";

//mainly for debugging - shows the search values
//echo "Level: $level, Race: , Element: , Farmable: $farmable";

//function for receiving the query, the multiplier, the colour and outputting stuff
function outputData($sql,$mod,$colour,$premium,$expmod)
{
$rs = mysql_query($sql) or die('Action failed: ' . mysql_error());

while ($row = mysql_fetch_assoc($rs))
{
echo "$row[name]\n";
echo "$row[level]\n";
$exp_adj=floor(floor(floor($row[exp]*$premium)*$mod)*$expmod);
echo "$exp_adj\n";
$job_adj=floor(floor(floor($row[job]*$premium)*$mod)*$expmod);
echo "$job_adj\n";
echo "$row[hp]\n";
echo "$row[attack] ~ $row[attack2]\n";
echo "$row[race]\n";
echo "$row[element] $row[element_level]\n";
echo "$row[def]\n";
echo "$row[mdef]\n";
echo "$row[hit]\n";
echo "$row[flee]\n";
$ratio=number_format($exp_adj/$row[hp], 2, '.', '');
echo "$ratio\n";
$jratio=number_format($job_adj/$row[hp], 2, '.', '');
echo "$jratio\n";
}
}

//This is putting the table header together
echo "\n";
echo "Monster\n";
echo "Level\n";
echo "EXP\n";
echo "Job\n";
echo "HP\n";
echo "Attack\n";
echo "Race\n";
echo "Element\n";
echo "DEF\n";
echo "MDEF\n";
echo "Hit\n";
echo "Flee\n";
echo "EXP per HP\n";
echo "JEXP per HP\n";

//select all from db where level > 16
$level_target=$level+15;
$sql = "SELECT * FROM monsters WHERE level>'$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,0.40,"red",$premium,$expmod);

//select all where level = level+15
$level_target=$level+15;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.15,"blue",$premium,$expmod);

//select all where level = level+14
$level_target=$level+14;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.20,"blue",$premium,$expmod);

//select all where level = level+13
$level_target=$level+13;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.25,"blue",$premium,$expmod);

//select all where level = level+12
$level_target=$level+12;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.30,"blue",$premium,$expmod);

//select all where level = level+11
$level_target=$level+11;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.35,"blue",$premium,$expmod);

//select all where level = level+10
$level_target=$level+10;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.40,"blue",$premium,$expmod);

//select all where level = level+9
$level_target=$level+9;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.35,"blue",$premium,$expmod);

//select all where level = level+8
$level_target=$level+8;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.30,"blue",$premium,$expmod);

//select all where level = level+7
$level_target=$level+7;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.25,"blue",$premium,$expmod);

//select all where level = level+6
$level_target=$level+6;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.20,"blue",$premium,$expmod);

//select all where level = level+5
$level_target=$level+5;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.15,"blue",$premium,$expmod);

//select all where level = level+4
$level_target=$level+4;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.10,"blue",$premium,$expmod);

//select all where level = level+3
$level_target=$level+3;
$sql = "SELECT * FROM monsters WHERE level='$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.05,"blue",$premium,$expmod);

//select all where level between level+2 and level-5
$level_target=$level+3;
$level_target_max=$level-6;
$sql = "SELECT * FROM monsters WHERE level<'$level_target' AND level>'$level_target_max' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,1.00,"green",$premium,$expmod);

if ($yellow=="on")
{
//select all where level between level-6 and level-10
$level_target=$level-5;
$level_target_max=$level-11;
$sql = "SELECT * FROM monsters WHERE level<'$level_target' AND level>'$level_target_max' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,0.95,"orange",$premium,$expmod);

//select all where level between level-11 and level-15
$level_target=$level-10;
$level_target_max=$level-16;
$sql = "SELECT * FROM monsters WHERE level<'$level_target' AND level>'$level_target_max' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,0.90,"orange",$premium,$expmod);

//select all where level between level-16 and level-20
$level_target=$level-15;
$level_target_max=$level-21;
$sql = "SELECT * FROM monsters WHERE level<'$level_target' AND level>'$level_target_max' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,0.85,"orange",$premium,$expmod);

//select all where level between level-21 and level-25
$level_target=$level-20;
$level_target_max=$level-26;
$sql = "SELECT * FROM monsters WHERE level<'$level_target' AND level>'$level_target_max' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,0.60,"orange",$premium,$expmod);

//select all where level between level-26 and level-30
$level_target=$level-25;
$level_target_max=$level-31;
$sql = "SELECT * FROM monsters WHERE level<'$level_target' AND level>'$level_target_max' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,0.35,"orange",$premium,$expmod);

//select all where level less than level-30
$level_target=$level-30;
$sql = "SELECT * FROM monsters WHERE level<'$level_target' AND level<='$max_level' AND level>='$min_level' $race $element $sql_farmable $sql_timed ORDER BY level DESC";
outputData($sql,0.10,"orange",$premium,$expmod);
}

?>