<?
define('PROTECTOR', 1);

$headmod = 'okrestnosti';//фикс. места

include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
going();
ryd();
sha();
place_city();
place_zamok();
place_tower();
include($path.'files/core.php');
/////////место
$req = mysql_query("SELECT * FROM `mesto` WHERE `usr` = '$log' LIMIT 1");
////////////////////////////
$mestouser = mysql_fetch_array($req);
/////////////////////////////////////////
$req = mysql_query("SELECT * FROM `world` WHERE `city` = '$udata[city]' and `x`='$mestouser[x]' and `y`='$mestouser[y]'");
$world = mysql_fetch_array($req);
//////////////////////////////////////////
if($_GET[mod]==go_left or $_GET[mod]==go_right or $_GET[mod]==go_up or $_GET[mod]==go_down){
$header=TRUE;
}else{
if(empty($world[name])){
$textl='Окрестности';}else{
$textl=$world[name];
}
}
include($path.'files/head.php');
include($path.'files/zag.php');
////////////////////////
$random=rand(1000,9999);
////////////////



$timeout = time() - 150;

$asd = mysql_num_rows(mysql_query("SELECT laikas, usr FROM online WHERE laikas > '$timeout' AND usr='$pk[usr]'"));
////////////////////////////





switch($_GET[mod]){

default:


$xi=$mestouser[x]-1;
$xmi=$mestouser[x]+1;
$yi=$mestouser[y]-1;
$ymi=$mestouser[y]+1;
#################################
if($world['br']=='0'){
$req = mysql_query("SELECT name FROM world WHERE `city` = '$udata[city]' AND `x` = '$xmi' AND `y`='$mestouser[y]' LIMIT 1");
$ri=mysql_num_rows($req);
if($ri==1){
$right = mysql_fetch_array($req);
}
}
################################
if($world['bl']=='0'){
$req = mysql_query("SELECT name FROM world WHERE `city` = '$udata[city]' AND `x` = '$xi' AND `y`='$mestouser[y]' LIMIT 1");
$le=mysql_num_rows($req);
if($le==1){
$left = mysql_fetch_array($req);
}
}
##############################
if($world['bu']=='0'){
$req = mysql_query("SELECT name FROM world WHERE `city` = '$udata[city]' AND `y` = '$ymi' AND `x`='$mestouser[x]' LIMIT 1");
$up=mysql_num_rows($req);
if($up==1){
$upo = mysql_fetch_array($req);
}
}
#######################################
if($world['bd']=='0'){
$req = mysql_query("SELECT name FROM world WHERE `city` = '$udata[city]' and `y` = '$yi' and `x`='$mestouser[x]' LIMIT 1");
$do=mysql_num_rows($req);
if($do==1){
$down = mysql_fetch_array($req);
}
}
$req = mysql_query("SELECT * FROM `mob` WHERE `city` = '$udata[city]' and `x`='$mestouser[x]' and `y`='$mestouser[y]' and `clan` = '$udata[clan]' ORDER BY lvl DESC");

//////////////////////////////
echo"<div align='center'><b>$world[name]</b></div>";
echo"<div align='center'><b>Бой с КБ может начать только лидер клана</b></div>";
echo"<div align='center'><b><font color='red'>X</font>: $mestouser[x]; <font color='red'>Y</font>: $mestouser[y]</b></div>";
echo"<div align='center'><b><a href=\"okrestnosti1.php?&r=$random\">Ждать</a></b></div>";
///////////////Тест
if($udata[info_karta] == 1){
echo"<div align='center'>";
$x=$mestouser['x']-3;
$y=$mestouser['y']+3;

$wave=1;
$table=1;

echo'<table>';

while($wave<='49'){

if($table=='8'){$table='1';$x=$x-'7';$y=$y-'1';}
$locas = mysql_result(mysql_query("SELECT COUNT(*) FROM `world`  WHERE `city` = '$udata[city]' and `x`='$x' and `y`='$y' LIMIT 1"),0);
if($locas=='1'){
$xy = mysql_fetch_assoc(mysql_query("SELECT `bu`,`bd`,`br`,`bl` FROM `world` WHERE `city` = '$udata[city]' and `x`='$x' and `y`='$y' LIMIT 1"));
}
////////////////////////////////////
$locas1 = mysql_result(mysql_query("SELECT COUNT(*) FROM `world`  WHERE `city` = '$udata[city]' and `x`='$x' and `y`='$y' and `portal` = '1' LIMIT 1"),0);
if($locas1=='1'){
$xy['color']='blue';
}
///////////////////////////////////
$locas2 = mysql_result(mysql_query("SELECT COUNT(*) FROM `mob`  WHERE `city` = '$udata[city]' and `x`='$x' and `y`='$y' and `tip` = 'boss' and `clan` = '$udata[clan]' LIMIT 1"),0);
if($locas2=='1'){
$xy['color']='red';
}
///////////////////////////////////
if($locas=='0'){

$xy['color']='black';
}
if($table=='1')echo'<tr border="0" HEIGHT="15">';



echo'<td WIDTH="15" BGCOLOR="'.$xy['color'].'">';
if($mestouser['x']==$x && $mestouser['y']==$y){
echo'<img src="pic/main/player.png" alt="*">';
}

echo'</td>';

if($table=='7')echo'</tr>';

$wave++;
$table++;
$x++;
}

echo'</table></div>';
}

////////////////Тест
$avto=mysql_num_rows($req);
$req1 = mysql_query("SELECT * FROM `mob` WHERE `city` = 'clan_city' and `clan` = '$udata[clan]'");
$avto1=mysql_num_rows($req1);
if($avto1 == 0 and $udata[clan_prava] == 5){
mysql_query("INSERT INTO `mob` (`id`, `name`, `lvl`, `city`, `hp`, `hpall`, `umin`, `umax`, `pgolova`, `pbody`, `pnogi`, `pmag`, `krit`, `ukrit`, `antikrit`, `lovk`, `sd`, `drop`, `ss`, `shems`, `sm`, `money`, `exp`, `tip`, `status`, `time`, `oponent`, `quest`, `x`, `y`, `text`, `clan`, `clan_lvl`) VALUES (NULL, 'Маг-отшельник', '50', 'clan_city', '4500', '4500', '40', '120', '100', '100', '100', '60', '50', '10', '50', '25', '90', '50', '90', '50', '90', '2500', '2500', 'boss', 'on', '86400', 'not', '', '0', '0', '', '$udata[clan]', '')");}
if($avto>=1){
echo'<b>Монстры:</b><br/>';

While($mob = mysql_fetch_array($req))
{
if($mob['tip']=='boss'){
$color='#e94038';
}else{
$color='#5ade36';
}

if($mob[status]==on){
//////////
if($udata[clan_prava] == 5){echo"<a href=\"ok.php?id=$mob[id]\"><font color='$color'>$mob[name]($mob[hp] хп, $mob[lvl] ур)</font></a> <a href=\"okrestnosti1.php?mod=info&id=$mob[id]\"><img src='pic/inf.png'></a><br/>";}
else{ echo"<font color='$color'>$mob[name]($mob[hp] хп, $mob[lvl] ур)</font> <a href=\"okrestnosti1.php?mod=info&id=$mob[id]\"><img src='pic/inf.png'></a><br/>";}

}
elseif($mob[status]== сbattle){
//////////
echo"<b><a href=\"ok.php?id=$mob[id]\"><font color='$color'>$mob[name]($mob[hp]/$mob[hpall])</font></a> против клана<a href=\"search.php?nick=$mob[oponent]&go=go\">$mob[oponent]</a></b><br/>";

}
elseif($mob[status]==off){
$d = time();
if($d>=($mob[oponent]+$mob[time])){

mysql_query("UPDATE `mob` SET `status`='on',`hp`='$mob[hpall]', `oponent`='not' WHERE `id` = '$mob[id]'");

echo"<a href=\"ok.php?id=$mob[id]\"><font color='$color'>$mob[name]($mob[hpall] хп, $mob[lvl] ур)</font></a> <a href=\"okrestnosti1.php?mod=info&id=$mob[id]\"><img src='pic/inf.png'></a><br/>";
}else{
if($mob[tip] ==boss){
//Время
$boss_time = $mob[oponent]+$mob[time]+3600;
$date_time_array = getdate($boss_time);
$hours = $date_time_array['hours'];
$minutes = $date_time_array['minutes'];
$seconds = $date_time_array['seconds'];
$month = $date_time_array['mon'];
$day = $date_time_array['mday'];
$year = $date_time_array['year'];
$boss_time = mktime($hours-1,$minutes-3,$seconds,$month,$day,$year);
$timeCode=strftime('%H:%M:%S',$boss_time);
//Конец
echo"<b><font color='$color'>$mob[name](труп)</font></b> [<b>$timeCode</b>] <img src='pic/inf.png'><br/> ";
}else{
}

}
}
}
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//

echo"<br /><b>Локации:</b><br/>";
if($world[incity]==1){echo"[город] <a href=\"to_gorod.php?\">Город</a><br/>";}
if($world[portal]==1){echo"[портал] <a href=\"okrestnosti1.php?mod=portal\">Портал</a><br/>";}
if($le==1){$x = $mestouser[x]-1; echo"[влево]<b> (X= $x; Y= $mestouser[y])</b> <a href=\"okrestnosti1.php?mod=go_left\">$left[name]</a><br/>";}
if($ri==1){$x = $mestouser[x]+1; echo"[вправо]<b> (X= $x; Y= $mestouser[y])</b> <a href=\"okrestnosti1.php?mod=go_right\">$right[name]</a><br/>";}
if($do==1){$y = $mestouser[y]-1; echo"[вниз]<b> (X= $mestouser[x]; Y= $y) </b><a href=\"okrestnosti1.php?mod=go_down\">$down[name]</a><br/>";}
if($up==1){$y = $mestouser[y]+1; echo"[вверх]<b> (X= $mestouser[x]; Y= $y) </b><a href=\"okrestnosti1.php?mod=go_up\">$upo[name]</a><br/>";}
echo"<br /><b><a href=okrestnosti1.php?mod=perss>Кто тут?</a></b><br/>";

break;

case 'perss':

///////////////игроки
echo'<b>Игроки на локации:</b><br/>';
$odin=false;
$timeout=time()-150;//оффлайн

$req = mysql_query("SELECT * FROM online WHERE laikas > '$timeout' and usr!='$log'");

////////////////////////////
While($who = mysql_fetch_array($req))
{
$reqs = mysql_query("SELECT * FROM `mesto` WHERE `usr` = '$who[usr]' LIMIT 1");
$mesto = mysql_fetch_array($reqs);//место

$reqs = mysql_query("SELECT id,city,storona,hp FROM `users` WHERE `usr` = '$who[usr]' LIMIT 1");
$cit = mysql_fetch_array($reqs);//город

//ddddddddddddddddddddddddddddddddddddddddddd

if($mestouser['city']==$mesto[city] && $cit[city]==$udata[city] && $mesto[x]==$mestouser['x'] && $mesto[y]==$mestouser['y']){
if($cit[storona]==$udata[storona]){echo'<font color="green">Союзник: ';}else{
echo'<font color="red">Враг:</font> ';
}
idlog($idlog=$who[usr]); if($cit[storona]==$udata[storona]){echo" ($cit[hp] хп)</font><br/>";} else{
if($udata[city] != fornost and $udata[city] != clan_city){ echo"<font color='red'> <a href=\"ok.php?k=pk&id=$cit[id]\">Бить($cit[hp] хп)</a></font><br/>";} else{ echo'<br/>'; } }
$odin=true;
}
}
echo'<a href=okrestnosti1.php>Назад</a>';
if($odin==false){
echo'Никого нет!<br/><a href=okrestnosti1.php>Назад</a>';
}
/////////////////
break;

case 'info':
$reqm = mysql_query("SELECT * FROM `mesto` WHERE `usr` = '$log' LIMIT 1");
$mm = mysql_fetch_array($reqm);
if(empty($mm[page])){$mm[page]=7;}
$id=$_GET[id];
$req = mysql_query("SELECT * FROM `mob` WHERE `city` = '$udata[city]' and `id`='$id' and `x`='$mestouser[x]' and `y`='$mestouser[y]' LIMIT 1");
////////////////////////////
if (mysql_num_rows($req)==0){echo"Такого монстра не существует.".mysql_num_rows($req);include($path.'files/down.php');exit;}
$mob = mysql_fetch_array($req);

echo"<b>$mob[name]</b><br/>";
echo"Уровень: $mob[lvl] ($mob[exp] опыта)<br/>";
echo"Шанс получения ресурса: $mob[sd]%<br/>";
echo"Шанс получения монет: $mob[sm]% ($mob[money] монет)<br/>";
echo"Шанс получения схемы: $mob[ss]%<br/>";
echo"Жизни: $mob[hp]/$mob[hpall]<br/>";
echo"Урон: $mob[umin]/$mob[umax]<br/>";
echo"Защита головы: $mob[pgolova]<br/>";
echo"Защита тела: $mob[pbody]<br/>";
echo"Защита ног: $mob[pnogi]<br/>";
echo"Защита от умений: $mob[pmag]<br/>";
echo"Ловкость: $mob[lovk]<br/>";
echo"Крит: $mob[krit]%<br/>";
echo"Крит-урон: $mob[ukrit]%<br/>";
echo"АНТИ-крит: $mob[antikrit]%<br/>";

echo"<a href=\"okrestnosti1.php?\">Назад</a>";
break;
case 'go_left':
$xi=$mestouser[x]-1;

$req = mysql_query("SELECT name FROM world WHERE `city` = '$udata[city]' AND `x` = '$xi' AND `y`='$mestouser[y]' LIMIT 1");
$le=mysql_num_rows($req);
if($le==1 and $world['bl']=='0'){
mysql_query("UPDATE `mesto` SET `x`='$xi' WHERE usr = '$log'");
header("Location: okrestnosti1.php?");exit;
}else{
header("Location: okrestnosti1.php?");exit;
}
//////////////////////////////////////////
break;
case 'go_right':
$xmi=$mestouser[x]+1;

$req = mysql_query("SELECT name FROM world WHERE `city` = '$udata[city]' AND `x` = '$xmi' AND `y`='$mestouser[y]' LIMIT 1");
$ri=mysql_num_rows($req);
if($ri==1 and $world['br']=='0'){
mysql_query("UPDATE `mesto` SET `x`='$xmi' WHERE usr = '$log'");
header("Location: okrestnosti1.php?");exit;
}else{
header("Location: okrestnosti1.php?");exit;
}
//////////////////////////////////////////
break;
case 'go_up':
$ymi=$mestouser[y]+1;

$req = mysql_query("SELECT name FROM world WHERE `city` = '$udata[city]' AND `y` = '$ymi' AND `x`='$mestouser[x]' LIMIT 1");
$up=mysql_num_rows($req);
if($up==1 and $world['bu']=='0'){
mysql_query("UPDATE `mesto` SET `y`='$ymi' WHERE usr = '$log'");
header("Location: okrestnosti1.php?");exit;
}else{
header("Location: okrestnosti1.php?");exit;
}
//////////////////////////////////////////
break;
case 'go_down':
$yi=$mestouser[y]-1;

$req = mysql_query("SELECT name FROM world WHERE `city` = '$udata[city]' and `y` = '$yi' and `x`='$mestouser[x]' LIMIT 1");
$do=mysql_num_rows($req);
if($do==1 and $world['bd']=='0'){
mysql_query("UPDATE `mesto` SET `y`='$yi' WHERE usr = '$log'");
header("Location: okrestnosti1.php?");exit;
}else{
header("Location: okrestnosti1.php?");exit;
}
//////////////////////////////////////////
break;
case 'portal':
echo'<div class="event">';
$req = mysql_query("SELECT * FROM world WHERE `city` = '$udata[city]' and `y` = '$mestouser[y]' and `x`='$mestouser[x]' and `portal`='1' LIMIT 1");
$do=mysql_num_rows($req);
if($do==1){
if($_GET[act]==city){

mysql_query("UPDATE `mesto` SET `place` = 'gorod',`city` = '0',`x` = '0',`y` = '0' WHERE `usr` = '$log'");
echo"Вы прибыли в город.<br/>";
echo"<a href=\"gorod.php?\">Далее</a>";
echo'</div>';
include($path.'files/down.php');exit;
}elseif($_GET[act]==loc){
$req = mysql_query("SELECT * FROM world WHERE `city` = '$udata[city]' and `id` = '$_GET[id]' and `portal`='1' LIMIT 1");
$do=mysql_num_rows($req);
if($do==1){
$citys = mysql_fetch_array($req);

mysql_query("UPDATE `mesto` SET `x` = '$citys[x]',`y` = '$citys[y]' WHERE `usr` = '$log'");

echo"Вы прибыли в локацию $citys[name].<br/>";
echo"<a href=\"okrestnosti1.php?\">Далее</a>";
echo'</div>';
include($path.'files/down.php');exit;
}else{
echo"В этой локации нет портала!<br/>";
}
}
echo"<b>Город:</b><br/>";
echo"<a href=\"okrestnosti1.php?mod=portal&act=city\">Город</a><br/>";

echo"<b>Местность:</b><br/>";
$req = mysql_query("SELECT * FROM world WHERE `city` = '$udata[city]' and `portal`='1'");
//////////////////////////////
While($mob = mysql_fetch_array($req)){

echo"<a href=\"okrestnosti1.php?mod=portal&act=loc&id=$mob[id]\">$mob[name]</a><br/>";

}
echo"<a href=\"okrestnosti1.php?\">Назад</a>";
}else{
echo"В этой локации нет портала!<br/>";
}
echo'</div>';
break;


}
include($path.'files/down.php');
?>