<?php
require_once ("data_class.php");
class Attack extends Data {
function Init() {
$this->GetUserData();
}
function DefineAttacks() {
$at = mysql_query("
SELECT
id,
name,
opposite
FROM
attack_types
WHERE
creature = '".$this->creature[creature_id]."'
OR
creature = 0
");
$i = 1;
$this->max = mysql_num_rows($at);
while ($i <= $this->max) {
$this->attacks[$i] = mysql_fetch_assoc($at);
$i++;
}
} //
function Start() {
$this->Init();
$ch = mysql_query("SELECT * FROM creature_hunts WHERE uid = '".$_SESSION["id"]."' AND active = 1");
if (mysql_num_rows($ch) > 0) {
echo "<table align='center' width='600'><tr><td>You already have active creature hunt!<br />
<br />Check the Duel icon on right menu or go <a href='?p=duel'>back</a>!</td></tr></table>";
} else {
$this->t = $_GET["c"];
echo "<form action='?p=attack&c=$this->t' method='post'>";
echo "<input type='hidden' name='target' value='$this->t' />";
echo"<table align='left' width='280' border='0'>";
echo "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Select actions from list...</td></tr>";
$this->t = $_GET["c"];
if (empty($this->t) OR preg_match("/[^0-9]+/", $this->t)) {
echo "<td>Invalid creature specification. Please go back and try again.</td>";
exit;
}
$m = 6;
$a = 1;
if (isset($_POST["attack_creature"])) {
$this->from = time();
$this->length = $_POST["turns"] * 30;
$this->turns = $_POST["turns"];
$this->to = $this->from + $this->length;
$dif = $this->to - $this->from;
if ($dif <= 0) {$dif = 0;}
$h = mysql_query("
INSERT INTO
creature_hunts
VALUES (
'',
'".$this->creature[user_id]."',
'$this->t',
'1',
'$this->from',
'$this->to',
'',
'',
'".$_POST["skill"]."',
'',
'".$_POST["att_1_type"]."',
'".$_POST["att_2_type"]."',
'".$_POST["att_3_type"]."',
'".$_POST["att_4_type"]."',
'".$_POST["att_5_type"]."',
'".$_POST["att_6_type"]."',
'',
'',
'',
'',
'',
'',
'');
"); // end mysql_query
/*
$db = mysql_query("
UPDATE
creature_hunts
SET
uid = '".$this->creature[creature_id]."',
tid = '$this->t',
active = 1,
rfrom = '$this->from',
rto = '$this->to',
a1 = '".$_POST["att_1_type"]."',
a2 = '".$_POST["att_2_type"]."',
a3 = '".$_POST["att_3_type"]."',
a4 = '".$_POST["att_4_type"]."',
a5 = '".$_POST["att_5_type"]."',
a6 = '".$_POST["att_6_type"]."'
");
*/
if ($h) {
$p = mysql_query("UPDATE player_creatures SET current_action = 'Attacking a creature...'");
echo "<td>Your attack will be executed in $dif seconds.</td>";
$t = mysql_query("UPDATE users SET turns = turns - ".$this->turns." WHERE id = '".$_SESSION["id"]."'");
}
}
else
{
$this->DefineAttacks();
while ($a <= $m) {
echo "<tr><td>";
echo '
<select name="att_'.$a.'_type">';
echo '<option value="0">No attack</option>';
$i = 1;
while ($i <= $this->max) {
echo "<option value='".$this->attacks[$i][id]."'>".$this->attacks[$i][name]."</option>";
$i++;
}
echo "</select> | $a. action";
echo "<br /><br /></td></tr>";
$a++;
}
echo '<td><input type="submit" name="attack_creature" value="Proceed with attack" />';
}
echo '</td></tr>';
echo "</table>";
echo"<table align='right' width='280' border='0'>";
echo "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Attack length & skill choice:</td></tr>";
echo '<tr><td><br /><select name="turns">';
echo '<option value="1">1 turn</option>';
echo '<option value="2">2 turns</option>';
echo '<option value="5">5 turns</option>';
echo '<option value="10">10 turns</option>';
echo '<option value="15">15 turns</option>';
echo "</select> | # turns";
echo '</td></tr>';
echo "<tr><td><br /><select name='skill'>";
echo '<option value="0">No skill</option>';
$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++;
}
$i = 1;
while ($i <= $this->max) {
echo '<option value='. $this->skill[$i][id] .'>'. $this->skill[$i][name] .'</option>';
$i++;
}
}
echo "</select> | ? skill";
echo '</td></tr>';
echo "</table>";
}
}
}// end class
?>