<?php
defined('PROTECTOR') or die('Error: restricted access');
function zasad(){}
function ryd(){
global $inryd;
if ($inryd=='1'){
header ('Location: rydnik.php?');exit;}}
//////////БОИ
function going(){
global $in_battle,$inpk,$inar,$inzasada;
///////////////////////////////БОЙ/////////////////////
if ($in_battle=='1'){
header ('Location: battle.php?');exit;}
/////////////////////////////////////////////////////////////////
elseif ($inpk=='1'){
header ('Location: pk.php?');exit;}
///////////////////////////////////////////////////////////////////
elseif ($inar=='1'){
header ('Location: combat.php?');exit;}}
##############################################################################################

function auto_clean(){
global $log;
$req=mysql_query("SELECT * FROM log WHERE usr = '$log' LIMIT 20");
$avto = mysql_num_rows($req);
if($avto>='20'){
$lim=round($avto/2);
mysql_query("DELETE FROM `log` WHERE `usr` = '$log' LIMIT $lim");}}

function del_log($lpl){
global $log;
mysql_query("DELETE FROM `log` WHERE `usr` = '$log' and `place` = '$lpl'");}

function log_msg($tlog){
global $log;
$req=mysql_query("SELECT * FROM log WHERE usr = '$log' and place='$tlog' and timer>='".time()."' ORDER BY id DESC LIMIT 6");
$avto = mysql_num_rows($req);
if($avto>=1){
echo'<div class="log">';
While($ilok = mysql_fetch_assoc($req))
{
if($ilok['kto']=='system'){$color='#AAAAAA';}
if($ilok['kto']=='user'){$color='#66FF66';}
if($ilok['kto']=='enemy'){$color='#FF6633';}
echo '<small><font color="'.$color.'">'.$ilok[text].'</font></small><br/>';}
echo'</div>';}}

function log_duel($tlog){
global $log;
$req=mysql_query("SELECT * FROM duellog WHERE opon = '$log' or usr = '$log' and timer>='".time()."' ORDER BY id DESC LIMIT 6");
$avto = mysql_num_rows($req);
if($avto>=1){

While($ilok = mysql_fetch_assoc($req))
{
if($ilok[usr]=="system"){$color='#AAAAAA';}
if($ilok[usr]!=="$log"){$color='#FF6633';}
if($ilok[usr]=="$log"){$color='#CCCCCC';}
if($ilok[umen]==1 and $ilok[usr]=="$log"){$color='#71CC71';}
if($ilok[umen]==1 and $ilok[usr]!=="$log"){$color='#FF6633';}
if($ilok[uron]>0){
echo '<font color="#7f9fae">'.$ilok[usr].' </font><font color="'.$color.'">'.$ilok[text].'</font> <font color="#7f9fae">'.$ilok[opon].'</font> -'.$ilok[uron].'<br/>';}
else{echo '<font color="#AAAAAA">'.$ilok[text].'</font><br/>';}
}
}}

function idlog($idlog){}

///РЕФЕРАЛЫ
function ref(){
global $log,$udata,$set;
if(!empty($udata['ref'])){
if($udata['lvl']>='3' and $udata['ref']!='not'){

$req = mysql_query("SELECT `exp`,`money`,`usr` FROM `users` WHERE `id` = '$udata[ref]' LIMIT 1");
// //////////////////////////
$avto = mysql_num_rows($req);
$refec = mysql_fetch_array($req);
$req = mysql_query("SELECT * FROM `users` WHERE `id` = '$udata[ref]' LIMIT 1");
$usdata = mysql_fetch_array($req);
$res = mysql_query("SELECT * FROM `set` WHERE `usr` = '$usdata[usr]' LIMIT 1");
$set = mysql_fetch_array($res);
if ($avto == 1) {
    $refer = mysql_fetch_array($req);
    $refer[money]=$usdata[money]+350;
    $refer[exp]=$usdata[exp]+700;
    $time = date("H:i d.m.y");
    $text = "Ваш друг $udata[usr] дошел до 3 уровня, сумма 350 монет и 700 опыта была успешно вам перечислена!";
    mysql_query("UPDATE `users` SET `money` = '$refer[money]', `exp`='$refer[exp]' WHERE `id` = '$udata[ref]' LIMIT 1");
    mysql_query("UPDATE `set` SET `friend` = '$set[friend]'+'1' WHERE `usr` = '$usdata[usr]' LIMIT 1");
    mysql_query("UPDATE `users` SET `ref` = 'not' WHERE `usr` = '$log' LIMIT 1");
    mysql_query("INSERT INTO `msg_r` SET `user_from` = 'Система', `user_to` = '$refec[usr]', `time` = '$time', `read` = 1, `mail_msg` = '$text'");}}}}
/////////////////////


function vip(){
global $log,$udata,$set;
$sett = mysql_query("SELECT * FROM `set` WHERE `usr` = '$log' LIMIT 1");
$set = mysql_fetch_assoc($sett);
$time = time();
if($set[vip]==on and $time >= $set[viptime]){
mysql_query("UPDATE `set` SET `vip` = 'off' WHERE `usr` = '$log' LIMIT 1");
$time = date("H:i d.m.y");
$text = "Закончилось время вашего vip-статуса";
mysql_query("INSERT INTO `msg_r` SET `user_from` = 'VIP', `user_to` = '$log', `time` = '$time', `read` = 1, `mail_msg` = '$text'");}}

function domin(){
global $udata;

$req=mysql_query("SELECT * FROM domination WHERE id = '1'");
$dom = mysql_fetch_assoc($req);
if($udata['storona']=='white'){
$my=$dom['white'];
$enemy=$dom['black'];
}else{
$my=$dom['black'];
$enemy=$dom['white'];
}
$all=$my+$enemy;
$domin=round($my/$all * 100);
if($domin<='15'){
echo' <img src="pic/main/towerscontrol1.png" alt="d">'.$domin.'%';
}elseif($domin<='30'){
echo' <img src="pic/main/towerscontrol2.png" alt="d">'.$domin.'%';
}elseif($domin<='45'){
echo' <img src="pic/main/towerscontrol3.png" alt="d">'.$domin.'%';
}elseif($domin<='55'){
echo' <img src="pic/main/towerscontrol4.png" alt="d">'.$domin.'%';
}elseif($domin<='70'){
echo' <img src="pic/main/towerscontrol5.png" alt="d">'.$domin.'%';
}elseif($domin<='85'){
echo' <img src="pic/main/towerscontrol6.png" alt="d">'.$domin.'%';
}elseif($domin<='100'){
echo' <img src="pic/main/towerscontrol7.png" alt="d">'.$domin.'%';}}

/////АУРЫ//////////////
function aura(){
global $log,$udata;
$time=time();
///////
$req = mysql_query("SELECT * FROM `aurs` WHERE `actimer`<'$time' and `usr`='$log'");
////////////////////////////
$avto=mysql_num_rows($req);
if($avto=='1'){
$req = mysql_query("SELECT * FROM `item_aura` WHERE `usr` = '$log' and `status`='1' LIMIT 1");
$avto=mysql_num_rows($req);
if($avto=='1'){
$mag = mysql_fetch_array($req);

$nlovk=$udata[lovk]-$mag[lovk];
$nsila=$udata[sila]-$mag[sila];
$nprotect=$udata[prot]-$mag[protect];
$nhp=$udata[hpall]-$mag[hp];
$nmp=$udata[mpall]-$mag[mp];
$nkrit=$udata[krit]-$mag[krit];
$nukrit=$udata[ukrit]-$mag[ukrit];

mysql_query("UPDATE `users` SET
         `sila` = '$nsila',
         `lovk` = '$nlovk',
         `prot` = '$nprotect',
         `hpall` = '$nhp',
         `mpall` = '$nmp',
         `krit` = '$nkrit',
         `ukrit` = '$nukrit'
          WHERE `usr` = '$log'") or die (mysql_error());



mysql_query("DELETE FROM `item_aura` WHERE `id` = '$mag[id]' LIMIT 1");
mysql_query("DELETE FROM `aurs` WHERE `usr` = '$log' LIMIT 1");
}
}
}
////////////////////////

//////////////ЧИСТИМ АРЕНУ
function clear_arena(){}
//////////////////////

///////КОРМИМ ПИТОВ
function pit_eda(){
global $log;

$time=time();
$req = mysql_query("SELECT `dies`,`eda`,`name`,`korm`,`status` FROM `pit` WHERE `usr` = '$log' LIMIT 1") or die(mysql_error());
$avto=mysql_num_rows($req);
if($avto>='1'){
$pit = mysql_fetch_assoc($req);
$proc=(($pit['korm']-$time)/$pit['eda'])*100;
if($proc<=0 and $pit['status']!="die"){
$pit['dies']=$pit['dies']+1;
mysql_query("UPDATE `pit` SET `hp` = '0',`dies`='$pit[dies]',`status`='die' WHERE `usr` = '$log' LIMIT 1");
///пишем письмо
$time = date("H:i d.m.y");
$text = $pit[name].' погиб от голода! Вы можете его воскресить в питомнике!';
mysql_query("INSERT INTO `msg_r` SET `user_from` = 'Зверовод', `user_to` = '$log', `time` = '$time', `read` = 1, `mail_msg` = '$text'");
}
}
}
////////////////

//навигация
function place_okr(){}

//навигация
function place_zamok(){}

//навигация
function place_tower(){}

//навигация
function place_city(){}
?>