<?php
include 'core/sys.php';
include 'core/func_war.php';
$teleport_cen = 50;
reg();
if(isset($_GET['id']) and !empty($_GET['id'])){
$id = int($_GET['id']);
$cena_tel = $teleport_cen*$id;
$room = mysql_fetch_assoc(mysql_query("SELECT * FROM `room` WHERE `id`='".$id."' LIMIT 1"));
head($room['name']);
	if(!$room){
	echo '<div id="error">
	Комнаты не существует!
	</div>';
	foot();
	exit;
	}
	if($user['money']<$cena_tel and $user['in_loc'] != $id){
	echo '<div id="error">
	Недостаточно денег для телепорта</div>';
	foot();
	exit;
	}
	if($user['in_loc'] != $id){
	
	$kazna_money = round($cena_tel/100*15);
	echo '<div id="ok">
	Оплата телепортации: - <img src="img/money/money.png" alt=""> '.$cena_tel.'<br>';
	$kazna_us_q = mysql_fetch_assoc(mysql_query("SELECT `login`,`id` FROM `users` ORDER BY `win` DESC LIMIT 1"));
	if($kazna_us_q['id'] != $user['id']){
	mysql_query("UPDATE `users` SET `money`=`money`+".$kazna_money." WHERE `id` = '".$kazna_us_q['id']."'");
	echo 'Альфа-Одаренный <b>'.$kazna_us_q['login'].'</b> получает <img src="img/money/money.png" alt=""> '.$kazna_money;
	}
	echo '</div>';
	mysql_query("UPDATE `users` SET 
	`in_loc`='".$id."',
	`money`=`money`-".$cena_tel."	WHERE `id`='".$user['id']."'");
	}
echo '<div class="text"><a href="war.php">Локации</a>-> '.$room['name'].' <Spam style="float: right;">[<a href="war.php?id='.$room['id'].'">Ждать</a></span>]</div>';
/* Бешенство монстров*/
$time_agr = array(12,15,18,21);
$hour_agr = date("H",time());
$rand_agr = rand(1,12);
$rand_t_agr =  rand(1,3);

	if(in_array($hour_agr,$time_agr) and $user['health']>$rand_agr){
	echo '<div id="error">Сейчас время бешенства .Будьте осторожны! Монстры могут напасть в любую минуту<br>';
		if($rand_t_agr==1){
		$rand_agr_slov = array('царапнул','укусил','ранил');
		shuffle($rand_agr_slov);
		$rand_monster = mysql_fetch_assoc(mysql_query("SELECT * FROM `monster` WHERE `dead`=0 AND `room_id`='".$id."' ORDER BY RAND() LIMIT 1"));
		$rand_m_name = mysql_fetch_assoc(mysql_query("SELECT * FROM `monster_name` WHERE `id`='".$rand_monster['monster_id']."' LIMIT 1"));
		echo '<b>'.$rand_m_name['name'].'</b> '.$rand_agr_slov[1].' на <b>'.$rand_agr.'</b><br><a href="attack.php?monstr='.$rand_monster['id'].'&amp;room='.$id.'">Ударить в ответ</a>';

		mysql_query("UPDATE `users` SET `health`=`health`-".$rand_agr.",`health_resp`='".time()."' WHERE `id`='".$user['id']."'");
		}
	echo '</div>';
	}
/*************/
echo '<div class="row">';
$total = mysql_result(mysql_query("SELECT COUNT(id) FROM `monster` WHERE `room_id`='".$room['id']."'"),0); 
$sql_monster = mysql_query("SELECT * FROM `monster` WHERE `room_id`='".$room['id']."' ORDER BY `level` LIMIT ".$page.",".$set['str']." ");
while($row_monster = mysql_fetch_assoc($sql_monster)){
$monst_name = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `monster_name` WHERE `id`='".$row_monster['monster_id']."'"));
if($row_monster['dead']==0){
			$stranica  ='';
			if(!empty($_GET['page'])){
			$stranica = '&page='.$_GET['page'];
			}
echo '<img src="img/mob/'.$id.'.png"> <a href="attack.php?monstr='.$row_monster['id'].'&amp;room='.$id .$stranica.'"> '.$monst_name['name'].'</a> 
|<a href="monster.php?m='.$row_monster['id'].'">инфо</a> [Уровень: '.$row_monster['level'].'| HP: '.$row_monster['health'].'/'.$row_monster['max_health'].']<br>';
}else{
$min_2 = 60*2; ///Респа через 2 мин
$t_resp = time()-$row_monster['dead_time'];
if($t_resp >= $min_2 ){
mysql_query("UPDATE `monster` SET `health`='".$row_monster['max_health']."',`dead`=0,`dead_time`=0 WHERE `id`='".$row_monster['id']."'");
}
$vozroj_time = $min_2 - $t_resp;
	if($vozroj_time <= 0){
	$vozroj = 'сейчас';
	}else{
	$vozroj = date("i:s",$vozroj_time );
	}
echo '<b>'.$monst_name['name'].'</b> (мертв|Возрождение '.$vozroj.') [Уровень: '.$row_monster['level'].']<br>';
}
}
echo '</div>';

$in_loc = mysql_query("SELECT `id`,`login`,`time`,`level` FROM `users` WHERE `in_loc`='".$id."' AND `time`+300>".time()." LIMIT 20");
$c_in_loc = mysql_num_rows($in_loc );
	echo '<div class="name" style="font-size: 75%;">тут: ';
	if($c_in_loc > 0){
		
		while($pers_loc = mysql_fetch_assoc($in_loc)){			
			echo '<a href="pers.php?ank='.$pers_loc['id'].'">'.$pers_loc['login'].'</a>['.$pers_loc['level'].']';
		}
		
		}else echo 'никого';
	echo '</div>';
    if($total > $set['str'])
	{
		pages($page, $total, 'war.php?id='.$room['id'].'&amp;', $set['str']);
	}

}else{
head('Локации');
$sql_rooms = mysql_query("SELECT * FROM `room`");


echo '<div class="row">';
while ($rooms=mysql_fetch_assoc($sql_rooms)){
$row_telep = $teleport_cen*$rooms['id'];
if($user['in_loc']==$rooms['id']){
$row_telep = 0;
}

echo '<div class="loc'.$rooms['id'].'" id="hover_loc"><a id="link_loc" href="war.php?id='.$rooms['id'].'">'.$rooms['name'].'</a> <span style="float: right;font-size: 80%;padding-right:1px; text-shadow: 1px 1px #000">телепорт: <img src="img/money/money.png" alt=""> '.$row_telep.'</span><br></div>';
}
echo '</div>';
}
foot();
?>