<?php
$user = $ku;
if(isset($_GET['LinkNoUser'])) echo "<div class='feedback'><ul><li class='title'><span>Извините, но самим собой играть нельзя!</span></li><li></li></ul></div>";

echo "<div class='content'>";

echo '<div class="block">';

        $udata2 = $ku;
		$req1 = mysql_querll("SELECT * FROM `arena` WHERE `lider` = '".$udata2['nick']."' or `oponent` = '".$udata2['nick']."' LIMIT 1");
		$t = mysql_fetch_array($req1);
		$time = time();
		if($time > $t['timer'])
		{
		mysql_querll("DELETE FROM `tmp_arena` WHERE `usr` = '".$udata2['nick']."'");
		mysql_querll("DELETE FROM `tmp_arena` WHERE `oponent` = '".$udata2['nick']."'");
		mysql_querll("DELETE FROM `arena` WHERE `oponent` = '".$udata2['nick']."' or `lider` = '".$udata2['nick']."'");
		header('Location: ?arena&LinkGoUserEnd'); exit;
		}

		$req2 = mysql_querll("SELECT * FROM `tmp_arena` WHERE `oponent` = '".$udata2['nick']."' LIMIT 1");
		$ar2 = mysql_fetch_array($req2);
		$req = mysql_querll("SELECT * FROM `tmp_arena` WHERE `usr` = '".$udata2['nick']."' LIMIT 1");
		$ar = mysql_fetch_array($req);
		$chek = mysql_num_rows($req);
		if($chek <= 0)
		{
		header('Location: ?arena');
		}
		if($ar['step'] == 'yes')
		{
				echo'Вы сделали ход<br />ожидайте хода противника<br /><a href="?go_boy&amp;'.rand(1000,9999).'">Обновить</a><br />';
echo '</div></div>';
 include_once 'inc/foot.php';
		}

////////////////////////////////////////////////////////////////////// pac 1


 if(isset($_GET['udar'])){
 	$req = mysql_querll("SELECT * FROM `arena` WHERE `lider` = '".$udata2['nick']."' LIMIT 1");
		$chek = mysql_fetch_array($req);
		if($chek['oponent'] == 'not')
		{
		echo'Нет противника<br />';
		echo'<a href="?go_boy&amp;'.rand(1000,9999).'">Обновить</a> | <a href="?go_boy&amp;exit">Отменить</a><br />';
		echo '</div></div>'; include 'inc/foot.php'; exit;
		}
		$req = mysql_querll("SELECT * FROM `tmp_arena` WHERE `usr` = '".$udata2['nick']."'");
		$chek = mysql_num_rows($req);
		if($chek <= 0)
		{
		header('Location: ?arena');
		}
			$req = mysql_querll("SELECT * FROM `kolhoz_user` WHERE `nick` = '".$ar['oponent']."' LIMIT 1");
			$op = mysql_fetch_array($req);
				$attack = mysql_real_escape_string($_POST['a_kuda']);
				$protect = mysql_real_escape_string($_POST['p_kuda']);
					if($_POST['a_kuda'] == 'golova')
					{
$ref=rand(0,2);
					$uron = $ku['arena1']+$ref;
					$msg = 'Игрок '.$udata2['nick'].' ударил вас в голову на '.$uron.' урона';
					}
					if($_POST['a_kuda'] == 'body')
					{ 
					
					$ref = rand(0,1);
					$uron = $ku['arena1']+$ref;
					$msg = 'Игрок '.$udata2['nick'].' ударил вас в живот на '.$uron.' урона';
					}
					if($_POST['a_kuda'] == 'nogi')
					{
					$ref = rand(0,1);
					$uron = $ku['arena1']+$ref;
					$msg = 'Игрок '.$udata2['nick'].' ударил вас в ноги на '.$uron.' урона';
					}
					
					if($uron > $op['arena2'])
					{
						echo 'Вы побeдили игрока '.$op['nick'];
						echo '<br /><a href="?arena">Продолжить</a><br />';
						$win = $udata2['arena_win'] + 1;
						$expt = rand(100,1000);
						$exp = $ku['arena4']*$expt;

                                                $expw = 1;
						$ret = $ku['arena5']*$ku['arena4'];
						
						mysql_querll("UPDATE `kolhoz_user` SET `arena_win` = '".($ku['arena_win']+$expw)."', `rating` = '".($ku['rating']+$exp)."', `arena2` = '".$ref."' WHERE `nick` = '".$udata2['nick']."' LIMIT 1");
						mysql_querll("DELETE FROM `tmp_arena` WHERE `usr` = '".$udata2['nick']."'");
						mysql_querll("DELETE FROM `tmp_arena` WHERE `usr` = '".$op['nick']."'");
						$re = 0;
						mysql_querll("UPDATE `kolhoz_user` SET `arena2` = '$re' WHERE `nick` = '".$op['nick']."' LIMIT 1");
						mysql_querll("DELETE FROM `arena` WHERE `oponent` = '".$udata2['nick']."' or `lider` = '".$udata2['nick']."'");
						
$_SESSION['rating']=$exp;
update_mc($expq);
include_once 'inc/foot.php';
exit;
					}
					if($ku['arena2'] <= 0)
					{
						echo 'Вы проиграли';
						echo '<br /><a href="?arena">Продолжить</a><br />';
						mysql_querll("DELETE FROM `tmp_arena` WHERE `usr` = '".$udata2['nick']."'");
						mysql_querll("DELETE FROM `tmp_arena` WHERE `usr` = '".$op['nick']."'");
						mysql_querll("DELETE FROM `arena` WHERE `oponent` = '".$udata2['nick']."'");
						echo '</div></div>'; include 'inc/foot.php'; exit;
					}
					$uron = $op['arena2'] - $uron;
					if($uron <= 0)
					{
					$uron = $op['arena2'] - 0;
					$msg = 'Игрок '.$udata2['nick'].' нанес вам 0 урона';
					}
					if($attack == $ar2['protect'])
					{
					$uron = $op['arena2'] -0;
					$msg = 'Вы заблокировали удар';
					}
					$time = time()+30;
				mysql_querll("INSERT INTO `msg_arena` SET  `usr` = '".$udata2['nick']."', `oponent` = '".$ar['oponent']."', `msg` = '$msg', `time` = '$time'");
				mysql_querll("UPDATE `tmp_arena` SET `step` = 'yes', `protect` = '$protect', `attack` = '$attack' WHERE `usr` = '".$udata2['nick']."' LIMIT 1");
				$req = mysql_querll("UPDATE `tmp_arena` SET `step` = 'not' WHERE `oponent` = '".$udata2['nick']."' LIMIT 1");
				mysql_querll("UPDATE `kolhoz_user` SET `arena2` = '$uron' WHERE `nick` = '".$ar['oponent']."' LIMIT 1");
						if($req = true)
							{
						
						header('Location: ?go_boy');
						
						}else{
				echo 'Ошибка... Администратор извещен.';
						}
 
 
 }elseif(isset($_GET['exit'])){
 if($_GET['go'] == 'lider')
		{
			mysql_querll("DELETE FROM `tmp_arena` WHERE `usr` = '".$ku['nick']."'");
			mysql_querll("DELETE FROM `tmp_arena` WHERE `oponent` = '".$ku['nick']."'");
			mysql_querll("DELETE FROM `arena` WHERE `lider` = '".$ku['nick']."'");
			header("Location: ?arena");
		}	
 
 
 }else{
 	
 
 
     					if($ku['arena2'] <= 0)
					{
						header('Location: ?go_boy&udar');
						
						exit;
					}
		$req = mysql_querll("SELECT * FROM `arena` WHERE `lider` = '".$udata2['nick']."' LIMIT 1");
		$chek = mysql_fetch_array($req);
		if($chek['oponent'] == 'not')
		{
		echo'Заявка создана. Ожидайте соперника<br />';
		echo'<img width="16" height="16" src="images/icons/refresh.png" alt="o"> <a href="?go_boy&amp;'.rand(1000,9999).'">Обновить</a><br /><img alt="" width="16" height="16" src="images/icons/cross.png"> <a href="?go_boy&amp;exit&go=lider">Отменить</a><br />';
		echo '</div></div>'; include 'inc/foot.php'; exit;
		}
		$req = mysql_querll("SELECT * FROM `kolhoz_user` WHERE `nick` = '".$ar['oponent']."' LIMIT 1");
		$op = mysql_fetch_array($req);
		echo'Жизни противника '.$ar['oponent'].' <img width="16" height="16" src="/images/icons/heart.png" alt="o"/> '.$op['arena2'].'<br />';
        echo'Ваши жизни <img width="16" height="16" src="/images/icons/heart.png" alt="o"/> '.$ku['arena2'];
               
echo '<li>Ваши способности: <span>
<span>
<img width="16" height="16" src="/images/icons/sword.png" alt="Мощн" title="Мощн"/>&nbsp;<span class="title">'.$ku['arena1'].'</span>&nbsp;
</span><span>
<img width="16" height="16" src="/images/icons/heart.png" alt="Жив" title="Жив"/>&nbsp;<span class="title">'.$ku['arena2'].' </span>&nbsp;
</span><span>
<img width="16" height="16" src="/images/icons/shield.png" alt="Защита" title="Защита"/>&nbsp;<span class="title">'.$ku['arena3'].'</span>&nbsp;
</span>
</span></li>';

echo '<form action="?go_boy&udar" method="post">';
				echo "Ударить:<br/>
				<select name=\"a_kuda\">
				<option value=\"golova\">В голову</option>
				<option value=\"body\">В живот</option>
				<option value=\"nogi\">В ноги</option>
				</select><br/>";
				echo "Защита:<br/>
				<select name=\"p_kuda\">
				<option value=\"golova\">Головы</option>
				<option value=\"body\">Живота</option>
				<option value=\"nogi\">Ног</option>
				</select><br/>";
			echo '<input class="button" type="submit" value="Ударить" /></form>';
			
			$req = mysql_querll("SELECT * FROM `msg_arena` WHERE `oponent` = '".$udata2['nick']."' ORDER BY `id` DESC LIMIT 10");
			@$avto = mysql_num_rows($req);
				
			while(@$msg = mysql_fetch_array($req)){
					if(time() < $msg['time'])
					{
					echo $msg['msg'];
			echo '<br />';
					}
			}
 
 }



echo '</div></div>';
include_once 'inc/foot.php';



?>



				