<?php
/*
* This file is part of 'Crown of Evanion'.
*
* 'Crown of Evanion' is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 'Crown of Evanion' is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 'Crown of Evanion'; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$title = "My Dragon";
include("include.php");
if($Username != "") {
if($stage >= 2) {
$page = $_REQUEST['page'];
echo "<div align=\"center\"><p class=\"drag\"><a href=$PHP_SELF>Overview</a> | <a href=$PHP_SELF?page=attack>Attack</a> | <a href=$PHP_SELF?page=equip>Equipment</a></p></div>";
$errors = array(
'1' => "<h5>You cannot attack someone if your dragon has no HP!</h5>",
'2' => "<h5>The Dragon you wanted to attack was not found.</h5>",
'3' => "<h5>You did not fill in a Dragon to attack!</h5>",
'4' => "<h5>You cannot attack an enemy with 0 health.</h5>",
);
if(! $page) {
echo "
<div class=\"drag\">
<div align=\"center\">
$errors[$error]
<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"150\" height=\"150\" id=\"egg\" align=\"middle\">
<param name=\"allowScriptAccess\" value=\"sameDomain\" />
<param name=\"movie\" value=\"$DragImage\" />
<param name=\"quality\" value=\"high\" />
<param name=\"bgcolor\" value=\"#ffffff\" />
<embed src=\"$DragImage\" quality=\"high\" bgcolor=\"#ffffff\" width=\"150\" height=\"150\" name=\"egg\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />
</object>
</div>
<p><strong>Name:</strong> $Dragon</p>
<p><strong>Gender:</strong> $DragGen</p>
<p><strong>Age:</strong> $DragLevel[$stage]</p>
<p><strong>Health:</strong> $HP / $MaxHP</p>
<p><strong>Hunger:</strong> $DragHung[$hunger]</p>
<p><strong>Happiness:</strong> $DragFun[$fun]</p>
<p><strong>Strength:</strong> $DragStren</p>
<p><strong>Toughness:</strong> $DragTough</p>
</div>
";
}
if($page == "attack") {
$select = mysql_query("SELECT * FROM attacks WHERE level <= '$stage' ORDER BY id ASC");
echo "<UL id=\"ops\">";
while ($attacks = mysql_fetch_array($select)) {
echo "<li><a href=$PHP_SELF?page=assultsel&id=$attacks[id]>$attacks[name]</a></li>";
}
}
if($page == "assultsel" && $id != "") {
$id = $_REQUEST['id'];
if($HP == 0) {
header("location: $PHP_SELF?error=1");
include ("footer.php");
die;
}
$select = mysql_query("SELECT * FROM attacks WHERE id = '$id'");
$attack = mysql_fetch_array($select);
if($attack[level] <= $stage) {
echo "<div align=\"center\">
What Dragon would you like to $attack[name]?
<form action=\"$PHP_SELF\" method=\"POST\">
<input type=\"hidden\" name=\"page\" value=\"assult\">
<input type=\"hidden\" name=\"id\" value=\"$id\">
<input type=\"text\" name=\"who\">
<input type=\"submit\" value=\"$attack[name]!\"
</div>
";
} else {
echo "<h2>You do not have access to this attack!";
}
}
if($page == "assult") {
$who = $_POST['who'];
$id = $_POST['id'];
if(!$who) {
header("location: $PHP_SELF?error=3");
include("footer.php");
die;
}
if($who == $Dragon) {
header("location: $PHP_SELF?page=assultsel&id=$id");
include("footer.php");
die;
}
if(!$id) {
header("location: $PHP_SELF?page=attack");
include("footer.php");
die;
}
if($HP == 0) {
header("location: $PHP_SELF?error=1");
include ("footer.php");
die;
}
$select = mysql_query("SELECT * FROM attacks WHERE id = '$id'");
$attack = mysql_fetch_array($select);
if($attack[level] <= $stage) {
$select = mysql_query("SELECT * FROM dragons WHERE name LIKE '$who'");
$num = mysql_num_rows($select);
} else {
echo "<h2>You do not have access to this attack.</h2>";
}
if($num == 0) {
header("location: $PHP_SELF?error=2");
include("footer.php");
die;
}
$enemy = mysql_fetch_array($select);
if($enemy[health] <= 0) {
header("location: $PHP_SELF?error=4");
include("footer.php");
die;
}
$select = mysql_query("SELECT defense FROM items WHERE id = '$enemy[armor]'");
$enarm = mysql_fetch_array($select);
$AS = $attack[damage];
$DS = round($DragStren / 2);
$ET = round($enemy[tough] / 1.5);
$EA = $enarm[defense];
$dam1 = $AS+$DS;
$dam2 = $ET+$EA;
$dam = $dam1-$dam2;
if($dam < 0) {
$dam = 0;
}
$select = mysql_query("SELECT id,dragon FROM users WHERE dragon = '$who'");
$wtf = mysql_fetch_array($select);
mysql_query("UPDATE dragons SET health = health-$dam WHERE name = '$enemy[name]'");
mysql_query("INSERT INTO event (foruser,text) VALUES ('$wtf[id]','$wtf[dragon] has been attacked by $Dragon, doing $dam damage.')");
$select = mysql_query("SELECT health FROM dragons WHERE name = '$who'");
$final = mysql_fetch_array($select);
if($final[health] < 0) {
mysql_query("UPDATE dragons SET health = '0' WHERE name = '$who'");
}
echo "You have done $dam damage to $who.";
}
} else {
echo "<h2>You do not have access to this page!</h2>";
}
if($page == "equip" && $id == "") {
if(!$DragArmor) {
echo "You have no armor equipped.";
} else {
$select = mysql_query("SELECT * FROM items WHERE id = '$DragArmor'");
$arm = mysql_fetch_array($select);
echo "<div align=\"center\">
<div class=\"itemdesc\">
<div align=\"center\">
<img src=\"$arm[image]\" alt=\"$arm[name]\" width=\"90\" height=\"90\" border=\"0\">
</div>
<p class=\"name\"><strong>Armor:</strong> $arm[name]</p>
<p><strong>Protection:</strong> $arm[defense]</p>
<p><a href=$PHP_SELF?page=equip&id=$DragArmor>Unequip Armor</a></p>
</div>
</div>";
}
}
if($page == "equip" && $id != "") {
if(!$DragArmor) {
echo "No armor to unequip!";
} else {
mysql_query("INSERT INTO useritems (itemid,owner) VALUES ('$DragArmor','$UserID')");
mysql_query("UPDATE dragons SET armor = '0' WHERE name = '$Dragon'");
echo "The armor has been removed from $Dragon and returned to your inventory.";
}
}
} else {
header("location: login.php");
}
include("footer.php");
?>