$pagearray["monsterturn"].="The monster attacks you for $persondamage damage.<br /><br />";
$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");
$pagearray["monsterturn"].="The monster attacks you for $persondamage damage.<br /><br />";
$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");
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();}
$pagearray["yourturn"]="You have cast the ".$newspellrow["name"]." spell, and will gain ".$newspellrow["attribute"]."% damage until the end of this fight.<br /><br />";
$pagearray["yourturn"]="You have cast the ".$newspellrow["name"]." spell, and will gain ".$newspellrow["attribute"]."% defense until the end of this fight.<br /><br />";
$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.
$pagearray["monsterturn"].="The monster attacks you for $persondamage damage.<br /><br />";
$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!<br /><br />";
$pagearray["monsterturn"].="The monster attacks you for $persondamage damage.<br /><br />";
$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");
$updatequery=doquery("UPDATE {{table}} SET currentaction='Fighting',currenthp='$newhp',currentmp='$newmp',currentfight='$newfight',currentmonster='$newmonster',currentmonsterhp='$newmonsterhp',currentmonstersleep='$newmonstersleep',currentmonsterimmune='$newmonsterimmune',currentuberdamage='$newuberdamage',currentuberdefense='$newuberdefense' WHERE id='".$userrow["id"]."' LIMIT 1","users");
}else{
$pagearray["command"]="<b>You have died.</b><br /><br />As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br /><br />You may now continue back to <a href=\"index.php\">town</a>, and we hope you fair better next time.";
if($userrow["experience"]+$exp<16777215){$newexp=$userrow["experience"]+$exp;$warnexp="";}else{$newexp=$userrow["experience"];$exp=0;$warnexp="You have maxed out your experience points.";}
if($userrow["gold"]+$gold<16777215){$newgold=$userrow["gold"]+$gold;$warngold="";}else{$newgold=$userrow["gold"];$gold=0;$warngold="You have maxed out your experience points.";}
$page="Congratulations. You have defeated the ".$monsterrow["name"].".<br />You gain $exp experience. $warnexp <br />You gain $gold gold. $warngold <br /><br /><b>You have gained a level!</b><br /><br />You gain ".$levelrow[$userrow["charclass"]."_hp"]." hit points.<br />You gain ".$levelrow[$userrow["charclass"]."_mp"]." magic points.<br />You gain ".$levelrow[$userrow["charclass"]."_tp"]." travel points.<br />You gain ".$levelrow[$userrow["charclass"]."_strength"]." strength.<br />You gain ".$levelrow[$userrow["charclass"]."_dexterity"]." dexterity.<br />$spelltext<br />You can now continue <a href=\"index.php\">exploring</a>.";
$page="Congratulations. You have defeated the ".$monsterrow["name"].".<br />You gain $exp experience. $warnexp <br />You gain $gold gold. $warngold <br /><br />";
$dropquery=doquery("SELECT * FROM {{table}} WHERE mlevel <= '".$monsterrow["level"]."' ORDER BY RAND() LIMIT 1","drops");
$droprow=mysql_fetch_array($dropquery);
$dropcode="dropcode='".$droprow["id"]."',";
$page.="This monster has dropped an item. <a href=\"index.php?do=drop\">Click here</a> to reveal and equip the item, or you may also move on and continue <a href=\"index.php\">exploring</a>.";
}else{
$dropcode="";
$page.="You can now continue <a href=\"index.php\">exploring</a>.";
}
$title="Victory!";
}
}
$updatequery=doquery("UPDATE {{table}} SET currentaction='Exploring',level='$newlevel',maxhp='$newhp',maxmp='$newmp',maxtp='$newtp',strength='$newstrength',dexterity='$newdexterity',attackpower='$newattack',defensepower='$newdefense', $newspell currentfight='0',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentuberdamage='0',currentuberdefense='0',$dropcode experience='$newexp',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1","users");
$query=doquery("UPDATE {{table}} SET slot".$_POST["slot"]."name='$newname',slot".$_POST["slot"]."id='".$droprow["id"]."',$old1[0]='".$userrow[$old1[0]]."',$old2[0]='".$userrow[$old2[0]]."',$new1[0]='".$userrow[$new1[0]]."',$new2[0]='".$userrow[$new2[0]]."',attackpower='".$userrow["attackpower"]."',defensepower='".$userrow["defensepower"]."',currenthp='".$userrow["currenthp"]."',currentmp='".$userrow["currentmp"]."',currenttp='".$userrow["currenttp"]."',dropcode='0' WHERE id='".$userrow["id"]."' LIMIT 1","users");
$query=doquery("UPDATE {{table}} SET slot".$_POST["slot"]."name='$newname',slot".$_POST["slot"]."id='".$droprow["id"]."',$new1[0]='".$userrow[$new1[0]]."',$new2[0]='".$userrow[$new2[0]]."',attackpower='".$userrow["attackpower"]."',defensepower='".$userrow["defensepower"]."',dropcode='0' WHERE id='".$userrow["id"]."' LIMIT 1","users");
}
$page="The item has been equipped. You can now continue <a href=\"index.php\">exploring</a>.";
display($page,"Item Drop");
}
$attributearray=array("maxhp"=>"Max HP",
"maxmp"=>"Max MP",
"maxtp"=>"Max TP",
"defensepower"=>"Defense Power",
"attackpower"=>"Attack Power",
"strength"=>"Strength",
"dexterity"=>"Dexterity",
"expbonus"=>"Experience Bonus",
"goldbonus"=>"Gold Bonus");
$page="The monster dropped the following item: <b>".$droprow["name"]."</b><br /><br />";
$page.="This item has the following attribute(s):<br />";
$page.="<br />Select an inventory slot from the list below to equip this item. If the inventory slot is already full, the old item will be discarded.";
$page.="You may also choose to just continue <a href=\"index.php\">exploring</a> and give up this item.";
display($page,"Item Drop");
}
functiondead(){
$page="<b>You have died.</b><br /><br />As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br /><br />You may now continue back to <a href=\"index.php\">town</a>, and we hope you fair better next time.";