<?
define('PROTECTOR', 1);

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

@include('files/db.php');
@include('files/auth.php');
@include('files/func.php');
going();
ryd();
place_city();
place_tower();
@include('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('files/head.php');
@include('files/zag.php');
////////////////////////
$random=rand(1000,9999);
////////////////

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]' ORDER BY lvl DESC");
//////////////////////////////
echo"<div align='center'><b><font color ='lime'>$world[name]</b></font></div>";
if($mestouser[x]==0)
if($mestouser[y]==0)
echo"<div align='center'>Если Вы хотели попасть в другое место, но попали сюда - Вам следует перейти для начала в Город</div>";

echo"<div align='center'><b><font color='red'>X</font>: $mestouser[x]; <font color='red'>Y</font>: $mestouser[y]</b></div>";
$x=htmlspecialchars($mestouser[x]);
$y=htmlspecialchars($mestouser[y]);
if($udata[prava]==3){echo"<a href=\"mod_panel.php?mod=6&x=$x&y=$y\">Изменить мобов</a></br><a href=\"mod3.php?mod=5&x=$x&y=$y\">Создать моба</a></br>";}
if($udata[prava]==5){echo"<a href=\"adm_panel.php?mod=6&x=$x&y=$y\">Изменить мобов</a></br><a href=\"cpanel.php?mod=5&x=$x&y=$y\">Создать моба</a></br>";}
$avto=mysql_num_rows($req);
if($avto>=1){
echo'<b>Монстры:</b><br/>';

While($mob = mysql_fetch_array($req))
{
if($mob['tip']=='boss'){
$color='#e94038';
}else{
$color='#FF803A';
}
if($mob[status]==on){
echo"<a href=\"ok.php?id=$mob[id]\"><font color='$color'>$mob[name]</font></a> (<img src=\"pic/hp.png\" alt=\"*\"/>$mob[hp] <img src=\"pic/up.png\" alt=\"*\"/>$mob[lvl]) ";
$vrag = mysql_query("SELECT * FROM `tmp` WHERE `mob`= '$mob[id]'");
$vr = mysql_fetch_array($vrag);
if(!empty($vr[usr])){echo" vs <a href=\"search.php?nick=$vr[usr]&amp;go=go\"><font color='$5ade36'>$vr[usr]
</font></a>";}
else{echo"[<a href=\"okrestnosti.php?mod=info&amp;id=$mob[id]\">Инфо</a>]";}
echo"<br/>"; 
}
elseif($mob[status]==battle){
$r = mysql_query("SELECT * FROM `tmp` WHERE `city` = '$udata[city]' AND `usr`='$mob[oponent]' LIMIT 1");
$m = mysql_fetch_array($r);
$d = time();
if(($d>=($m['ltime']+600) and $mob[hp]<=0) or $d>=($m['ltime']+600)){
mysql_query("UPDATE `mob` SET `status`='on',`hp`='$mob[hpall]', `oponent`='not' WHERE `id` = '$mob[id]'");
$req = mysql_query("SELECT * FROM `users` WHERE `usr` = '$mob[oponent]' LIMIT 50");
$mu = mysql_fetch_array($req);

$nloses=$mu[loses]+1;
mysql_query("UPDATE users SET loses = '$nloses',hp='0' WHERE usr = '$mob[oponent]'");//пишем данные в плэера
mysql_query("DELETE FROM `tmp` WHERE usr='$mob[oponent]'");
mysql_query("DELETE FROM `log` WHERE usr='$mob[oponent]'");

echo"<a href=\"ok.php?id=$mob[id]\"><font color='$color'>$mob[name]</font></a> (<img src=\"pic/hp.png\" alt=\"*\"/>$mob[hp] <img src=\"pic/up.png\" alt=\"*\"/>$mob[lvl]) [<a href=\"okrestnosti.php?mod=info&amp;id=$mob[id]\">Инфо</a>]<br/>";
}else{
echo"<b><a href=\"okrestnosti.php?mod=info&amp;id=$mob[id]\"><font color='$color'>$mob[name]($mob[hp]/$mob[hpall])</font></a> против <a href=\"search.php?nick=$mob[oponent]&amp;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]\"> Бить</a> <a href=\"okrestnosti.php?mod=info&amp;id=$mob[id]\"><font color='$color'>$mob[name]($mob[hpall] хп)</font></a><br/>";
}else{
echo"";}}}}
///////////////игроки
if($odin==false){
$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);//город
if($mestouser['city']==$mesto[city] && $cit[city]==$udata[city] && $mesto[x]==$mestouser['x'] && $mesto[y]==$mestouser['y']){
if($cit[storona]==$udata[storona]){echo'<b>Игроки:</b><br/><font color="green">Союзник: ';}else{
echo'<b>Игроки:</b><br/><font color="red">Враг: ';}
idlog($idlog=$who[usr]); echo" <a href=\"ok.php?k=pk&amp;id=$cit[id]\">Бить($cit[hp] хп)</a></font><br/>";
$odin=true;}}}

/////////////////
echo"<b>Локации:</b><br/>";
if($world[incity]==1){echo"<img src=\"pic/main/gate.png\" alt=\"[город]\"/> <a href=\"to_gorod.php?\">Город</a><br/>";}
if($world[portal]==1){echo"<img src=\"pic/game/portal.png\" alt=\"[портал]\"/> <a href=\"okrestnosti.php?mod=portal\">Портал</a><br/>";}
if($le==1){echo"<img src=\"pic/game/vlevo.png\" alt=\"[влево]\"/> <a href=\"okrestnosti.php?mod=go_left\">$left[name]</a><br/>";}
if($ri==1){echo"<img src=\"pic/game/vpravo.png\" alt=\"[вправо]\"/> <a href=\"okrestnosti.php?mod=go_right\">$right[name]</a><br/>";}
if($do==1){echo"<img src=\"pic/game/vniz.png\" alt=\"[вниз]\"/> <a href=\"okrestnosti.php?mod=go_down\">$down[name]</a><br/>";}
if($up==1){echo"<img src=\"pic/game/vverh.png\" alt=\"[вверх]\"/> <a href=\"okrestnosti.php?mod=go_up\">$upo[name]</a><br/>";}
echo"<img src=\"pic/game/karta.png\" alt=\"[открыть карту]\"/> <a href=\"karta.php?\">Карта (-5 энергии)</a><br/>";
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('files/down.php');exit;}
$mob = mysql_fetch_array($req);

echo"<b>$mob[name]</b><br/>";
echo"Уровень: $mob[lvl]<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=\"okrestnosti.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: okrestnosti.php?");exit;
}else{
header("Location: okrestnosti.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: okrestnosti.php?");exit;
}else{
header("Location: okrestnosti.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: okrestnosti.php?");exit;
}else{
header("Location: okrestnosti.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: okrestnosti.php?");exit;
}else{
header("Location: okrestnosti.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('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=\"okrestnosti.php?\">Далее</a>";
echo'</div>';
include('files/down.php');exit;}else{
echo"В этой локации нет портала!<br/>";}}
echo"<b>Город:</b><br/>";
echo"<a href=\"okrestnosti.php?mod=portal&amp;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=\"okrestnosti.php?mod=portal&amp;act=loc&amp;id=$mob[id]\">$mob[name]</a><br/>";}
echo"<a href=\"okrestnosti.php?\">Назад</a>";}else{
echo"В этой локации нет портала!<br/>";}
echo'</div>';
break;}
@include('files/down.php');
?>
