<?php
require_once ("data_class.php");
class Creature extends Data {
function Init() {
$this->GetUserData();
}
function NextLevel() {
$qc = mysql_query("SELECT hp FROM creatures_data WHERE id = '".$this->creature[creature_id]."'");
$this->base = mysql_fetch_assoc($qc);
$this->expNeeded = ceil(($this->base[hp] * ($this->creature[level] * $this->creature[level])) * (1.79 + ($this->creature[level] / 10)));
if ($this->creature[exp] >= $this->expNeeded) {
$u = mysql_query("
UPDATE player_creatures SET level = level + 1, skillpoints = skillpoints + 3 WHERE user_id = '".$_SESSION["id"]."'
");
$this->Init();
if ($this->creature[skillpoints] > 0) {
$this->exp = $this->expNeeded . " (<a href='?o=level'><b><font color='red'><blink>+up</blink></font></b></a>)";
}
else {
$this->exp = $this->expNeeded;
}
} else {
if ($this->creature[skillpoints] > 0) {
$this->exp = $this->expNeeded . " (<a href='?o=level'><b><font color='red'><blink>+up</blink></font></b></a>)";
}
else {
$this->exp = $this->expNeeded;
}
}
}
function CreatureDetails () {
$this->Init();
//treba iskalkulirati slijedeci level za XP, pa pozivamo funkciju koja to radi :)
$this->NextLevel();
echo "<table align='left' width='280' border='0'><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;' colspan='2'><b>".$this->creature[name]."</b> (<a href='?o=cudoviste'><i>Edit</i></a>)</td></tr><tr>";
echo "<td>Class:</td>";
echo "<td>".$this->creature[type]."</td></tr><tr>";
echo "<td>HP:</td>";
echo "<td>".$this->creature[hp]."</td></tr><tr>";
echo "<td>Speed:</td>";
echo "<td>".$this->creature[speed]."</td></tr><tr>";
echo "<td>ATT:</td>";
echo "<td>".$this->creature[att]."</td></tr><tr>";
echo "<td>DEF:</td>";
echo "<td>".$this->creature[def]."</td></tr><tr>";
echo "<td>Level:</td>";
echo "<td>".$this->creature[level]."</td></tr><tr>";
echo "<td>XP:</td>";
echo "<td>".$this->creature[exp]."/".$this->exp."</td></tr><tr>";
echo "<td>Gold:</td>";
echo "<td>".$this->creature[gold]." coins</td></tr><tr>";
echo "<td colspan='2' style='margin-bottom: 2px; border-bottom: 1px solid #ccc; border-top: 1px solid #ccc;'>Activities...</td></tr><tr>";
echo "<td colspan='2'><b>Currently:</b></td></tr><tr>";
echo "<td colspan='2'>".$this->creature[current_action]."</td>";
echo "</tr></table>";
}
function ShowSkills() {
$this->Init();
$i = 1;
while ($i <= $this->max) {
echo "<tr><td>". $this->skill[$i][name] ." <a href='' title='header=[Skill info] body=[".$this->skill[$i][name]."<br />".$this->skill[$i][effect]."]'>[?]</a></td></tr>";
$i++;
}
} //
function CreatureSkills() {
$this->Init();
echo "<table width='280' align='right' border='0'>";
echo "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature info: </td></tr>";
echo "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>".$this->creature[description]."</td></tr>";
echo "<tr><td>Total skills: $this->max</td></tr>";
echo "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Latest skills: (<a href='?o=skills'><b><i>View all</i></b></a>)</td></tr>";
$s = mysql_query("SELECT * FROM skills WHERE creature_id = '".$this->creature[id]."' AND level <= '".$this->creature[level]."' ORDER BY id DESC LIMIT 5");
$this->max = mysql_num_rows($s);
if ($this->max > 0) {
$i = 1;
while ($i <= $this->max) {
$this->skill[$i] = mysql_fetch_assoc($s);
$i++;
}
$this->ShowSkills();
}
else {
echo "<tr><td>This creature has no special skills yet.</td></tr>";
}
echo "</tr></table>";
} //
function EditCreature() {
$this->Init();
if (isset($_POST["scname"]) && $_POST["scname"] == 'Change name' && !empty($_POST["cname"])) {
$cname = mysql_real_escape_string($_POST["cname"]);
$u = mysql_query("UPDATE player_creatures SET name = '$cname' WHERE user_id = '".$_SESSION['id']."'");
$value = $cname;
} else {$value = $this->creature[name]; $msg = $this->creature[current_action];}
echo "<form action='?o=cudoviste' method='post'";
echo "<table width='280' align='left' border='0'><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature details: </td></tr><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature name: <input type='text' name='cname' value='$value'/></td></tr><tr>";
//echo "<td>Custom 'current action' message:<br /><input type='text' name='cmsg' value='$msg'/ style='width: 250px;'></td></tr><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'><input type='submit' value='Change details' name='scname' /></td>";
echo "</tr></table>";
echo "</form>";
}
function LevelUp ($attribute) {
if ($this->creature[skillpoints] > 0) {
if ($attribute == 'speed') {
$u = mysql_query("UPDATE player_creatures SET $attribute = $attribute + 0.2, skillpoints = skillpoints - 1 WHERE user_id = '".$_SESSION['id']."'");
} else {
$u = mysql_query("UPDATE player_creatures SET $attribute = $attribute + 1, skillpoints = skillpoints - 1 WHERE user_id = '".$_SESSION['id']."'");
}
} else {
echo "<tr><td colspan='2'><b><blink>You have no skillpoints to distribute!</blink></b></td></tr>";
}
}
function SkillsDetail () {
$this->Init();
$s = mysql_query("SELECT * FROM skills WHERE creature_id = '".$this->creature[id]."' AND level <= '".$this->creature[level]."' ORDER BY id DESC LIMIT 5");
$this->max = mysql_num_rows($s);
if ($this->max > 0) {
$i = 1;
while ($i <= $this->max) {
$this->skill[$i] = mysql_fetch_assoc($s);
$i++;
}
}
else {
echo "<table align='center' width='300' border='0'><tr>";
echo "<td>This creature has<br />no special skills yet.</td>";
echo "</tr></table>";
}
echo "<table width='280' align='left' border='0'><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature info: </td></tr><tr>";
echo "<td>Total skills: $this->max</td></tr><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>All skills:</td></tr><tr>";
$i = 1;
while ($i <= $this->max) {
echo "<td>". $this->skill[$i][name] ." <a href='' title='header=[Skill info] body=[".$this->skill[$i][name]."<br />".$this->skill[$i][effect]."]'>[?]</a></td></tr><tr>";
$i++;
}
echo "</tr></table>";
}
function LevelInfo() {
echo "<table width='280' align='left' border='0'><tr>";
if (isset($_GET["u"]) && $_GET["u"] == 'att' && $_GET["o"] == 'level') {
$a = 'att';
$this->LevelUp($a);
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Attack + 1</td></tr><tr>";
}
else if (isset($_GET["u"]) && $_GET["u"] == 'def' && $_GET["o"] == 'level') {
$a = 'def';
$this->LevelUp($a);
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Defence + 1</td></tr><tr>";
}
else if (isset($_GET["u"]) && $_GET["u"] == 'sp' && $_GET["o"] == 'level') {
$a = 'speed';
$this->LevelUp($a);
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Speed + 0,2</td></tr><tr>";
} else {
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Level up</td></tr><tr>";
}
$this->Init();
$this->points = $this->creature[skillpoints];
if ($this->points <= 0) {
$la = "(<i>+</i>)";
$ld = "(<i>+</i>)";
$ls = "(<i>+</i>)";
} else {
$la = "(<a href='?o=level&u=att'><b>+</b></a>)";
$ld = "(<a href='?o=level&u=def'><b>+</b></a>)";
$ls = "(<a href='?o=level&u=sp'><b>+</b></a>)";
}
echo "<td>Total exp: ". $this->creature[exp] ."</td></tr><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Total points: ". $this->points ."</td></tr><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature attributes:</td></tr><tr>";
echo "<td>Attack: ". $this->creature[att] ." $la</td></tr><tr>";
echo "<td>Defence: ". $this->creature[def] ." $ld</td></tr><tr>";
echo "<td>Speed: ". $this->creature[speed] ." $ls<br /><br />
*Note: with one point you can increase speed only by 0.2</td></tr><tr>";
echo "</tr></table>";
} // function
function DrawGUI() {
$this->CreatureDetails();
$this->CreatureSkills();
}
} // end class
?>