<?

require_once 'core/system.php';
echo only_reg();
$header = 'Арена';
require_once 'core/head.php';

?>






<?

$kount = mysql_result(mysql_query("SELECT COUNT(*)  FROM `user`"),0);
$health = rand(1,$user[level]);
if($_GET['attack'])
{
if($user['health'] < 20){
$_SESSION['light'] = $warning_arena_low_health;
header('Location: ?');
exit();
}
if($user['mana'] < 50)
{
$_SESSION['light'] = $warning_arena_low_mana;
header('Location: ?');
exit();
}else{
$ank = mysql_fetch_array(mysql_query("select * from `user` where (`id` = '$get_attack')"));
if($ank['bonus_sila'] > time()) {
    $ank['sila'] += 300;
    $ank['max_health'] += 300;
    $ank['lovk'] += 300;
    $ank['zashit'] += 300;
    $ank['mana'] += 300;
}

$pets_param2 = $user[silapets] + $user[vinoslpets] + $user[healthpets];
$pets_param3 = $ank[silapets] + $ank[vinoslpets] + $ank[healthpets];
$ank_param = $ank[sila] + $ank[max_health] + $ank[lovk] + $ank[zashit] + $pets_param3;
$user_param = $user[sila] + $user[max_health] + $user[lovk] + $user[zashit] + $pets_param2;




if($ank_param > $user_param){
mysql_query("update `user` set `health` = '".($user['health']-30)."',`exp` = '".($user['exp']+10)."',`silver`='".($user['silver']+10)."',`arena_pobed`='".($user['arena_pobed']+ 0)."',`mana`='".($user['mana']-70)."' where (`id` = '".$user['id']."')");
mysql_query("UPDATE `user` SET `liga` = '".($user['liga']-1)."' WHERE `id` = '$user[id]' LIMIT 1");
header('Location: ?');
$_SESSION['light'] = "<h2 class='dred' style='font-weight:bold;'><img src='/images/icon/2hit.png' alt=''/> Поражение <img src='/images/icon/2hit.png' alt=''/></h2><div class='separ'></div><a class='btn' href='/arena.php?attack=$_GET[attack]'><span class='end'><span class='label'>Новый бой</span></span></a><div class='separ'></div><img src='/images/icon/silver.png' alt=''/> 10 серебра <img src='/images/icon/exp.png' alt='exp'/> 10 опыта<br>";
exit();
}else{
if($user[level] <= 5){
$mini = 30;
$maxi = 90;
$max = 9;
$min = 2;
}
if($user[level] >= 6){
$mini = 50;
$maxi = 150;
$max = 21;
$min = 9;
}
if($user[level] >= 10){
$mini = 70;
$maxi = 210;
$max = 36;
$min = 15;
}
if($user[level] >= 15){
$mini = 110;
$maxi = 350;
$max = rand(50,70);
$min = 30;
}
if($user[level] >= 20){
$mini = 170;
$maxi = 420;
$max = rand(65,99);
$min = rand(40,70);
}
if($user[level] >= 25){
$mini = 200;
$maxi = 510;
$max = rand(70,150);
$min = rand(57,88);
}
if($user[level] >= 30){
$mini = 230;
$maxi = 580;
$max = rand(85,170);
$min = rand(63,92);
}
if($user[prava] == 3){
$mini = $mini * 2;
$maxi = $maxi * 2;
$max = $max * 2;
$min = $min * 2;
}
$silver = rand($mini,$maxi);
$exp = rand(0,100);
$nagrada = rand(0,1);
$arena_pobed = 1;
if($user['bonus_elik'] > time()) {
    $exp = $exp * 3;
}
include (H.'/clan/clan_bonus.php');
if($user['clan_id'] != 0) {
    mysql_query("INSERT INTO `jr_clan` SET `user_id` = '".$user['id']."', `clan_id` = '".$user['clan_id']."', `exp` = '$exp'");
    mysql_query("UPDATE `clans` SET `exp` = `exp` + $exp, `quest` = `quest` + 1 WHERE `id` = '".$user['clan_id']."'");
}
if($user['petschek'] != 1) {
    mysql_query("UPDATE `user` SET `exp_pets` = `exp_pets` + $exp WHERE `id` = '".$user['exp_pets']."'");
}
if($key_percent <= $key_chance) {
$show_key = '<div class="separ"></div><span class="bold white">Вы получили</span><br /><br /> Ключ<br />';
mysql_query("update `user` set `keys` = '".($user['keys']+1)."' where `id` = '".$user['id']."'");
}else{
$show_key = '';
}
mysql_query("update `user` set `health` = '".($user['health']-7)."',`exp` = '".($user['exp']+$exp)."',`klyh` = '".($user['keys']+$nagrada)."',`silver`='".($user['silver']+$silver)."',`arena_pobed`='".($user['arena_pobed']+$arena_pobed)."',`mana`='".($user['mana']-50)."' where (`id` = '".$user['id']."');
mysql_query("UPDATE `user` SET `liga` = '".($user['liga']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
header('Location: /arena');
$_SESSION['light'] = "<h2 class='dgreen' style='font-weight:bold;'><img src='/images/icon/2hit.png' alt=''/> Победа <img src='/images/icon/2hit.png' alt=''/></h2><div class='separ'></div><a class='btn' href='?attack=$_GET[attack]'><span class='end'><span class='label'>Новый бой</span></span></a><div class='separ'></div><img src='/images/icon/silver.png' alt=''/> ".$silver." серебра <img src='/images/icon/exp.png' alt='exp'/> ".$exp." опыта<br>".$show_key;
exit();
}
}
}
echo "<div class='player center blue'>Побеждай врагов и становись сильнее!</div>

<div class='mini-line'></div>";

echo "<div class='player'>

<h2>Доступный противник</h2>

</div>";

if($kount < 2)echo "<div class='dot-line'></div><div class='player grey'>Нет противников!</div>";




$opponents = mysql_query("SELECT * FROM `user` WHERE `id` != '".$user['id']."' AND `level` <= '".$user['level']."' ORDER BY RAND() DESC LIMIT 1");

while($opponent = mysql_fetch_array($opponents))

{
$pets_param1 = $user[silapets] + $user[vinoslpets] + $user[healthpets];
$pets_param = $opponent[silapets] + $opponent[vinoslpets] + $opponent[healthpets];
$opponent_param = $opponent[sila] + $opponent[max_health] + $opponent[lovk] + $opponent[zashit] + $pets_param;
$user_param = $user[sila] + $user[max_health] + $user[lovk] + $user[zashit] + $pets_param1;




echo "<div class='block_zero'><div class='float-left'>

<a href='/arena?attack=$opponent[id]'><img src='/style/avatar/".($opponent['pol'] == 0 ? "zj" : "m")."/$opponent[avatar].png' width='120' height='160' style='margin-right:10px;float:left;' alt=''/></a></div>

<img src='/images/icon/user.png' alt=''/> $opponent[nick]
<br><br>

<img src='/images/icon/str.png' alt='str'/> Сила: $opponent[sila] (<span class='dgreen'>+$opponent[umensila]</span>)
<br>

<img src='/images/icon/vit.png' alt='vit'/> Здоровье: $opponent[max_health] (<span class='dgreen'>+$opponent[umenmax_health]</span>)
<br>

<img src='/images/icon/agi.png' alt='agi'/> Ловкость: $opponent[lovk] (<span class='dgreen'>+$opponent[umenlovk]</span>)
<br>

<img src='/images/icon/def.png' alt='def'/> Защита: $opponent[zashit] (<span class='dgreen'>+$opponent[umenzashit]</span>)
<br>


<img src='/images/icon/2hit.png'> $opponent_param (<span class='dgreen'>+$pets_param</span>) VS $user_param (<span class='dgreen'>+$pets_param1</span>)
<br>
<br>
<a class='btn' href='/arena?attack=$opponent[id]'><span class='end'><span class='label'>Атакoвать</span></span></a>





<br>

<div style='clear:both;'></div>
</div>";
}
echo "<div class='dot-line'></div>

<div class='player center'>
<a class='btn' href='/arena'><span class='end'><span class='label'>Другие противники</span></span></a>
</div>";

echo "<div class='mini-line'></div><div class='player'><img src='/images/icon/skill.png'> Ваш рейтинг: <b>$user[liga]</b></div>";
echo "<div class='mini-line'></div>

<div class='player'>
Ваши параметры:
<br>
<img src='/images/icon/str.png' alt='str'/> $user[sila] <img src='/images/icon/vit.png' alt='vit'/> $user[max_health] <img src='/images/icon/agi.png' alt='agi'/> $user[lovk] <img src='/images/icon/def.png' alt='def'/> $user[zashit]


</div>
<div class='mini-line'></div>";
if($user['petschek'] == 1){
echo "<div class='player'>Ваш питомец:</br><img src='$user[pets]'height='35'> <img src='/images/icon/pit.png'><span class='orange'> $user[petsname]</span> (<span class='dgreen'>+$pets_param1</span>)</div></div>";
echo "<div class='mini-line'></div>"; 
}
echo "<div class='player'><ul class='hint'><li>Чем больше уровень противника, тем больше опыта получишь за победу!</li></ul></div>";
require_once 'core/foot.php';
?>