".$spellrow["name"]."\n";
}
}
if ($pagearray["magiclist"] == "") { $pagearray["magiclist"] = "\n"; }
$magiclist = $pagearray["magiclist"];
$chancetoswingfirst = 1;
// First, check to see if we need to pick a monster.
if ($userrow["currentfight"] == 1) {
if ($userrow["latitude"] < 0) { $userrow["latitude"] *= -1; } // Equalize negatives.
if ($userrow["longitude"] < 0) { $userrow["longitude"] *= -1; } // Ditto.
$maxlevel = floor(max($userrow["latitude"]+5, $userrow["longitude"]+5) / 5); // One mlevel per five spaces.
if ($maxlevel < 1) { $maxlevel = 1; }
$minlevel = $maxlevel - 2;
if ($minlevel < 1) { $minlevel = 1; }
// Pick a monster.
$monsterquery = doquery("SELECT * FROM {{table}} WHERE level>='$minlevel' AND level<='$maxlevel' ORDER BY RAND() LIMIT 1", "monsters");
$monsterrow = mysql_fetch_array($monsterquery);
$userrow["currentmonster"] = $monsterrow["id"];
$userrow["currentmonsterhp"] = rand((($monsterrow["maxhp"]/5)*4),$monsterrow["maxhp"]);
if ($userrow["difficulty"] == 2) { $userrow["currentmonsterhp"] = ceil($userrow["currentmonsterhp"] * $controlrow["diff2mod"]); }
if ($userrow["difficulty"] == 3) { $userrow["currentmonsterhp"] = ceil($userrow["currentmonsterhp"] * $controlrow["diff3mod"]); }
$userrow["currentmonstersleep"] = 0;
$userrow["currentmonsterimmune"] = $monsterrow["immune"];
$chancetoswingfirst = rand(1,10) + ceil(sqrt($userrow["dexterity"]));
if ($chancetoswingfirst > (rand(1,7) + ceil(sqrt($monsterrow["maxdam"])))) { $chancetoswingfirst = 1; } else { $chancetoswingfirst = 0; }
unset($monsterquery);
unset($monsterrow);
}
// Next, get the monster statistics.
$monsterquery = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["currentmonster"]."' LIMIT 1", "monsters");
$monsterrow = mysql_fetch_array($monsterquery);
$pagearray["monstername"] = $monsterrow["name"];
// Do run stuff.
if (isset($_POST["run"])) {
$chancetorun = rand(4,10) + ceil(sqrt($userrow["dexterity"]));
if ($chancetorun > (rand(1,5) + ceil(sqrt($monsterrow["maxdam"])))) { $chancetorun = 1; } else { $chancetorun = 0; }
if ($chancetorun == 0) {
$pagearray["yourturn"] = "You tried to run away, but were blocked in front!
";
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "
";
$pagearray["monsterturn"] = "";
if ($userrow["currentmonstersleep"] != 0) { // Check to wake up.
$chancetowake = rand(1,15);
if ($chancetowake > $userrow["currentmonstersleep"]) {
$userrow["currentmonstersleep"] = 0;
$pagearray["monsterturn"] .= "The monster has woken up.
";
} else {
$pagearray["monsterturn"] .= "The monster is still asleep.
";
}
}
if ($userrow["currentmonstersleep"] == 0) { // Only do this if the monster is awake.
$tohit = ceil(rand($monsterrow["maxdam"],(($monsterrow["maxdam"]/6)*3)));
if ($userrow["difficulty"] == 2) { $tohit = ceil($tohit * $controlrow["diff2mod"]); }
if ($userrow["difficulty"] == 3) { $tohit = ceil($tohit * $controlrow["diff3mod"]); }
$toblock = ceil(rand($userrow["defensepower"],$userrow["defensepower"]*.75)/4);
$tododge = rand(1,150);
if ($tododge <= sqrt($userrow["dexterity"])) {
$tohit = 0; $pagearray["monsterturn"] .= "You dodge the monster's attack. No damage has been scored.
";
$persondamage = 0;
} else {
$persondamage = $tohit - $toblock;
if ($persondamage < 1) { $persondamage = 1; }
if ($userrow["currentuberdefense"] != 0) {
$persondamage -= ceil($persondamage * ($userrow["currentuberdefense"]/100));
}
if ($persondamage < 1) { $persondamage = 1; }
}
$pagearray["monsterturn"] .= "The monster attacks you for $persondamage damage.
";
$userrow["currenthp"] -= $persondamage;
if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4);
$updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
$playerisdead = 1;
}
}
}
$updatequery = doquery("UPDATE {{table}} SET currentaction='Exploring' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
header("Location: index.php");
die();
// Do fight stuff.
} elseif (isset($_POST["fight"])) {
// Your turn.
$pagearray["yourturn"] = "";
$tohit = ceil(rand($userrow["attackpower"]*.75,$userrow["attackpower"])/3);
$toexcellent = rand(1,150);
if ($toexcellent <= sqrt($userrow["strength"])) { $tohit *= 2; $pagearray["yourturn"] .= "Excellent hit!
"; }
$toblock = ceil(rand($monsterrow["armor"]*.75,$monsterrow["armor"])/3);
$tododge = rand(1,200);
if ($tododge <= sqrt($monsterrow["armor"])) {
$tohit = 0; $pagearray["yourturn"] .= "The monster is dodging. No damage has been scored.
";
$monsterdamage = 0;
} else {
$monsterdamage = $tohit - $toblock;
if ($monsterdamage < 1) { $monsterdamage = 1; }
if ($userrow["currentuberdamage"] != 0) {
$monsterdamage += ceil($monsterdamage * ($userrow["currentuberdamage"]/100));
}
}
$pagearray["yourturn"] .= "You attack the monster for $monsterdamage damage.
";
$userrow["currentmonsterhp"] -= $monsterdamage;
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "
";
if ($userrow["currentmonsterhp"] <= 0) {
$updatequery = doquery("UPDATE {{table}} SET currentmonsterhp='0' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
header("Location: index.php?do=victory");
die();
}
// Monster's turn.
$pagearray["monsterturn"] = "";
if ($userrow["currentmonstersleep"] != 0) { // Check to wake up.
$chancetowake = rand(1,15);
if ($chancetowake > $userrow["currentmonstersleep"]) {
$userrow["currentmonstersleep"] = 0;
$pagearray["monsterturn"] .= "The monster has woken up.
";
} else {
$pagearray["monsterturn"] .= "The monster is still asleep.
";
}
}
if ($userrow["currentmonstersleep"] == 0) { // Only do this if the monster is awake.
$tohit = ceil(rand(($monsterrow["maxdam"]*.5),$monsterrow["maxdam"]));
if ($userrow["difficulty"] == 2) { $tohit = ceil($tohit * $controlrow["diff2mod"]); }
if ($userrow["difficulty"] == 3) { $tohit = ceil($tohit * $controlrow["diff3mod"]); }
$toblock = ceil(rand($userrow["defensepower"]*.75,$userrow["defensepower"])/4);
$tododge = rand(1,150);
if ($tododge <= sqrt($userrow["dexterity"])) {
$tohit = 0; $pagearray["monsterturn"] .= "You dodge the monster's attack. No damage has been scored.
";
$persondamage = 0;
} else {
$persondamage = $tohit - $toblock;
if ($persondamage < 1) { $persondamage = 1; }
if ($userrow["currentuberdefense"] != 0) {
$persondamage -= ceil($persondamage * ($userrow["currentuberdefense"]/100));
}
if ($persondamage < 1) { $persondamage = 1; }
}
$pagearray["monsterturn"] .= "The monster attacks you for $persondamage damage.
";
$userrow["currenthp"] -= $persondamage;
if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4);
$updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
$playerisdead = 1;
}
}
// Do spell stuff.
} elseif (isset($_POST["spell"])) {
// Your turn.
$pickedspell = $_POST["userspell"];
if ($pickedspell == 0) { display("You must select a spell first. Please go back and try again.", "Error"); die(); }
$newspellquery = doquery("SELECT * FROM {{table}} WHERE id='$pickedspell' LIMIT 1", "spells");
$newspellrow = mysql_fetch_array($newspellquery);
if ($userspells[$pickedspell] != 1) { display("You have not yet learned this spell. Please go back and try again.", "Error"); die(); }
if ($userrow["currentmp"] < $newspellrow["mp"]) { display("You do not have enough Magic Points to cast this spell. Please go back and try again.", "Error"); die(); }
if ($newspellrow["type"] == 1) { // Heal spell.
$newhp = $userrow["currenthp"] + $newspellrow["attribute"];
if ($userrow["maxhp"] < $newhp) { $newspellrow["attribute"] = $userrow["maxhp"] - $userrow["currenthp"]; $newhp = $userrow["currenthp"] + $newspellrow["attribute"]; }
$userrow["currenthp"] = $newhp;
$userrow["currentmp"] -= $newspellrow["mp"];
$pagearray["yourturn"] = "You have cast the ".$newspellrow["name"]." spell, and gained ".$newspellrow["attribute"]." Hit Points.
";
} elseif ($newspellrow["type"] == 2) { // Hurt spell.
if ($userrow["currentmonsterimmune"] == 0) {
$monsterdamage = rand((($newspellrow["attribute"]/6)*5), $newspellrow["attribute"]);
$userrow["currentmonsterhp"] -= $monsterdamage;
$pagearray["yourturn"] = "You have cast the ".$newspellrow["name"]." spell for $monsterdamage damage.
";
} else {
$pagearray["yourturn"] = "You have cast the ".$newspellrow["name"]." spell, but the monster is immune to it.
";
}
$userrow["currentmp"] -= $newspellrow["mp"];
} elseif ($newspellrow["type"] == 3) { // Sleep spell.
if ($userrow["currentmonsterimmune"] != 2) {
$userrow["currentmonstersleep"] = $newspellrow["attribute"];
$pagearray["yourturn"] = "You have cast the ".$newspellrow["name"]." spell. The monster is asleep.
";
} else {
$pagearray["yourturn"] = "You have cast the ".$newspellrow["name"]." spell, but the monster is immune to it.
";
}
$userrow["currentmp"] -= $newspellrow["mp"];
} elseif ($newspellrow["type"] == 4) { // +Damage spell.
$userrow["currentuberdamage"] = $newspellrow["attribute"];
$userrow["currentmp"] -= $newspellrow["mp"];
$pagearray["yourturn"] = "You have cast the ".$newspellrow["name"]." spell, and will gain ".$newspellrow["attribute"]."% damage until the end of this fight.
";
} elseif ($newspellrow["type"] == 5) { // +Defense spell.
$userrow["currentuberdefense"] = $newspellrow["attribute"];
$userrow["currentmp"] -= $newspellrow["mp"];
$pagearray["yourturn"] = "You have cast the ".$newspellrow["name"]." spell, and will gain ".$newspellrow["attribute"]."% defense until the end of this fight.
";
}
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "
";
if ($userrow["currentmonsterhp"] <= 0) {
$updatequery = doquery("UPDATE {{table}} SET currentmonsterhp='0',currenthp='".$userrow["currenthp"]."',currentmp='".$userrow["currentmp"]."' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
header("Location: index.php?do=victory");
die();
}
// Monster's turn.
$pagearray["monsterturn"] = "";
if ($userrow["currentmonstersleep"] != 0) { // Check to wake up.
$chancetowake = rand(1,15);
if ($chancetowake > $userrow["currentmonstersleep"]) {
$userrow["currentmonstersleep"] = 0;
$pagearray["monsterturn"] .= "The monster has woken up.
";
} else {
$pagearray["monsterturn"] .= "The monster is still asleep.
";
}
}
if ($userrow["currentmonstersleep"] == 0) { // Only do this if the monster is awake.
$tohit = ceil(rand($monsterrow["maxdam"],(($monsterrow["maxdam"]/6)*3)));
if ($userrow["difficulty"] == 2) { $tohit = ceil($tohit * $controlrow["diff2mod"]); }
if ($userrow["difficulty"] == 3) { $tohit = ceil($tohit * $controlrow["diff3mod"]); }
$toblock = ceil(rand($userrow["defensepower"],$userrow["defensepower"]*.75)/4);
$tododge = rand(1,150);
if ($tododge <= sqrt($userrow["dexterity"])) {
$tohit = 0; $pagearray["monsterturn"] .= "You dodge the monster's attack. No damage has been scored.
";
$persondamage = 0;
} else {
if ($tohit <= $toblock) { $tohit = $toblock + 1; }
$persondamage = $tohit - $toblock;
if ($userrow["currentuberdefense"] != 0) {
$persondamage -= ceil($persondamage * ($userrow["currentuberdefense"]/100));
}
if ($persondamage < 1) { $persondamage = 1; }
}
$pagearray["monsterturn"] .= "The monster attacks you for $persondamage damage.
";
$userrow["currenthp"] -= $persondamage;
if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4);
$updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
$playerisdead = 1;
}
}
// Do a monster's turn if person lost the chance to swing first. Serves him right!
} elseif ( $chancetoswingfirst == 0 ) {
$pagearray["yourturn"] = "The monster attacks before you are ready!
";
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "
";
$pagearray["monsterturn"] = "";
if ($userrow["currentmonstersleep"] != 0) { // Check to wake up.
$chancetowake = rand(1,15);
if ($chancetowake > $userrow["currentmonstersleep"]) {
$userrow["currentmonstersleep"] = 0;
$pagearray["monsterturn"] .= "The monster has woken up.
";
} else {
$pagearray["monsterturn"] .= "The monster is still asleep.
";
}
}
if ($userrow["currentmonstersleep"] == 0) { // Only do this if the monster is awake.
$tohit = ceil(rand(($monsterrow["maxdam"]*.5),$monsterrow["maxdam"]));
if ($userrow["difficulty"] == 2) { $tohit = ceil($tohit * $controlrow["diff2mod"]); }
if ($userrow["difficulty"] == 3) { $tohit = ceil($tohit * $controlrow["diff3mod"]); }
$toblock = ceil(rand($userrow["defensepower"]*.75,$userrow["defensepower"])/4);
$tododge = rand(1,150);
if ($tododge <= sqrt($userrow["dexterity"])) {
$tohit = 0; $pagearray["monsterturn"] .= "You dodge the monster's attack. No damage has been scored.
";
$persondamage = 0;
} else {
$persondamage = $tohit - $toblock;
if ($persondamage < 1) { $persondamage = 1; }
if ($userrow["currentuberdefense"] != 0) {
$persondamage -= ceil($persondamage * ($userrow["currentuberdefense"]/100));
}
if ($persondamage < 1) { $persondamage = 1; }
}
$pagearray["monsterturn"] .= "The monster attacks you for $persondamage damage.
";
$userrow["currenthp"] -= $persondamage;
if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4);
$updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
$playerisdead = 1;
}
}
} else {
$pagearray["yourturn"] = "";
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "
";
$pagearray["monsterturn"] = "";
}
$newmonster = $userrow["currentmonster"];
$newmonsterhp = $userrow["currentmonsterhp"];
$newmonstersleep = $userrow["currentmonstersleep"];
$newmonsterimmune = $userrow["currentmonsterimmune"];
$newuberdamage = $userrow["currentuberdamage"];
$newuberdefense = $userrow["currentuberdefense"];
$newfight = $userrow["currentfight"] + 1;
$newhp = $userrow["currenthp"];
$newmp = $userrow["currentmp"];
if ($playerisdead != 1) {
$pagearray["command"] = <<