Файл: public_html/bashna.php
Строк: 152
<?php
include './system/common.php';
include './system/functions.php';
include './system/user.php';
$title = 'Башня смерти';
include './system/h.php';
auth(); // Закроем от гостей
# Находим башню в базе #
$batle = mysql_query("SELECT * FROM `bashna` WHERE `id` = '1' ORDER BY `id` LIMIT 1");
$batle = mysql_fetch_array($batle);
$myLog = mysql_query("SELECT * FROM `bashna_log` WHERE `id_bashna` = '$batle[id]' AND `id_user` = '$myID' AND `tipe` = 'user' ORDER BY `id` DESC LIMIT 1");
$myLog = mysql_fetch_array($myLog);
$myLog_2 = mysql_query("SELECT * FROM `bashna_log` WHERE `id_bashna` = '$batle[id]' AND `id_user` = '$myID' AND `tipe` = 'users' ORDER BY `id` DESC LIMIT 1");
$myLog2 = mysql_fetch_array($myLog_2);
if($batle['health'] > $batle['max_health'])$batle['health'] = $batle['max_health'];
if($batle['health'] < 0)$batle['health'] = 0;
# Ремонт #
if(isset($_GET['remont']) and $user['side'] == $batle['side']){
if($batle['health'] == $batle['max_health']){
$_SESSION['msg'] = "Локация ещё в порядке";
header('Location: ?');
exit();
}
if($user['kamen'] < 4){
$_SESSION['msg'] = "У вас не хватает ".ico('icons','kamen.png')." ".(4-$user['kamen'])." камня";
header("Location: ?");
exit();
}else{
$rand = rand(1,2);
mysql_query("update `bashna` set `health` = '".($batle['health']+$rand*ceil($user['max_health']*10/100))."' where (`id` = '".$batle['id']."')");
mysql_query("update `users` set `kamen` = '".($user['kamen']-4)."' where (`id` = '".$myID."')");
mysql_query("INSERT INTO `bashna_log` SET `id_user` = '$myID', `tipe` = 'remont', `uron` = '".$rand*ceil($user['max_health']*10/100)."', `id_bashna` = '$batle[id]'");
$_SESSION['msg'] = 'Ремонт прошёл успешно';
header("Location: ?");
exit();
}
}
# Атака игрока #
if(isset($_GET['attack_user']) and $myLog_2['time'] < time()){
$_hp = ceil($user['max_health']*10/100);
if($user['energy'] < 10 or $user['health'] < $_hp){
$_SESSION['msg'] = "Для нападения необходимо минимум ".ico('icons','health.png')." 10% жизни и ".ico('icons','energy.png')." 10 энергии!<br><a href='/rinok?koldun&url=/bashna/?$random' class='btn2' data-ajax>Восстановить ".ico('icons','gold.png')." 15</a>";
header('Location: ?');
exit();
}else{
$opponent = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `online` > '".(time()-300)."' AND `fix_mesto` = '$title' AND `side` != '$user[side]' ORDER BY RAND() LIMIT 1"));
if($opponent){
if($opponent['health'] > num($opponent['max_health']*2))$opponent['health'] = num($opponent['max_health']*2);
mysql_query("update `users` set `energy` = '".($user['energy']-10)."' where (`id` = '".$user['id']."')");
$_def_opp = rand(round($opponent['def']/12), round($opponent['def']/7));
$_str = $_str - $_def_opp;
if($_str < 0)$_str = 0;
mysql_query("INSERT INTO `bashna_log` SET `id_user` = '$myID', `id_user2` = '$opponent[id]', `tipe` = 'users', `uron` = '".$_str."', `time` = '".(time()+2)."', `id_bashna` = '$batle[id]'");
mysql_query("update `users` set `health` = '".($opponent['health']-$_str)."' where (`id` = '".$opponent['id']."')");
}
header("Location: ?$random");
exit();
}
}
# Атака #
if(isset($_GET['attack']) and $user['side'] != $batle['side'] and $user[level] <= 10){
if(isset($myLog) and $myLog['time'] > time()){
header('Location: ?');
exit();
}
# Статы башни #
$batle_str = ceil($user['str']*65/100);
$batle_def = ceil($user['def']*65/100);
# Урон #
$_str_opp = rand(round($batle_str/6), round($batle_str/4));
$_def_opp = rand(round($batle_def/12), round($batle_def/7));
$_str_opp = $_str_opp - $_def;
if($_str_opp < 0)$_str_opp = 0;
$_str = $_str - $_def_opp;
if($_str < 0)$_str = 0;
mysql_query("INSERT INTO `bashna_log` SET `id_user` = '$myID', `tipe` = 'bashna', `uron` = '".$_str_opp."', `id_bashna` = '$batle[id]'");
mysql_query("INSERT INTO `bashna_log` SET `id_user` = '$myID', `tipe` = 'user', `uron` = '".$_str."', `time` = '".(time()+10)."', `id_bashna` = '$batle[id]'");
mysql_query("update `bashna` set `health` = '".($batle['health']-$_str)."' where (`id` = '".$batle['id']."')");
if($batle['health'] <= 0 or $_str > $batle['health']){
mysql_query("update `bashna` set `side` = '".$user['side']."' where (`id` = '".$batle['id']."')");
mysql_query("update `bashna` set `health` = '".$batle['max_health']."' where (`id` = '".$batle['id']."')");
mysql_query("update `users` set `gold` = '".($user['gold']+5)."' where (`id` = '".$myID."')");
mysql_query("INSERT INTO `bashna_log` SET `id_user` = '$myID', `tipe` = 'zahvat', `id_bashna` = '$batle[id]'");
$_SESSION['msg'] = "<font color='green'><b>Вы захватили башню смерти</b></font><hr>Награда: ".ico('icons','gold.png')." 5 золота";
}
mysql_query("update `users` set `health` = '".($user['health']-$_str_opp)."', `exp` = '".($user['exp']+ceil($_str*50/100))."' where (`id` = '".$myID."')");
header("Location: /bashna/");
exit();
}
# Страничка башни #
echo "<div class='block'>";
echo "<span style='float:right'>".ico('icons','health.png')." ".round($batle['health']/$batle['max_health']*100,1)."%</span>";
echo "Владельцы: ";
if($batle[side] == 'good')echo "<font color='green'>Добро</font>";
else echo "<font color='red'>Зло</font>";
$good = mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `online` > '".(time()-300)."' AND `fix_mesto` = '$title' AND `side` = 'good'"));
$evil = mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `online` > '".(time()-300)."' AND `fix_mesto` = '$title' AND `side` = 'evil'"));
echo "<div class='center'>".ico('icons','good.png')." $good vs ".ico('icons','evil.png')." $evil</div>";
echo "<hr>";
if($user['side'] != $batle['side']){
if($user[level] <= 10)echo "<a href='?attack' class='link center' data-ajax>Атаковать ";
if($myLog['time'] > time())echo "[".tl($myLog['time']-time())."]";
echo "</a>";
}else{
echo "<a href='?remont' class='link center' data-ajax>Ремонтировать за ".ico('icons','kamen.png')." 4</a>";
}
echo "<a href='?attack_user' class='link center' data-ajax>Бить врагов</a>";
echo "</div>";
echo "<div class='block'>";
require_once ('bashni_log.php');
echo "</div>";
echo "<a href='/bashni' class='link'>".ico('icons','arrow.png')." Вернуться назад</a>";
include './system/f.php';
?>