<?php
require_once ('system/func.php');
$title = 'Поединки';
require_once ('system/header.php');
auth(); // Закроем от гостей
# Настройки #
$id = abs(intval($_GET['id']));
if($id)$profile = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$id."'"));
else $profile = $user;
if($user[level] >= 10){
$duel = mysql_fetch_array(mysql_query('SELECT * FROM `duel` WHERE `id_user` = "'.$myID.'"'));
if($duel[start] == 1){
header('Location: /duel/batle/');
exit();
}
if($duel['opponent'] == 0){
$opponent = mysql_query("SELECT * FROM `users` WHERE `side` != '$user[side]' ORDER BY RAND() LIMIT 1");
$opponent = mysql_fetch_array($opponent);
mysql_query("update `duel` set `opponent` = '$opponent[id]' where (`id` = '".$duel['id']."')");
header('Location: /duel/');
exit();
}
if(isset($_GET[koll])){
if($user[gold] < 25){
$_SESSION[msg] = "Не хватает ".ico('icons','gold.png')." ".(25-$user[gold])." золота";
header('Location: ?');
exit();
}
mysql_query("update `duel` set `koll` = '10' where (`id` = '".$duel['id']."')");
mysql_query("update `users` set `gold` = '".($user[gold]-25)."' where (`id` = '".$myID."')");
$_SESSION[msg] = "Бои успешно восстановлены";
header('Location: ?');
exit();
}
if(isset($_GET[opponent])) {
if($duel[koll] == 0){
$_SESSION[msg] = "У вас нет доступных боёв<br><a href='?koll' class='btn2'>Восстановить за ".ico('icons','gold.png')." 25</a>";
header('Location: ?');
exit();
}
$opponent = mysql_query("SELECT * FROM `users` WHERE `id` = '$duel[opponent]'");
$opponent = mysql_fetch_array($opponent);
mysql_query("update `duel` set `start` = '1', `opp_health` = '".$opponent[max_health]."', `user_health` = '".$user[max_health]."', `koll` = '".($duel[koll]-1)."' where (`id` = '".$duel['id']."')");
header('Location: /duel/batle/');
exit();
}
$opponent = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'.$duel['opponent'].'"'));
echo "<div class='block center'>";
echo '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="38%" align="right" valign="top">';
echo " <center> <a>$user[login]</center></a><br><img src='/manekenImage_$myID.png' width='120' height='160' style='margin-right:3px;margin-top:-2px;'></a>
<td width='12%' align='center'><img src='/images/other/versus.png' width='50' height='63' class='vs' alt=''></td>

<td width='38%' align='left' valign='top'>
<center>  <a>$opponent[login]</center></a><br><img src='/manekenImage_$opponent[id].png' width='120' height='160' style='margin-right:3px;margin-top:-2px;'></a></td></tr></table></br>".ico('icons','str.png')." Урон:$opponent[str] ".ico('icons','def.png')." Броня:$opponent[def] ".ico('icons','health.png')." Здоровье:$opponent[max_health]<a href=?opponent=$opponent[id]' class='btn2'>".ico('icons','str.png')." Сразиться</a><br><span class='info'>Осталось боёв:</span> ".ico('icons','sum_stat.png')."  $duel[koll]<hr>";
echo "<div class='mb10'></div><a href='/rinok/merchant/' class='btn2'>Купить зелья</a>";
echo "</div>";
echo '<div class="block">';
echo ico('icons','liga.png')." Звание: ";
if($profile['liga']>=-10000 and $profile['liga']<19){
echo "<span class='item-4'>Новичок</span>";
}elseif($profile['liga']>=20 and $profile['liga']<199){
echo "<span class='item-4'>Ученик (+2%)</span>";
}elseif($profile['liga']>=200 and $profile['liga']<499){
echo "<span class='item-4'>Воин (+4%)</span>";
}elseif($profile['liga']>=500 and $profile['liga']<1199){
echo "<span class='item-4'>Боец (+6%)</span>";
}elseif($profile['liga']>=1200 and $profile['liga']<1999){
echo "<span class='item-4'>Рыцарь (+8%)</span>";
}elseif($profile['liga']>=2000 and $profile['liga']<3999){
echo "<span class='item-4'>Гладиатор (+10%)</span>";
}elseif($profile['liga']>=4000 and $profile['liga']<5999){
echo "<span class='item-4'>Центурион (+12%)</span>";
}elseif($profile['liga']>=6000 and $profile['liga']<7999){
echo "<span class='item-4'>Титан (+14%)</span>";
}elseif($profile['liga']>=8000 and $profile['liga']<9999){
echo "<span class='item-4'>Властелин (+16%)</span>";
}elseif($profile['liga']>=10000 and $profile['liga']<14999){
echo "<span class='item-4'>Повелитель (+18%)</span>";
}elseif($profile['liga']>=15000 and $profile['liga']<100000000000){
echo "<span class='item-5'>Довакин (+20%)</span>";
}
echo ' ,'.ico('icons','liga.png').' Рейтинг: '.n_f($profile['liga']).'</div>';


}else{
echo "<div class='block center'>";
echo ico ('icons','duel.png')." <a>Поединки</a> доступны только с ".ico('icons','level.png')." 10 уровня!<br>".ico('icons','level.png')." Уровень можно прокачать в ".ico('icons','arena.png')." <a>Сражениях</a><br>";
echo "<a href='/arena' class='btn2'>Перейти к Сражениям</a>";
echo "</div>";
}
require_once ('system/footer.php');
?>