Файл: 3/bashna.php
Строк: 149
<?php
require_once ('system/func.php');
$title = 'Башня смерти';
require_once ('system/header.php');
auth(); // Закроем от гостей
echo'<div class="lent mlra w80">
<div class="bl-ttl"><div class="te"><div class="ttl">
'.$title.'
</div></div></div>';
# Находим башню в базе #
$batle = $db->query("SELECT * FROM `bashna` WHERE `id` = '1' ORDER BY `id` LIMIT 1")->fetch_assoc();
$myLog = $db->query("SELECT * FROM `bashna_log` WHERE `id_bashna` = '$batle[id]' AND `id_user` = '$myID' AND `tipe` = 'user' ORDER BY `id` DESC LIMIT 1")->fetch_assoc();
$myLog_2 = $db->query("SELECT * FROM `bashna_log` WHERE `id_bashna` = '$batle[id]' AND `id_user` = '$myID' AND `tipe` = 'users' ORDER BY `id` DESC LIMIT 1")->fetch_assoc();
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);
$db->query("update `bashna` set `health` = '".($batle['health']+$rand*ceil($user['max_health']*10/100))."' where (`id` = '".$batle['id']."')");
$db->query("update `users` set `kamen` = '".($user['kamen']-4)."' where (`id` = '".$myID."')");
$db->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 = $db->query("SELECT * FROM `users` WHERE `online` > '".(time()-300)."' AND `fix_mesto` = '$title' AND `side` != '$user[side]' ORDER BY RAND() LIMIT 1")->fetch_assoc();
if($opponent){
if($opponent['health'] > num($opponent['max_health']*2))$opponent['health'] = num($opponent['max_health']*2);
$db->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;
$db->query("INSERT INTO `bashna_log` SET `id_user` = '$myID', `id_user2` = '$opponent[id]', `tipe` = 'users', `uron` = '".$_str."', `time` = '".(time()+2)."', `id_bashna` = '$batle[id]'");
$db->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;
$db->query("INSERT INTO `bashna_log` SET `id_user` = '$myID', `tipe` = 'bashna', `uron` = '".$_str_opp."', `id_bashna` = '$batle[id]'");
$db->query("INSERT INTO `bashna_log` SET `id_user` = '$myID', `tipe` = 'user', `uron` = '".$_str."', `time` = '".(time()+60)."', `id_bashna` = '$batle[id]'");
$db->query("update `bashna` set `health` = '".($batle['health']-$_str)."' where (`id` = '".$batle['id']."')");
if($batle['health'] <= 0 or $_str > $batle['health']){
$db->query("update `bashna` set `side` = '".$user['side']."' where (`id` = '".$batle['id']."')");
$db->query("update `bashna` set `health` = '".$batle['max_health']."' where (`id` = '".$batle['id']."')");
$db->query("update `users` set `gold` = '".($user['gold']+5)."' where (`id` = '".$myID."')");
$db->query("INSERT INTO `bashna_log` SET `id_user` = '$myID', `tipe` = 'zahvat', `id_bashna` = '$batle[id]'");
$_SESSION['msg'] = "<font color='green'><b>Вы захватили башню смерти</b></font><br>Награда: ".ico('icons','gold.png')." 5 золота";
}
$db->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 = $db->query("SELECT * FROM `users` WHERE `online` > '".(time()-300)."' AND `fix_mesto` = '$title' AND `side` = 'good'")->num_rows;
$evil = $db->query("SELECT * FROM `users` WHERE `online` > '".(time()-300)."' AND `fix_mesto` = '$title' AND `side` = 'evil'")->num_rows;
echo "<div class='center'>".ico('icons','good.png')." $good vs ".ico('icons','evil.png')." $evil</div>";
echo "<br>";
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='fight'>";
require_once ('bashni_log.php');
echo "</div>";
echo "<a href='/bashni' class='link'>".ico('icons','arrow.png')." Вернуться назад</a>";
echo "</div>";
require_once ('system/footer.php');
?>