<?php
require_once ('system/func.php');
$title = 'Орк разведчик';
require_once ('system/header.php');
auth(); // Закроем от гостей
# Находим драка в базе #

if($user['level'] < 15){

echo '<div class="wrapper">
<center><img src="/images/other/big_drag1.png" width ="110px"></center>';
echo '<b>Орк разведчик доступен только с 15 уровня!</b></div>';
echo "<a href='/dragons.php' class='bbtn mb5'><img src='/images/icons/arrow.png'>Назад к долине орков</a>";
require_once ('system/footer.php');
exit();
}





$dragon = mysql_query("SELECT * FROM `dragon` WHERE `id` = '1' ORDER BY `id` LIMIT 1");
$dragon = mysql_fetch_array($dragon);
$batle = mysql_query("SELECT * FROM `dragon` WHERE `id` = '1' ORDER BY `id` LIMIT 1");
$batle = mysql_fetch_array($batle);
$myLog = mysql_query("SELECT * FROM `blue_log` WHERE `id_dragon` = '$batle[id]' AND `id_user` = '$myID' AND `tipe` = 'user' ORDER BY `id` DESC LIMIT 1");
$myLog = mysql_fetch_array($myLog);
if($batle['status']>=1)
header('location: /dragon_g/off');
if($batle['health'] > $batle['max_health'])$batle['health'] = $batle['max_health'];
if($batle['health'] < 0)$batle['health'] = 0;


# Атака #
if(isset($_GET['attack']) and $user['side'] != $batle['side']){
$quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '4'"));
$qt = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
if($q['last'] < time())mysql_query("update `quest_user` set `koll` = `koll`+'1' where (`id` = '".$qt['id']."')");
if(isset($myLog) and $myLog['time'] > time()){


header('Location: ?');
exit();
}



$_hp = ceil($user['max_health']*10/100);
if($user['health'] < 10 or $user['health'] < $_hp){
$_SESSION['msg'] = "Для нападения необходимо минимум ".ico('icons','health.png')." 10% здоровья!<br><a href='/cel.php' class='btn_grey' data-ajax>Перейти к Целительнице </a>";
if($user['energy'] < 10){
$_SESSION['msg'] = "Для нападения необходимо минимум ".ico('icons','energy.png')." 10 выносливости!<br><a href='/cel.php' class='btn_grey' data-ajax>Перейти к Целительнице  15</a>";




header('Location: ?');
exit();
}
}
if(isset($batle) and $batle['time'] > time()){

header('Location: ?');


exit();
}
# Статы Зелёного Драка #
$batle_str = 2000;
$batle_def = 2000;
# Урон #
$_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 `green_log` SET `id_user` = '$myID', `tipe` = 'dragon', `uron` = '".$_str_opp."', `time` = '".(time()+1)."', `id_dragon` = '$batle[id]'");
mysql_query("INSERT INTO `green_log` SET `id_user` = '$myID', `tipe` = 'user', `uron` = '".$_str."', `time` = '".(time()+5)."', `id_dragon` = '$batle[id]'");
mysql_query("update `dragon` set `health` = '".($batle['health']-$_str)."' where (`id` = '".$batle['id']."')");
if($batle['health'] <= 0 or $_str > $batle['health']){
mysql_query("update `dragon` set `health` = '".$batle['max_health']."' where (`id` = '".$batle['id']."')");
mysql_query("update `dragon` set `time` = '".(time()+3600*10)."' where (`id` = '".$batle['id']."')");
mysql_query("update `users` set `almaz` = '".($user['almaz']+25)."' where (`id` = '".$myID."')");
mysql_query("INSERT INTO `green_log` SET `id_user` = '$myID', `tipe` = 'zahvat', `id_dragon` = '$batle[id]'");
$_SESSION['msg'] = "<font color='blue'><b>Вы победили Орка разведчика</b></font><hr>Ваша награда: ".ico('icons','almaz.png')." 25 алмазов";
}
mysql_query("update `users` set `health` = '".($user['health']-$_str_opp)."', `exp` = '".($user['exp']+ceil($_str*1/100))."' where (`id` = '".$myID."')");
header("Location: /dragon_g/");
exit();
}
# Страничка боя #

echo '<div class="wrapper">
<center><img src="/images/other/big_drag1.png" width ="110px"></center></div>';

echo "<div class='wrapper center'>";
if($batle[time] > time()){
echo "Орк разведчик повержен! <br>Воскреснет через ".tl($batle[time]-time());
require_once ('system/footer.php');

}else{
echo "<center><br><font color='white'>".ico('icons','health.png')."$dragon[health]/$dragon[max_health]</font></center>";
echo "<div  class='exp progress-bar'><div class='exp_in progress-bar' style='width: ".round($batle['health']/$batle['max_health']*100,1)."%;' ></div></div><br>";

echo "<a href='?attack' class='btn_grey' data-ajax>Атаковать"; 
if($myLog['time'] > time())echo "[".tl($myLog['time']-time())."]";
echo "</a>";
}

echo "</div>";
echo "<div class='line'></div>";
echo "<div class='wrapper'>";
require_once ('green_log.php');
echo "</div>";
echo "  <a href='/dragons.php' class='main_link'><img src='/images/icons/arrow.png'>Назад к долине орков</a>";
require_once ('system/footer.php');

?>