Файл: army.php
Строк: 286
<?php
require 'sys/sid.php';
require 'sys/config.php';
include 'sys/user.php';
include 'sys/head.php';
visit(0, 'army');
$do = isset($_GET['do']) ? $_GET['do'] : NULL;
switch($do)
{
default:
if (isset($_GET['run']))
{
$run = number($_GET['run']);
$tst = mysql_query("SELECT * FROM duty WHERE user = '$user[id]' AND id = '$run' AND timeleft < '$rtime' AND done = '0' AND time_run > '$rtime' LIMIT 1");
if (mysql_num_rows($tst) == false)
{
err('Этот легион возвращается домой или уже вернулся!');
}
else
{
$q = mysql_fetch_assoc($tst);
$loc = mysql_fetch_assoc(mysql_query("SELECT x, y FROM location WHERE id = '$user[terrain]' LIMIT 1"));
$arrival = travel_time(10 * $q['speed'], $user['coor_x'], $user['coor_y'], $loc['x'], $loc['y']);
$timer = ($rtime + $arrival) - $q['time_run'];
mysql_query("UPDATE duty SET time_back = '".($rtime + $timer)."' WHERE id = '$run' AND user = '$user[id]' LIMIT 1");
mysql_query("UPDATE duty SET time_run = '0' WHERE id = '$run' AND user = '$user[id]' LIMIT 1");
header('location: army' . $run);
}
}
if (isset($_GET['guard']))
{
$guard = number($_GET['guard']);
$tst = mysql_query("SELECT * FROM duty WHERE user = '$user[id]' AND id = '$guard' AND timeleft < '$rtime' AND done = '0' AND time_run < '$rtime' AND time_back < '$rtime' LIMIT 1");
$gen = mysql_query("SELECT id, health FROM generals WHERE cid = '$guard' LIMIT 1");
$gn = mysql_fetch_assoc($gen);
if (mysql_num_rows($tst) == false)
{
err('Этот легион сейчас не может охранять замок!');
}
elseif (mysql_num_rows($gen) == false)
{
err('Этот легион не может охранять замок без генерала!');
}
elseif ($gn['health'] == 0)
{
err('Генерал этого легиона мертв, легион не может охранять замок!');
}
elseif ($gn['time_recovery'] != 0)
{
err('Генерал этого легиона восстанавливается, легион не может охранять замок!');
}
else
{
if ($_GET['act'] == 'on') $act = 1;
else $act = 0;
mysql_query("UPDATE duty SET security = '$act' WHERE user = '$user[id]' AND id = '$guard' AND timeleft < '$rtime' AND done = '0' LIMIT 1");
header('location: army' . $guard);
}
}
if (isset($_GET['disband']))
{
$disband = number($_GET['disband']);
$tst = mysql_query("SELECT id FROM duty WHERE user = '$user[id]' AND id = '$disband' AND timeleft < '$rtime' AND time_run < '$rtime' AND done = '0' AND time_back < '$rtime' LIMIT 1");
if (mysql_num_rows($tst) == false)
{
err('Этот легион нельзя разогнать!');
}
else
{
mysql_query("DELETE FROM duty WHERE user = '$user[id]' AND id = '$disband' AND timeleft < '$rtime' AND done = '0' LIMIT 1");
}
}
if (isset($_GET['id']))
{
$id = number($_GET['id']);
$legion = mysql_result(mysql_query("SELECT COUNT(*) FROM duty WHERE id = '$id' AND user = '$user[id]' AND timeleft < '$rtime' AND done = '0'"), 0);
if ($legion != 0)
{
$l = mysql_query("SELECT duty .*,
(SELECT SUM(lot) FROM duty WHERE id = '$id' AND user = '$user[id]' AND timeleft < '$rtime' AND done = '0') AS num,
(SELECT SUM(power) FROM duty WHERE id = '$id' AND user = '$user[id]' AND timeleft < '$rtime' AND done = '0') AS power
FROM duty WHERE id = '$id' AND user = '$user[id]' AND timeleft < '$rtime' AND done = '0'");
while($q = mysql_fetch_assoc($l))
{
echo 'Легион <b>' . $q['name'] . '</b> | Мощь: <b>' . number_format($q['power'] * $q['num']) . '</b><br/>';
switch($q['cid']):
case 1:
$n = ($user['race'] == 1) ? '<img src="resize.php?img=images/paladin.png&width=25&height=0" alt=""/> Паладин' : '<img src="resize.php?img=images/prizrak.png&width=25&height=0" alt=""/> Призрак';
break;
case 2:
$n = ($user['race'] == 1) ? '<img src="resize.php?img=images/mechnik.png&width=25&height=0" alt=""/> Мечник' : '<img src="resize.php?img=images/himera.png&width=25&height=0" alt=""/> Химера';
break;
case 3:
$n = ($user['race'] == 1) ? '<img src="resize.php?img=images/strelok.png&width=25&height=0" alt=""/> Стрелок' : '<img src="resize.php?img=images/oskvernitel.png&width=25&height=0" alt=""/> Осквернитель';
break;
case 4:
$n = ($user['race'] == 1) ? '<img src="resize.php?img=images/mag.png&width=25&height=0" alt=""/> Маг' : '<img src="resize.php?img=images/grifon.png&width=25&height=0" alt=""/> Грифон';
break;
case 5:
$n = ($user['race'] == 1) ? '<img src="resize.php?img=images/koloss.png&width=25&height=0" alt=""/> Колосс' : '<img src="resize.php?img=images/yetti.png&width=25&height=0" alt=""/> Йетти';
break;
endswitch;
echo $n . ' (' . $q['num'] . ')<br/>';
}
$_Attack = mysql_fetch_assoc(mysql_query("SELECT time_run, time_back, security FROM duty WHERE timeleft < '$rtime' AND done = '0' AND user = '$user[id]' AND id = '$id' LIMIT 1"));
$_where = mysql_fetch_assoc(mysql_query("SELECT x, y FROM location WHERE id = '$user[terrain]' LIMIT 1"));
if ($_Attack['time_run'] > $rtime)
{
echo '<a href="cansel_run'.$id.'"><img src="images/unit_action_2.png" alt=""/></a> → Направляется к <a href="location'.$_where['x'].'_'.$_where['y'].'_2"><u>[x:' . $_where['x'] . ';y:' . $_where['y'] . ']</u></a> осталось ' . conv($_Attack['time_run'] - $rtime);
}
elseif ($_Attack['time_back'] > $rtime)
{
echo ' ← Возвращается домой, осталось ' . conv($_Attack['time_back'] - $rtime);
}
echo separator . '<img src="images/unit_action_1.png" alt=""/> <a href="control'.$id.'"><u>Разогнать</u></a><br/>
<img src="images/unit_action_6.png" alt=""/> <a href="direct'.$id.'"><u>Отправить</u></a><br/>';
echo ($_Attack['security'] == 0)
? '<img src="images/unit_action_3.png" alt=""/> <a href="guard'.$id.'_on"><u>Охранять</u></a><br/>'
: '<img src="images/unit_action_4.png" alt=""/> <a href="guard'.$id.'_off"><u>Снять с охраны</u></a><br/>';
} else err('Легиона не существует!');
}
else
{
$legion = mysql_result(mysql_query("SELECT COUNT(lot) FROM duty WHERE user = '$user[id]' AND timeleft < '$rtime' AND done = '0'"), 0);
echo '<b>Ваши войска:</b><br/>';
if ($legion != 0)
{
$l = mysql_query("SELECT * FROM duty WHERE user = '$user[id]' AND timeleft < '$rtime' AND done = '0' ORDER BY id ASC");
while($q = mysql_fetch_assoc($l))
{
echo '→ <a href="army'.$q['id'].'">' . $q['name'] . '</a><br/>';
}
} else {
echo 'Легионов нет.<br/>';
}
}
break;
case troops_run:
$smtr = mysql_query("SELECT id FROM construct WHERE user = '$user[id]' AND cid = '14' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($smtr) == false)
{
err('Необходимо построить здание Караульная башня!');
}
else
{
$sm = mysql_fetch_assoc($smtr);
$troops_run = mysql_num_rows(mysql_query("SELECT id FROM duty WHERE user = '$user[id]' AND time_run > '$rtime' AND done = '0'"));
if ($troops_run == 0)
{
echo 'Нет ни одного войска в дороге.<br/>';
}
else
{
$view = mysql_query("SELECT d.id, d.name, d.time_run, l.x, l.y FROM duty AS d LEFT JOIN users AS u ON(u.id = d.user) LEFT JOIN location AS l ON(l.id = u.terrain) WHERE d.user = '$user[id]' AND d.time_run > '$rtime' AND d.done = '0' ORDER BY d.time_run DESC");
while($a = mysql_fetch_assoc($view))
{
echo '→ Армия <a href="army'.$a['id'].'">' . $a['name'] . '</a> направляется к <a href="location'.$a['x'].'_'.$a['y'].'_2">[' . $a['x'] . ';' . $a['y'] . ']</a>
<a href="cansel_run'.$a['id'].'"><img src="images/unit_action_2.png" alt=""/></a><br/>
Осталось ' . val($a['time_run'] - $rtime) . '<br/>';
}
}
}
echo '<br/><a href="upgrade'.$sm['id'].'">Вернуться</a>';
break;
case troops_back:
$smtr = mysql_query("SELECT id FROM construct WHERE user = '$user[id]' AND cid = '14' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($smtr) == false)
{
err('Необходимо построить здание Караульная башня!');
}
else
{
$sm = mysql_fetch_assoc($smtr);
$troops_run = mysql_num_rows(mysql_query("SELECT id FROM duty WHERE user = '$user[id]' AND time_back > '$rtime' AND done = '0'"));
if ($troops_run == 0)
{
echo 'Нет ни одного прибывающего войска.<br/>';
}
else
{
$view = mysql_query("SELECT id, name, time_back FROM duty WHERE user = '$user[id]' AND time_back > '$rtime' AND done = '0' ORDER BY time_back DESC");
while($a = mysql_fetch_assoc($view))
{
echo '→ Армия <a href="army'.$a['id'].'">' . $a['name'] . '</a> возвращается домой<br/>
Прибывает через: ' . val($a['time_back'] - $rtime) . '<br/>';
}
}
}
echo '<br/><a href="upgrade'.$sm['id'].'">Вернуться</a>';
break;
case my_scout_run:
$smtr = mysql_query("SELECT id FROM construct WHERE user = '$user[id]' AND cid = '14' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($smtr) == false)
{
err('Необходимо построить здание Караульная башня!');
}
else
{
$sm = mysql_fetch_assoc($smtr);
$troops_run = mysql_num_rows(mysql_query("SELECT id FROM scouts WHERE player = '$user[id]' AND time_run > '$rtime' LIMIT 1"));
if ($troops_run == 0)
{
echo 'Шпиона в разведке нет.<br/>';
}
else
{
$view = mysql_query("SELECT scouts.*, l.x, l.y FROM scouts LEFT JOIN location AS l ON(l.id = scouts.destination) WHERE player = '$user[id]' AND time_run > '$rtime' LIMIT 1");
while($a = mysql_fetch_assoc($view))
{
echo '→ Шпион направляется к <a href="location'.$a['x'].'_'.$a['y'].'_2">[' . $a['x'] . ';' . $a['y'] . ']</a><br/>
Осталось ' . val($a['time_run'] - $rtime) . '<br/>';
}
}
}
echo '<br/><a href="upgrade'.$sm['id'].'">Вернуться</a>';
break;
case my_scout_back:
$smtr = mysql_query("SELECT id FROM construct WHERE user = '$user[id]' AND cid = '14' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($smtr) == false)
{
err('Необходимо построить здание Караульная башня!');
}
else
{
$sm = mysql_fetch_assoc($smtr);
$troops_run = mysql_num_rows(mysql_query("SELECT id FROM scouts WHERE player = '$user[id]' AND time_back > '$rtime' LIMIT 1"));
if ($troops_run == 0)
{
echo 'Прибывающего шпиона нет.<br/>';
}
else
{
$view = mysql_query("SELECT * FROM scouts WHERE player = '$user[id]' AND time_back > '$rtime' LIMIT 1");
while($a = mysql_fetch_assoc($view))
{
echo '→ Шпион возвращается домой<br/>
Осталось ' . val($a['time_back'] - $rtime) . '<br/>';
}
}
}
echo '<br/><a href="upgrade'.$sm['id'].'">Вернуться</a>';
break;
case my_saboteur_run:
$smtr = mysql_query("SELECT id FROM construct WHERE user = '$user[id]' AND cid = '14' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($smtr) == false)
{
err('Необходимо построить здание Караульная башня!');
}
else
{
$sm = mysql_fetch_assoc($smtr);
$troops_run = mysql_num_rows(mysql_query("SELECT id FROM saboteurs WHERE player = '$user[id]' AND time_run > '$rtime' LIMIT 1"));
if ($troops_run == 0)
{
echo 'Саботажника в разведке нет.<br/>';
}
else
{
$view = mysql_query("SELECT saboteurs.*, l.x, l.y FROM saboteurs LEFT JOIN location AS l ON(l.id = saboteurs.destination) WHERE player = '$user[id]' AND time_run > '$rtime' LIMIT 1");
while($a = mysql_fetch_assoc($view))
{
echo '→ Саботажник направляется к <a href="location'.$a['x'].'_'.$a['y'].'_2">[' . $a['x'] . ';' . $a['y'] . ']</a><br/>
Осталось ' . val($a['time_run'] - $rtime) . '<br/>';
}
}
}
echo '<br/><a href="upgrade'.$sm['id'].'">Вернуться</a>';
break;
case my_saboteur_back:
$smtr = mysql_query("SELECT id FROM construct WHERE user = '$user[id]' AND cid = '14' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($smtr) == false)
{
err('Необходимо построить здание Караульная башня!');
}
else
{
$sm = mysql_fetch_assoc($smtr);
$troops_run = mysql_num_rows(mysql_query("SELECT id FROM saboteurs WHERE player = '$user[id]' AND time_back > '$rtime' LIMIT 1"));
if ($troops_run == 0)
{
echo 'Прибывающего саботажника нет.<br/>';
}
else
{
$view = mysql_query("SELECT * FROM saboteurs WHERE player = '$user[id]' AND time_back > '$rtime' LIMIT 1");
while($a = mysql_fetch_assoc($view))
{
echo '→ Саботажник возвращается домой<br/>
Осталось ' . val($a['time_back'] - $rtime) . '<br/>';
}
}
}
echo '<br/><a href="upgrade'.$sm['id'].'">Вернуться</a>';
break;
case my_recruiter_run:
$smtr = mysql_query("SELECT id FROM construct WHERE user = '$user[id]' AND cid = '14' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($smtr) == false)
{
err('Необходимо построить здание Караульная башня!');
}
else
{
$sm = mysql_fetch_assoc($smtr);
$troops_run = mysql_num_rows(mysql_query("SELECT id FROM recruiters WHERE player = '$user[id]' AND time_run > '$rtime' LIMIT 1"));
if ($troops_run == 0)
{
echo 'Вербовщика в разведке нет.<br/>';
}
else
{
$view = mysql_query("SELECT recruiters.*, l.x, l.y FROM recruiters LEFT JOIN location AS l ON(l.id = recruiters.destination) WHERE player = '$user[id]' AND time_run > '$rtime' LIMIT 1");
while($a = mysql_fetch_assoc($view))
{
echo '→ Вербовщик направляется к <a href="location'.$a['x'].'_'.$a['y'].'_2">[' . $a['x'] . ';' . $a['y'] . ']</a><br/>
Осталось ' . val($a['time_run'] - $rtime) . '<br/>';
}
}
}
echo '<br/><a href="upgrade'.$sm['id'].'">Вернуться</a>';
break;
case my_recruiter_back:
$smtr = mysql_query("SELECT id FROM construct WHERE user = '$user[id]' AND cid = '14' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($smtr) == false)
{
err('Необходимо построить здание Караульная башня!');
}
else
{
$sm = mysql_fetch_assoc($smtr);
$troops_run = mysql_num_rows(mysql_query("SELECT id FROM recruiters WHERE player = '$user[id]' AND time_back > '$rtime' LIMIT 1"));
if ($troops_run == 0)
{
echo 'Прибывающего вербовщика нет.<br/>';
}
else
{
$view = mysql_query("SELECT * FROM recruiters WHERE player = '$user[id]' AND time_back > '$rtime' LIMIT 1");
while($a = mysql_fetch_assoc($view))
{
echo '→ Вербовщик возвращается домой<br/>
Осталось ' . val($a['time_back'] - $rtime) . '<br/>';
}
}
}
echo '<br/><a href="upgrade'.$sm['id'].'">Вернуться</a>';
break;
case troops_enemy:
$smtr = mysql_query("SELECT id FROM construct WHERE user = '$user[id]' AND cid = '14' AND timeleft < '$rtime' LIMIT 1");
if (mysql_num_rows($smtr) == false)
{
err('Необходимо построить здание Караульная башня!');
}
else
{
$smtr = mysql_fetch_assoc($smtr);
$troops_run = mysql_num_rows(mysql_query("SELECT id FROM users WHERE terrain IN(SELECT id FROM location WHERE id_player = '$user[id]') AND id IN(SELECT user FROM duty WHERE time_run > '$rtime')"));
if ($troops_run == 0)
{
echo 'Нет ни одного прибывающего войска.<br/>';
}
else
{
$view = mysql_query("SELECT d.name, d.time_run, d.id, l.x, l.y FROM duty AS d LEFT JOIN users AS u ON(d.user = u.id) JOIN location AS l ON(l.id = u.terrain) WHERE d.time_run > '$rtime'");
while($a = mysql_fetch_assoc($view))
{
echo '→ Армия <a href="view_enemy'.$a['id'].'">' . $a['name'] . '</a> из замка <a href="location'.$a['x'].'_'.$a['y'].'_2">['.$a['x'].';'.$a['y'].']</a><br/>
Прибывает через: ' . val($a['time_run'] - $rtime) . '<br/>';
}
}
}
echo '<br/><a href="upgrade'.$smtr['id'].'">Вернуться</a>';
break;
case view_enemy:
$id = number($_GET['id']);
$legion = mysql_query("SELECT id FROM users WHERE terrain IN(SELECT id FROM location WHERE id_player = '$user[id]') AND id IN(SELECT user FROM duty WHERE time_run > '$rtime' AND id = '$id')");
if (mysql_num_rows($legion) != false)
{
$l = mysql_query("SELECT d.cid, d.user, d.name, d.time_run, d.id, SUM(d.power) AS p, SUM(d.lot) AS n FROM duty AS d LEFT JOIN users AS u ON(d.user = u.id) JOIN location AS l ON(l.id = u.terrain) WHERE d.time_run > '$rtime' AND d.id = '$id' GROUP BY d.power");
while($q = mysql_fetch_assoc($l))
{
echo 'Легион <b>' . $q['name'] . '</b> | Мощь: <b>' . number_format($q['p'] * $q['n']) . '</b><br/>';
switch($q['cid']):
case 1:
$n = (user($q['user'], 'race') == 1) ? '<img src="resize.php?img=images/paladin.png&width=25&height=0" alt=""/> Паладин' : '<img src="resize.php?img=images/prizrak.png&width=25&height=0" alt=""/> Призрак';
break;
case 2:
$n = (user($q['user'], 'race') == 1) ? '<img src="resize.php?img=images/mechnik.png&width=25&height=0" alt=""/> Мечник' : '<img src="resize.php?img=images/himera.png&width=25&height=0" alt=""/> Химера';
break;
case 3:
$n = (user($q['user'], 'race') == 1) ? '<img src="resize.php?img=images/strelok.png&width=25&height=0" alt=""/> Стрелок' : '<img src="resize.php?img=images/oskvernitel.png&width=25&height=0" alt=""/> Осквернитель';
break;
case 4:
$n = (user($q['user'], 'race') == 1) ? '<img src="resize.php?img=images/mag.png&width=25&height=0" alt=""/> Маг' : '<img src="resize.php?img=images/grifon.png&width=25&height=0" alt=""/> Грифон';
break;
case 5:
$n = (user($q['user'], 'race') == 1) ? '<img src="resize.php?img=images/koloss.png&width=25&height=0" alt=""/> Колосс' : '<img src="resize.php?img=images/yetti.png&width=25&height=0" alt=""/> Йетти';
break;
endswitch;
echo $n . ' (' . $q['n'] . ')<br/>';
}
}
else err('Легиона не существует!');
echo '<br/><a href="troops_enemy">Вернуться</a>';
break;
case direct:
$id = number($_GET['id']);
$tst = mysql_query("SELECT * FROM duty WHERE user = '$user[id]' AND id = '$id' AND timeleft < '$rtime' AND done = '0' LIMIT 1");
$q = mysql_fetch_assoc($tst);
$gen = mysql_query("SELECT id, health FROM generals WHERE cid = '$id' LIMIT 1");
$gn = mysql_fetch_assoc($gen);
if (mysql_num_rows($tst) == false)
{
err('Легиона не сеществует!');
}
elseif (mysql_num_rows($gen) == false)
{
err('Легион не может отправится без генерала!');
}
elseif ($gn['health'] == 0)
{
err('Генерал мертв, легион не может отправится!');
}
elseif ($gn['time_recovery'] != 0)
{
err('Генерал этого легиона восстанавливается, легион не может отправится!');
}
elseif ($q['time_run'] > $rtime || $q['time_back'] > $rtime)
{
err('Легион не может отправляться, он уже в пути!');
}
elseif ($q['security'] == 1)
{
err('Этот легион охраняет замок, он не может никуда отправиться!');
}
else
{
if (isset($_POST['forward']))
{
$x = char($_POST['x'], 0);
$y = char($_POST['y'], 0);
$ctrl = mysql_fetch_assoc(mysql_query("SELECT id, id_player FROM location WHERE x = '$x' AND y = '$y' LIMIT 1"));
if ($x < -98 || $x > 98 || $y < -98 || $y > 98)
{
err('Неверные координаты!');
}
elseif ($ctrl['id_player'] == 0)
{
err('На этой местности ничего нет!');
}
elseif (user($ctrl['id_player'], 'untouch') > $rtime)
{
err('Этот замок под защитой!');
}
elseif (user($ctrl['id_player'], 'ban') > $rtime || user($ctrl['id_player'], 'forever') == 1)
{
err('Игрок арестован, атака невозможна.');
}
elseif ($x == $user['coor_x'] && $y == $user['coor_y'])
{
err('Ты не можешь атаковать свой замок!');
}
else
{
mysql_query("UPDATE users SET terrain = '$ctrl[id]' WHERE id = '$user[id]' LIMIT 1");
$arrival = travel_time(10 * $q['speed'], $user['coor_x'], $user['coor_y'], $x, $y);
mysql_query("UPDATE duty SET time_run = '" . ($rtime + $arrival) . "', time_back = '0' WHERE user = '$user[id]' AND done = '0' AND id = '$id' LIMIT 1");
header('location: army' . $id);
}
}
echo '<form method="post" action="direct'.$id.'">
<b>Координаты:</b><br/>
x: <input type="text" name="x" maxlength="3" size="3"/>
y: <input type="text" name="y" maxlength="3" size="3"/>
<br/>
<input type="submit" name="forward" value="Отправить"/>
</form>';
}
echo '<a href="army'.$id.'">Вернуться</a>';
break;
}
echo '<br/><a href="index.php">На главную</a>';
include 'sys/foot.php';
?>