
<?php


require_once ('./system/func.php'); //тут подключаем шапку 
$title = 'Подземелье';
require_once ('./system/header.php');
auth(); // Закроем от гостей
?>
	<style>
.life_bar{
    max-width:50%;
    border:#c90 solid 1px;
    margin:5px auto
}
.life_bar-green{
    background-color:#393
}
.life_bar-red{
    background-color:#933
}
.life_bar-black{
    background-color:#000
}
.life_bar,.life_bar-black,.life_bar-green,.life_bar-red{
    height:3px;padding:0
}
.exp_bar{
    margin-bottom:2px;
    border-top:#202020 solid 1px;
    background-color:#707070;
    padding:0
}
.exp_bar .progress{
    background-color:#6c6;
    width:0;
    padding-top:1px;
    padding-bottom:1px
}
.exp_bar .progress_life{
    background-color:#c66;
    width:0;
    padding-top:2px;
    padding-bottom:2px
}
.camp_log{
    float: left;
}
</style>

<?









$revolt = mysql_query("SELECT * FROM `revolt` ORDER BY `id` DESC LIMIT 1");
$revolt = mysql_fetch_assoc($revolt);

$revoltMember =  mysql_query("SELECT * FROM  `revolt_member` WHERE `revolt`='".$revolt['id']."' and `user`='".$user['id']."'");
$revoltMember = mysql_fetch_assoc($revoltMember);

$membersCounter = mysql_num_rows(mysql_query("SELECT `id` FROM `revolt_member` WHERE `revolt`='".$revolt['id']."' and `dead`='0'"));

$demons = $membersCounter * 10 + rand (10, $membersCounter);
$demonsParam = array("str"=>"150", "vit"=>"150", "agi"=>"150","def"=>"150");//параметры духов минемальные, дальше рандомно перемножим 
$revoltTime = 100;
$boss = array("name"=>"Босс","str"=>"500","vit"=>"500","agi"=>"500","def"=>"500"); //параметры демона (отредоктировать, а то очень силный)




if ($revolt['time_left'] < time())
{

	mysql_query("INSERT INTO `revolt` SET  `time_start`='".(time() + 3600*3)."'`start`='0'");
}

if ($revolt['time_left'] < time() AND $revolt['start'] == 1 AND $revolt['time_start'] < time())
{

   
    
}


/**
 * Считаем игроков участников...
 */



$membersCounter = mysql_num_rows(mysql_query("SELECT `id` FROM `revolt_member` WHERE `revolt`='".$revolt['id']."' and `dead`='0'"));






/**
 * Если мятеж еще не начат..
 */
if ($revolt['start'] == 0 && $revolt['time_start'] > time() && $revolt['end'] == 0 )
{


	 	echo div('header')." Награда за бой <br> ".ico('icons', 'almaz.png')." $almaz  ".ico('icons', 'gold.png')." $gold  ".ico('icons', 'exp.png')." $exp </div>";

			
		echo  div('block_c')." Подано заявок: $membersCounter<br/>	
		Битва начнется через: ".isTimer($revolt[time_start]);
        echo "</div>";
        

	if ($revoltMember)
	{

		/**
		 * Выйти из очереди мятежа.
		 */

		if (isset($_GET['exitBatlle']))
		{

			mysql_query("DELETE FROM `revolt_member` WHERE `id`='".$revoltMember['id']."'");
 header('Location: /lair/?PHPSESSION='.$LinkKey.'');
			exit;


		}


	    echo div('foot center')." <div class='cbtn red center mt4'><span class='cb_end'><span class='cb_ttl'><a href='?exitBatlle=$LinkKey'> Покинуть очередь </span></span></div> </a></div>";

		
	} else {


		//Подача заявки в подземелье
		if (isset($_GET['enter']) ) 
		{
			mysql_query("INSERT INTO `revolt_member` SET `user`='".$user['id']."',`health` = '".$user[max_health]."' ,`max_health` = '".$user[max_health]."', `revolt`='".$revolt['id']."'")or die (mysql_error());
			
 header('Location: /lair/?PHPSESSION='.$LinkKey.'');
			exit;		



		}

       	}
    if(!$revoltMember)
    echo div('foot center')." <div class='cbtn green center mt4'><span class='cb_end'><span class='cb_ttl'><a href='?enter=$LinkKey'> Подать заявку </span></span></div> </a></div>";
    else
    echo div('foot center')." <div class='cbtn blue center mt4'><span class='cb_end'><span class='cb_ttl'><a href='?r=$LinkKey'> Обновить </span></span></div> </a>";


	
	
	



} 
/**
 * Закрываем подземелье
 */
elseif ($revolt['time_start'] <=  time() && $revolt['start'] == 0 )
{
	mysql_query("UPDATE `users` SET `LairReward`='0' WHERE `id`='".$user['id']."'");

	mysql_query("UPDATE `revolt` SET `start`='1' WHERE `id`='".$revolt['id']."'");

	/**
	 * Создаем демонов...
	 */
	
	for ($i = 0; $i<$demons; $i++)
	{
$hp2 = rand(5,15); //на сколько умнажаем жихни, параметры духов (что бы не повтарялись)
		mysql_query("INSERT INTO `revolt_mobs` SET `type`='demon',
													`str`='".($demonsParam['str']*$hp2 )."',
													`agi`='".($demonsParam['agi']*$hp2 )."',
													`def`='".($demonsParam['def']*$hp2 )."',
													`max_hp`='".($demonsParam['vit']*$hp2 )."',
													`hp`='".($demonsParam['vit']*$hp2 )."',
													`revolt`='".$revolt['id']."'");

	}


    exit();

} 
elseif ($revolt['time_start'] <= time()  && $revolt['start']  == 1 && $revolt['end'] == 0 && $revolt['time_left'] >  time()) 
{
    

	
	/**
	 * Если юзверь участвует в битве и она началась
	 */
	



	if (mysql_num_rows(mysql_query("SELECT `id` FROM `revolt_mobs` WHERE `dead`='0' and `revolt`='".$revolt['id']."'")) == 0 &&
			$membersCounter == 1 && $revolt['kill_boss'] == 1)
	{
	 /**
	 * Раздаём награду только в том случае если все духи и демон мертвы и в мятеже остался 1 игрок, иначе никто ничего не получит.
	 */  
	$v = mysql_query("SELECT * FROM `revolt_member` WHERE `revolt`='".$revolt['id']."'");
	
        while($row = mysql_fetch_array($v)) {
		
		  $users = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id`='".$row['user']."'"));
		  $gold = ($row['kill']*2);
		  $crystals = ($row['kill']*500);
		  $exp = ($row['kill']*500);
		  mysql_query("UPDATE `users` SET `gold` = `gold` + '".$gold."', `crystals`= `crystals` + '".$crystals."', `exp` = `exp` + '".$exp."' WHERE `id`='".$row['user']."'");
		  mysql_query("UPDATE `revolt_member` SET `nagrada`='1' WHERE `id`='".$row['id']."'");
        }
        
		$pobeda =  mysql_fetch_assoc(
				mysql_query(
						"SELECT * FROM `revolt_member` WHERE `dead`='0' and `revolt`='".$revolt['id']."'"
					)
			);
			
			
			$lider = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id`='".$pobeda['user']."'"));
			$crystals = $pobeda['kill']*700;
			$gold = $pobeda['kill']*2 + 150;
			$exp = $pobeda['kill']*500;
			?>
			
			<div class="block">

			<span class="small yellow">За победу получаете 150 золота.</span></br>
			<span class="small yellow"><span class="lime"> <?=$pobeda['kill']?></span> Убито противников.</span></br>
			<span class="lime"><b>Всего вы получаете:</b></span></br>
			<span class="small yellow"><?=$crystals?> Кристаллов, <?=$gold?> Золота, <?=$exp?> Опыта.</span></br>
			</div>
			<?

		
		mysql_query("UPDATE `users` SET `gold` = `gold` + '".$gold."' WHERE `id`='".$pobeda['user']."'");
		mysql_query("TRUNCATE `revolt`");
		mysql_query("TRUNCATE `revolt_mobs`");
		mysql_query("TRUNCATE `revolt_logs`");
		mysql_query("TRUNCATE `revolt_member`");
			
		
		//header("Location:/revolt");
		
		
require_once ('system/footer.php');
	exit;
	}


   

	if ($revoltMember)
	{

		$mobsCounter = mysql_num_rows(mysql_query("SELECT `id` FROM `revolt_mobs`WHERE `revolt`='".$revolt['id']."'and `type`= 'demon' and `dead`='0'"));






	    echo div('block_l');
	    
		if($mobsCounter > 0) echo color('tomato').' Враги '.$mobsCounter.'</font> VS';
		
	    echo color('lime').'<span style = "float:center;">  В бою героев  '.$membersCounter.'</font> </span> <span style = "float:right;">   '.ico('icons', 'time.png').'  '.isTimer($revolt['time_left']).' </span></div>';
	   
	

		







		



		/**
		 * Бой...
		 */
		


		if ($revoltMember['dead'] == 1)
		{
			?>

<div class="block_C">
		
				
					Вас убили! Дождитесь окончания.
			
		
	    <div class='cbtn blue center mt4'><span class='cb_end'><span class='cb_ttl'><a href='?r=$LinkKey'> Обновить </span></span></div> </a>

			</div>
			
			<?php
		} else {

			/**
			 * Определяем есть ли демон
			 */
			

			if ($mobsCounter == 0)
			{

				if (mysql_num_rows(mysql_query("
						SELECT * FROM `revolt_mobs` WHERE `type`='boss'
							and `revolt`='".$revolt['id']."' and `dead`='0'
					")) == 0 && $revolt['kill_boss'] == 0)
				{

					/**
					 * Выпускаем демона...
					 */
					
$hp_demon = rand(100,250);//умнажаем параметры демона :) минимум 500*100 максимум 500*250
					mysql_query("INSERT INTO `revolt_mobs` SET `revolt`='".$revolt['id']."',
																`str`='".$boss['str']*$hp_demon."',
																`def`='".$boss['def']*$hp_demon."',
																`agi`='".$boss['agi']*$hp_demon."',
																`max_hp`='".($boss['vit']*$hp_demon)."',
																`hp`='".($boss['vit']*$hp_demon)."',
																`type`='boss'

						");


				}

			}


			$boss = mysql_fetch_assoc(mysql_query(
				"SELECT * FROM `revolt_mobs` WHERE `revolt`='".$revolt['id']."' and `dead`='0' and `type`='boss'"
 
				));
				 header('Location: /lair/?PHP6SESSION='.$LinkKey.'');
    exit();
		

            /**
			 * Атака
			 */
			


			if (isset($_GET['attack']))
			{
				$attack = htmlspecialchars(trim($_GET['attack']));
				
				if($revoltMember['cooldown'] < time()){

				/**
				 * Мочим духов!
				 */
				if ($attack == 'mob')
				{
					if ($mobsCounter > 0)
					{
						if($revoltMember['target'] == 0){

								$enemy = mysql_fetch_assoc(mysql_query("SELECT * FROM `revolt_mobs` 
																	WHERE `dead`='0' and `revolt`='".$revolt['id']."' ORDER BY RAND()"));						
								mysql_query("UPDATE `revolt_member` SET `target`='".$enemy['id']."' WHERE `user`='".$user['id']."'");
 header('Location: /lair/?PHP7SESSION='.$LinkKey.'');
						       exit;
						}else{
						
								$enemy = mysql_fetch_assoc(mysql_query("SELECT * FROM `revolt_mobs` 
																				WHERE `id`='".$revoltMember['target']."' and `revolt`='".$revolt['id']."'
																"));													
						}
						
					} else {
					}
                    
                /**
				 * Мочим Демона!
				 */
				}elseif ($attack == 'boss') {

					if ($boss)
					{
						$enemy =&$boss;
					} else {
					}
                /**
				 * Мочим игроков!
				 */
				} elseif ($attack == 'user'){
						
						if($revoltMember['target'] == 0){
								$q = mysql_query("SELECT * FROM `revolt_member` WHERE `dead`='0' and `revolt`='".$revolt['id']."' and `user` != '".$user['id']."' ORDER BY RAND()");
								$q = mysql_fetch_array($q);
	                          

						if (!$q)
							{
 header('Location: /lair/?PHP8SESSION='.$LinkKey.'');
								exit;
							}
						

								$enemy = mysql_fetch_assoc(mysql_query(
										"SELECT * FROM `users` WHERE `id`='".$q['user']."'"));
								mysql_query("UPDATE `revolt_member` SET `target`='".$enemy['id']."' WHERE `user`='".$user['id']."' and `revolt`='".$revolt['id']."'");
								header("Location:/revolt");
						}else{
						
						$enemy = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` 
																	WHERE `id`='".$revoltMember['target']."'
															"));
						
						}
					
				}
			

	
				$admg = 0;
				$dmg = 0;
				
		$ran = rand(30,45);
		$otbil = round(100 / ( 32000 / $user['def']));
        $otbil +=$ran;
		$otbil = 100 - $otbil;
		$uda=$user['str']/4;		
		$dmg=round((rand($uda,$user['str'])) / 100 * $otbil);
	#Атака моба.
			$chase_attack = rand(0,23);
			$chase_attack2 = rand(0,100);
		
	
			
			$ran = rand(30,35);
			$otbil2 = round(100 / ( 30000 / $user['def']));
			$otbil2 +=$ran;
			$otbil2 = 100 - $otbil2;
			$udar2=$enemy['str']/100*10;		
	        $r  = rand(1,3);
	        if($r == 1){
			$admg = ceil(($user['str']/12)); // Чем сильнее игрок, тем сильнее удары мобов.
		
			if ($admg>=$revoltMember['health']) {
					

					if ($attack == 'mob')
					{
						mysql_query("UPDATE `revolt_member` SET `dead`='1' WHERE `user`='".$user['id']."' and `revolt`='".$revolt['id']."'");				
						$log = '<span class=""><span class="red"> Враг</span> убил игрока <span class="lime">'.$user['login'].'</span></span>';
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");
 header('Location: /lair/?PHP9SESSION='.$LinkKey.'');
					} elseif ($attack == 'boss') {
					
						mysql_query("UPDATE `revolt_member` SET `dead`='1' WHERE `user`='".$user['id']."' and `revolt`='".$revolt['id']."'");				
						$log = '<span class="sma"><span class="red"> Босс</span> убил игрока <span class="lime">'.$user['login'].'</span></span>';
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");
 header('Location: /lair/?PHP10SESSION='.$LinkKey.'');
						exit;
						
					}
					
					}else{
					
					
					if ($attack == 'mob'  && $mobsCounter > 0)
					{
						mysql_query("UPDATE `revolt_member` SET `health`=`health`-'$admg' WHERE `user`='".$user['id']."'");
						$log = '<span class="red">Враг</span> ударил <span class="lime">'.$user['login'].'</span> на '.$admg.'</span>';
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");
					} elseif ($attack == 'boss' && $revolt['kill_boss'] == 0) {
						# code...
						mysql_query("UPDATE `revolt_member` SET `health`=`health`-'$admg' WHERE `user`='".$user['id']."'");
						$log = '<span class="red">Босс</span> ударил <span class="lime">'.$user['login'].'</span> на'.$admg.'</span>';
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");
					}
					
					}	
					
					}
		
		
		if($dmg<=0) {$dmg = rand(5,10);}
				
				if ($dmg>=$enemy['hp']) {
					
					$dmg = ceil($user['str']/4);

					if ($attack == 'mob'  && $mobsCounter > 0)
					{
						$kill = $revoltMember['kill'] + 1;
						mysql_query("UPDATE `revolt_member` SET `target`='0', `kill`='".$kill."' WHERE `user`='".$user['id']."' and `revolt`='".$revolt['id']."'");
						mysql_query("UPDATE `revolt_mobs` SET `dead`='1',`hp`=0 WHERE `id`='".$enemy['id']."'");
						$log = ' <span class="lime">'.$user['login'].'</span> убил <span class="red">врагa</span>';
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");
						header("Location:/revolt");
                        exit;
					} elseif ($attack == 'boss' && $revolt['kill_boss'] == 0) {
			
						$log = '<span class="lime"> '.$user['login'].'</span> убил <span class="red">врага</span>';						
						
					
						
						mysql_query("UPDATE `revolt_mobs` SET `dead`='1',`hp`=0 WHERE `type`='boss'");
						mysql_query("UPDATE `revolt` SET `kill_boss`='1' WHERE `id`='".$revolt['id']."'");
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");
						header("Location:/revolt");
					
                    } elseif ($attack == 'user') {
						
                        $kill = $revoltMember['kill'] + 1;
						
						
						mysql_query("UPDATE `revolt_member` SET `target`='0', `kill`='".$kill."' WHERE `user`='".$user['id']."' and `revolt`='".$revolt['id']."'");					
						mysql_query("UPDATE `revolt_member` SET `dead`='1' WHERE `user`='".$enemy['id']."' and `revolt`='".$revolt['id']."'");
						$log = '<span class="lime"> '.$user['login'].'</span> убил игрока <span class="red">'.$enemy['login'].'</span></span>';
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");
 header('Location: /lair/?PHP11SESSION='.$LinkKey.'');
                        exit;
                        
					}


					
				} else {


					if ($attack == 'mob')
					{
					                             	mysql_query("UPDATE `users` SET `LairAllDmg`=``LairAllDmg` + '$dmg' WHERE `user`='".$user['id']."'");

						mysql_query("UPDATE `revolt_mobs` SET `hp`=`hp`-'$dmg' WHERE `id`='".$enemy['id']."'");
						$log = '<span class="lime">'.$user['login'].'</span> ударил <span class="red"> врага</span> на '.$dmg.'</span>';
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");
					} elseif ($attack == 'boss') {
						# code...
						                         	mysql_query("UPDATE `users` SET `LairAllDmg`=``LairAllDmg` + '$dmg' WHERE `user`='".$user['id']."'");

						mysql_query("UPDATE `revolt_mobs` SET `hp`=`hp`-'$dmg' WHERE `type`='boss'");
						$log = '<span class="lime">'.$user['login'].'</span> ударил <span class="red">врага</span> на '.$dmg.'</span>';
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");
					} elseif ($attack == 'user') {
                         	mysql_query("UPDATE `users` SET `LairAllDmg`=``LairAllDmg` + '$dmg' WHERE `user`='".$user['id']."'");

						mysql_query("UPDATE `revolt_member` SET `health`=`health`-'$dmg' WHERE `user`='".$enemy['id']."'");
						$log = ' <span class="lime"> '.$user['login'].'</span> ударил игрока <span class="red">'.$enemy['login'].' </span> на '.$dmg.'</span>';
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");

					}



				}

				
				/**
				 * UPD cooldown
				 */
				

				mysql_query("UPDATE `revolt_member` SET `cooldown`='".(time()+3)."' WHERE `user`='".$user['id']."'");


				}else{
						$log = '<span class="lime"> '.$user['login'].'</span><span class="grey"> промахнулся</span></span>';
						mysql_query("INSERT INTO `revolt_logs` SET `time`='".time()."',`text`='$log',`revolt`='".$revolt['id']."',`user`='".$user['id']."'");

 header('Location: /lair/?PHP12SESSION='.$LinkKey.'');
				exit;
				
				}
				

			}

		/*
         * Интерфейс боя.
         */

			if ($mobsCounter > 0)
			{
			
				if($revoltMember['target'] == 0){

						$enemy = mysql_fetch_assoc(mysql_query("SELECT * FROM `revolt_mobs` 
																	WHERE `dead`='0' and `revolt`='".$revolt['id']."' ORDER BY RAND()"));						
						mysql_query("UPDATE `revolt_member` SET `target`='".$enemy['id']."' WHERE `user`='".$user['id']."'");
 header('Location: /lair/?PHP13SESSION='.$LinkKey.'');
						exit;
						
				}
				
			
	$enemy = mysql_fetch_assoc(mysql_query("SELECT * FROM `revolt_mobs` WHERE `id`='".$revoltMember['target']."' and `revolt`='".$revolt['id']."'"));
	$hp_progress_bot = round(100 / ($enemy['max_hp'] / $enemy['hp']));
	$hp_progress_user = round($revoltMember['health'])/($user['max_health']/100);
?>

			<div class="block_l">
		   Враг <img src="/images/icons/health.png" alt="*"/> <?=$enemy['hp']?> </div>
<div class='exp_bar'>
                    <div class='life_bar-green fl' style='width:<?=$hp_progress_bot?>%'></div>
                </div>
                	
				<div class="header">
				
<div class='cbtn red center mt3'><span class='cb_end'><span class='cb_ttl'><a  href="?attack=mob"> Атаковать</div></span></span></a>
<div class='cbtn blue center mt3'><span class='cb_end'><span class='cb_ttl'><a  href="?last=mob" > Сменить цель </div></span></span></a>
				</div></div>
				
                
			<div class="block_l">
			<? echo ava($user);?> Вы <img src="/images/icons/health.png" alt="*"/> <?=$revoltMember['health']?><br></div>
			<div class='exp_bar'>
            <div class='progress_life' style='width:<?=$hp_progress_user?>%'>
            </div>
        </div>
        
			

				<?php

			}


			if ($boss)
			{
	$enemy =&$boss;
	$hp_progress_bot = round(100 / ($enemy['max_hp'] / $enemy['hp']));
	$hp_progress_user = round($revoltMember['health'])/($user['max_health']/100);

?>

	<div class="block_l"> Босс <img src="/images/icons/health.png" alt="*"/> <?=$enemy['hp']?>
<div class='exp_bar'>
                    <div class='life_bar-green fl' style='width:<?=$hp_progress_bot?>%'></div>
                </div>
				</div>
				
			<div class="block_l">
			<?echo ava($user);?> <img src="/images/icons/health.png" alt="*"/> <?=$revoltMember['health']?><br></div>
			<div class='exp_bar'>
            <div class='progress_life' style='width:<?=$hp_progress_user?>%'>
            </div>
        </div>
		
				<div class="header">
				
<div class='cbtn red center mt3'><span class='cb_end'><span class='cb_ttl'><a  href="?attack=boss"> Атаковать</div></span></span></a>

				</div>
				

				<?php
			}




			if ($membersCounter > 1 && $revolt['kill_boss'] == 1)
			{
			
				if($revoltMember['target'] == 0){

						$q = mysql_query("SELECT * FROM `revolt_member` WHERE `dead`='0' and `revolt`='".$revolt['id']."' and `user` != '".$user['id']."' ORDER BY RAND()");
						$row = mysql_fetch_array($q);
	
					 header('Location: /lair/?PHP14SESSION='.$LinkKey.'');
    exit();
						/* Если не ту врага...
						*/

				if (!$row)
					{
				 header('Location: /lair/?PHP15SESSION='.$LinkKey.'');
    exit();
					}
						

					mysql_query("UPDATE `revolt_member` SET `target`='".$enemy['id']."' WHERE `user`='".$user['id']."' and `revolt`='".$revolt['id']."'");
					 header('Location: /lair/?PHP16SESSION='.$LinkKey.'');
    exit();
						
				}
	 $enemy = mysql_fetch_assoc(mysql_query("SELECT * FROM `revolt_member` WHERE `id`='".$revoltMember['target']."'"));

	$hp_progress_bot = round((($enemy['health'])/$enemy['max_health']/100)); 
	$hp_progress_user = round($revoltMember['health'])/($user['max_health']/100); ?>

<div class="block_l"><? echo ava($user);?> Вы <img src="/images/icons/health.png" alt="*"/> <?=$user['health']?><br></div><div class='exp_bar'>
<div class='progress_life' style='width:<?=$hp_progress_user?>%'></div></div></div>
		
				
<div class="header">
<div class='cbtn red center mt3'><span class='cb_end'><span class='cb_ttl'><a  href="?attack=user"> Атаковать</div></span></span></a>
<div class='cbtn blue center mt3'><span class='cb_end'><span class='cb_ttl'><a  href="?last=user" > Сменить цель </div></span></span></a>
</div>

<div class="block_l"><? echo  ava($enemy);?> <?=$enemy['login']?> <img src="/images/icons/health.png" alt="*"/> <?=$enemy['health']?>
<div class='exp_bar'><div class='progress_life' style='width:<?=$hp_progress_bot?>%'></div></div></div>
                
				
				<?php


			}

			?><div class="foot"><?

				$logs=mysql_query("SELECT * FROM `revolt_logs` WHERE `revolt`='".$revolt['id']."' ORDER BY `id` DESC LIMIT 16");

			if(mysql_num_rows($logs)=='0'){
			
			?><span class='grey'>Битва началась</span><?
			
			}elseif (mysql_num_rows($logs)>0) {
			
					while ($log=mysql_fetch_array($logs)) {
					
					?><?=$log['text'];?><br><?
			}	
	}
	
	?></div><?
			
		
			// Если мы хотим поменять цель.
			if (isset($_GET['last']))
			{
				$last = htmlspecialchars(trim($_GET['last']));

				/**
				 * Attack mob!
				 * @var [type]
				 */
				if ($last == 'mob'){
				
					$enemy = mysql_fetch_assoc(mysql_query("SELECT * FROM `revolt_mobs` 
																	WHERE `dead`='0' and `revolt`='".$revolt['id']."' ORDER BY RAND()"));		
					mysql_query("UPDATE `revolt_member` SET `target`='".$enemy['id']."' WHERE `user`='".$user['id']."'");
						
				}elseif ($last == 'user') {
				
						$q = mysql_query("SELECT * FROM `revolt_member` WHERE `dead`='0' and `revolt`='".$revolt['id']."' and `user` != '".$user['id']."' ORDER BY RAND()");
						$q = mysql_fetch_array($q);
						/**
						* Если не ту врага...
						*/

					if (!$q)
					{
 header('Location: /lair/?PHP17SESSION='.$LinkKey.'');
    exit();
					}
						$enemy = mysql_fetch_assoc(mysql_query(
							"SELECT * FROM `users` WHERE `id`='".$q['user']."'"
						));
						mysql_query("UPDATE `revolt_member` SET `target`='".$enemy['id']."' WHERE `user`='".$user['id']."'");
				
				
					}
 header('Location: /lair/?PHP18SESSION='.$LinkKey.'');
    exit();
			}
			
		
		
			exit;
			


		}







	} else {

		/**
		 * Если не участвует и она началась
		 */
		

		?>
		
		<div class="block_c">
		Вы опоздали, Подземелье закрыто! Ждите окончание боя  </div>
		
			</div>

		

		<div class="foot"><?

				$logs=mysql_query("SELECT * FROM `revolt_logs` WHERE `revolt`='".$revolt['id']."' ORDER BY `id` DESC LIMIT 16");

			if(mysql_num_rows($logs)=='0'){
			
		
			
			}elseif (mysql_num_rows($logs)>0) {
			
					while ($log=mysql_fetch_array($logs)) {
					
					?><span><?=$log['text'];?></span></br><?
			}	
	}
	?></div>
		
		<?php


	}





}





require_once ('system/footer.php');
?>