<?php
Error_Reporting(E_ALL & ~E_NOTICE);
include'inc/conf.php';
session_start();
$sql = mysql_query("SELECT * FROM `users` WHERE `id` = '".$_SESSION['id']."' ");
$row = mysql_fetch_array($sql);
$pass = mysql_real_escape_string(htmlspecialchars(stripslashes($_SESSION['pass'])));
$id = mysql_real_escape_string(htmlspecialchars(stripslashes($_SESSION['id'])));
$item = mysql_real_escape_string(htmlspecialchars(stripslashes($_GET['item'])));
$go=mysql_real_escape_string(htmlspecialchars(stripslashes($_GET['go'])));
//////////////////////////////////////////
///Если ПРОШЛО N времени то делаем возможность захвата ОПЯТЬ////
/////////////////////////////////////////
$dat=time()-1;
/////////////////////////////////////////////////////////////
if ($id == $row['id'] and md5($pass)==$row['pass']){
$step_sql=mysql_query("SELECT * FROM `osada_city` WHERE `city`='".$row['city']."'");
$st=mysql_fetch_array($step_sql);
$sql_os=mysql_query("SELECT * FROM `osada` WHERE `city`='".$row['city']."' AND `activ`='0' AND `number`='".$st['step']."'");
$osada=mysql_fetch_array($sql_os);
$user_sql=mysql_query("SELECT * FROM `osada_users` WHERE `city`='".$row['city']."'");
$user=mysql_fetch_array($user_sql);
if(empty($go)){
if($st['step']>=4 and $st['activ']==0){
$time=time();
$sql=mysql_query("UPDATE `osada_city` SET `activ`='2',`clan`='".$row['clan']."',`step`='1',`time`='".$time."' WHERE `city`='".$row['city']."'");
$step_sql=mysql_query("SELECT * FROM `osada_city` WHERE `city`='".$row['city']."'");
$st=mysql_fetch_array($step_sql);
$guild_sql=mysql_query("SELECT `name`,`id` FROM `clan` WHERE `id`='".$st['clan']."'");
$guild=mysql_fetch_array($guild_sql);
$msg='<font color="#3490a4">Город захвачен гильдией <a href="clan.php?go=info&id='.$guild['id'].'"><strong><font color="#3490a4">'.$guild['name'].'!</font></strong></a></font>';
$log=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$row['id']."',`msg`='".$msg."',`city`='".$row['city']."'");
$title='Город Захвачен';
include'inc/up.php';
$guild_sql2=mysql_query("SELECT `name`,`id` FROM `clan` WHERE `id`='".$st['clan']."'");
$clan=mysql_fetch_array($guild_sql2);
echo'<div class="under">
Схватка за город '.$row['name'].' закончена!<br/>
Победила гильдия: <a href="clan.php?go=info&id='.$clan['id'].'"><strong>'.$clan['name'].'</strong></a>
</div>';
echo'<div class="under">- <a href="osada.php">Обновить</a></div>';
include'inc/foot.php';
exit;
}
if($st['activ']==2){
if($st['time']<$dat){
$sql=mysql_query("DELETE FROM `osada_users` WHERE `city`='".$row['city']."'");
$log_sql=mysql_query("DELETE FROM `osada_logs` WHERE `city`='".$row['city']."'");
$sql_os2=mysql_query("SELECT * FROM `osada` WHERE `city`='".$row['city']."'");
$number=1;
while($os=mysql_fetch_array($sql_os2)){
$sql_os3=mysql_query("SELECT * FROM `osada` WHERE `city`='".$os['city']."' AND `number`='".$number."'");
$das=mysql_fetch_array($sql_os3);
$max_hp=$das['hp_max'];
$hp_m=mysql_query("UPDATE `osada` SET `hp`='".$max_hp."' WHERE `city`='".$row['city']."' AND `number`='".$number."'");
$number++;
}
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
$up=mysql_query("UPDATE `osada_city` SET `activ`='0' WHERE `city`='".$row['city']."'");
}
else{
$time=time()-1;
$ost=$st['time']-$time;
$ost2=@date("i",$ost);
$title='Город Захвачен';
include'inc/up.php';
$guild_sql2=mysql_query("SELECT `name`,`id` FROM `clan` WHERE `id`='".$st['clan']."'");
$clan=mysql_fetch_array($guild_sql2);
echo'<div class="under">
Схватка за город закончена!<br/>
Победила гильдия: <a href="clan.php?go=info&id='.$clan['id'].'"><strong>'.$clan['name'].'</strong></a><br/>
Напасть на город можно будет через <strong>'.$ost2.'</strong> минут.
</div>';
echo'<div class="under">- <a href="osada.php">Обновить</a></div>';
include'inc/foot.php';
exit;
}
$count_sql = mysql_query("SELECT `id` FROM `osada_users` WHERE `id_user`='".$_SESSION['id']."'");
$count=mysql_num_rows($count_sql);
if($user_s==0){
$plus_sql=mysql_query("INSERT INTO `osada_users` SET `id_user`='".$_SESSION['id']."',`nick`='".$row['login']."',`city`='".$row['city']."'");
}
$title='Город Захвачен';
include'inc/up.php';
$guild_sql2=mysql_query("SELECT `name`,`id` FROM `clan` WHERE `id`='".$st['clan']."'");
$clan=mysql_fetch_array($guild_sql2);
echo'<div class="under">
Схватка за город закончена!<br/>
Победила гильдия: <a href="clan.php?go=info&id='.$clan['id'].'"><strong>'.$clan['name'].'</strong></a>
</div>';
echo'<div class="under">- <a href="osada.php">Обновить</a></div>';
$ek_sql=mysql_query("SELECT * FROM `osada_logs` WHERE `id_user`='".$_SESSION['id']."' ORDER BY `id` DESC LIMIT 10");
while($ms=mysql_fetch_array($ek_sql)){
echo'<div class="post">'.$ms['msg'].'</div>';
}
include'inc/foot.php';
exit;
}
$title='Осада Города';
include'inc/up.php';
echo'<div class="post">';
echo '<a href="osada.php?go=kick">Атаковать '.$osada['name'].' ('.$osada['hp'].' HP)</a><br/>';
echo '<a href="osada.php?go=prot">Атаковать Противников</a>';
echo'</div>'; }
//////////////////////////////////////////////////////////
/////////////////PVP БОИ//////////////////////////////////
//////////////////////////////////////////////////////////
///****************************************************///
//////////////////////////////////////////////////////////
elseif($go=='prot'){
if($st['time']>$dat){
header("Location: osada.php"); exit;
}
$sql3 = mysql_query("SELECT `id`,`id_user` FROM `osada_users` WHERE `city` = '".$row['city']."' AND `id_user`<>'".$row['id']."' ORDER BY `last_activ` ASC");
$user = mysql_fetch_array($sql3);
$sql_2=mysql_query("SELECT `id` FROM `users` WHERE `id`='".$user['id_user']."'");
$rs=mysql_fetch_array($sql_2);
$us=$rs['id'];
header("Location: osada.php?go=pvp&id=".$us.""); exit;
}elseif($go=='pvp'){
if($st['time']>$dat){
header("Location: osada.php"); exit;
}
$ids=intval($_GET['id']);
$ids = mysql_real_escape_string(htmlspecialchars(stripslashes($ids)));
$count_sql = mysql_query("SELECT `id` FROM `users` WHERE `id`='".$ids."'");
$user_s=mysql_num_rows($count_sql);
if($user_s==0){ header("Location: osada.php?null"); exit; }
$s_user = mysql_query("SELECT `id`,`server` FROM `users` WHERE `id`='".$ids."'");
$ser=mysql_fetch_array($s_user);
if ($ser['server']!='osada.php'){
header ("Location: osada.php?er");
exit;
}
/*ЧИСТИМ ТАБЛИЦУ ПРИ НАБОРЕ 400 ЛОГОВ*/
$user2 = mysql_query("SELECT * FROM `osada_logs` WHERE `id_user`='".$_SESSION['id']."'");
$user_s=mysql_num_rows($user2);
if($user_s>=400){
$del=mysql_query("DELETE FROM `osada_logs` WHERE `id_user`='".$_SESSION['id']."'");
}
////////////////////////////////////
$sql3 = mysql_query("SELECT * FROM `users` WHERE `id` = '".$ids."'");
$user = mysql_fetch_array($sql3);
//единицы Расчета Удара
$u_m=$row['power']*1.4;
$d_p=$user['def'];
$s_m=$row['speed'];
$s_p=$user['speed'];
$m_m=$row['manevr'];
$m_p=$user['manevr'];
$power=$row['power']*$row['serdce']/100; ///Спец навык (Умения)
$luck=$row['luck']/2;
$speed=$s_m-$s_p;
if($speed<0) $speed=0;
//////
$manevr=$m_m-$m_p;
if($manevr<0) $manevr=0;
$udar=$u_m-$d_p;
$udar=$udar+$power;
$udar=$udar+$luck;
$udar=$udar+$speed;
$udar=$udar+$manevr;
$rand=rand(1,5);
$udar=round($udar+$rand);
$krand=rand($row['krit'],100);
if($krand==100){
$udar=round($udar*2);
}
///////Записываем результат
$hp_old=$user['hp'];
if($udar<0) $udar=$rand;
$hp2=$hp_old-$udar;
/////////////////////////
//////EXP
$lvl=$user['lvl'];
if ($lvl >=1 and $lvl <=10) $rand=rand(1,50);
if ($lvl >=11 and $lvl <=20) $rand=rand(60,180);
if ($lvl >=21) $rand=rand(200,400);
////////////////////////
$time=time();
$dat=time()-3;
if($row['last_kick']>$dat){
$dat=time()-3;
$msg='Ваша команда не готова к атаке.';
$log=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$row['id']."',`msg`='".$msg."',`city`='".$row['city']."'");
header("Location: osada.php"); exit;
}
////////////////////////////////////////////
//////////////////////////////////////////////
/////////РЕЕССУРСЫ////////////////////////////
$rr2=rand(1,100);
if($rr2==12){
$art_rand=rand(1,4);
$user = mysql_query("SELECT * FROM `art` WHERE `id_user`='".$_SESSION['id']."'");
$user_s=mysql_num_rows($user);
if($user_s>=25){
$msg='<strong><font color="#368c39">Вы не получили награду. В инвентаре больше 25 артефактов.</font></strong>';
}else{
if($art_rand==1){
$mysql=mysql_query("INSERT INTO `art` SET `id_user` = '".$_SESSION['id']."', `name`='Солнечный Медальон', `power_1`='speed',`power_2`='manevr',`plus_1`='30',`plus_2`='25',`owner`='0', `type`='medalon',`price`='4900'");
$type='medalon';
$name='Солнечный Медальон';
}
if($art_rand==2){
$mysql=mysql_query("INSERT INTO `art` SET `id_user` = '".$_SESSION['id']."', `name`='Пистолета Пирата', `power_1`='power',`power_2`='speed',`plus_1`='45',`plus_2`='35',`owner`='0', `type`='pistolet',`price`='8000'");
$type='pistolet';
$name='Пистолета Пирата';
}
if($art_rand==3){
$mysql=mysql_query("INSERT INTO `art` SET `id_user` = '".$_SESSION['id']."', `name`='Сабля Мертвеца', `power_1`='power',`power_2`='def',`plus_1`='75',`plus_2`='50',`owner`='0', `type`='sabla',`price`='12300'");
$type='sabla';
$name='Сабля Мертвеца';
}
if($art_rand==4){
$mysql=mysql_query("INSERT INTO `art` SET `id_user` = '".$_SESSION['id']."', `name`='Золотая Цепь', `power_1`='power',`power_2`='def',`plus_1`='120',`plus_2`='80',`owner`='0', `type`='cep',`price`='17500'");
$type='cep';
$name='Золотая Цепь';
}
}
if(!empty($type) and !empty($name)){
$msg='<strong><font color="#368c39">Вам выпало '.$name.'</font></strong>';
}
$d_sql=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$row['id']."',`msg`='".$msg."',`city`='".$row['city']."'"); }
///////////////////////////
$rr=rand(5,25);
if($rr==6){
$msg='<strong><font color="#009bc2">Вы нашли 1<img class="ico" src="img/pics/pearl.png" alt=""></font></strong>';
$pearl=$row['pearl']+1;
$sql = mysql_query("UPDATE `users` SET `pearl` = '".$pearl."' WHERE `id` = '".$row['id']."'");
if ($sql){ $d_sql=mysql_query("INSERT INTO `logs` SET `id_user`='".$row['id']."',`id_kill`='',`msg`='".$msg."',`city`='".$row['city']."'"); }
}
$rr2=rand(10,20);
if($rr2==11){
$mor=rand(1,15);
if($mor==3) { $money2=rand(200,500); }
else { $money2=rand(4,70); }
$msg='<strong><font color="#009bc2">Вы нашли '.$money2.'<img class="ico" src="img/pics/money.png" alt=""></font></strong>';
$money3=$row['money']+$money2;
$sql = mysql_query("UPDATE `users` SET `money` = '".$money3."' WHERE `id` = '".$row['id']."'");
if ($sql){ $d_sql=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$row['id']."',`id_kill`='',`msg`='".$msg."',`city`='".$row['city']."'"); }
}
////////////////////////////////////////////////
//////////////////////////////////////////////////
$ids=intval($_GET['id']);
$ids = mysql_real_escape_string(htmlspecialchars(stripslashes($ids)));
$time=time();
$sql = mysql_query("UPDATE `users` SET `last_kick` = '".$time."' WHERE `id` = '".$row['id']."'");
$aska = mysql_query("UPDATE `osada_users` SET `kil` = '".$ids."' WHERE `id_user` = '".$_SESSION['id']."'");
$dat=time()-3;
$down = mysql_query("UPDATE `users` SET `hp` = '".$hp2."' WHERE `id` = '".$ids."'");
$sq = mysql_query("SELECT * FROM `users` WHERE `id` = '".$ids."'");
$user=mysql_fetch_array($sq);
if($user['hp']<=0){ ///Если убивет противника
$lvl=$user['lvl'];
if ($lvl >=1 and $lvl <=10) $rand=rand(50,100);
if ($lvl >=11 and $lvl <=20) $rand=rand(100,300);
if ($lvl >=21) $rand=rand(300,600);
$exp=$row['exp']+$udar+$rand+$lvl;
//$exp=$exp*$row['predok']/100; ВКЛ на хостинге
$user_hp=$user['hp_max'];
$lost=$user['lost']+1;
$money=$user['money']*5/100;
$lost_money=$user['money']-$money;
$up_money=$row['money']+$money;
$sql = mysql_query("UPDATE `users` SET `lost` = '".$lost."', `lost_activ` = '1', `money`='".$lost_money."' WHERE `id` = '".$ids."'");
$win=$row['win']+1;
$sql2 = mysql_query("UPDATE `users` SET `win` = '".$win."', `exp` = '".$exp."', `money`='".$up_money."' WHERE `id` = '".$_SESSION['id']."'");
$msg='<img class="ico" src="img/pics/sword.png" alt="">Вы убили <a href="info.php?ids='.$user['id'].'">'.$user['login'].'</a>';
$log=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$row['id']."',`msg`='".$msg."',`city`='".$row['city']."'");
$msg2='<font color="#8c3636"><img class="ico" src="img/pics/sword.png" alt="">Вас убил <a href="info.php?ids='.$row['id'].'">'.$row['login'].'</a>.</font>';
$log2=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$ids."',`msg`='".$msg2."',`city`='".$row['city']."'");
header("Location: battle.php?go=war&id=".$ids."");
exit;
}
//////////////////////Если НЕЕ убивает
$msg='<img class="ico" src="img/pics/sword.png" alt="">Вы ударили <a href="info.php?ids='.$user['id'].'">'.$user['login'].'</a> на <font color="#8c3636">'.$udar.'</font>.</a>';
$log=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$row['id']."',`msg`='".$msg."',`city`='".$row['city']."'");
$msg2='<font color="#8c3636"><img class="ico" src="img/pics/sword.png" alt="">Вас ударил <a href="info.php?ids='.$row['id'].'">'.$row['login'].'</a> на '.$udar.'</font>.</a>';
$log2=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$ids."',`msg`='".$msg2."',`city`='".$row['city']."'");
//////////////////////
$exp=$row['exp']+$udar+$rand+$lvl;
/*
$exp2=$exp*$row['predok'];
$exp2=$exp2/100;
*/ //Вкл на хостинге
$up = mysql_query("UPDATE `users` SET `exp` = '".$exp."' WHERE `id` = '".$_SESSION['id']."'");
header("Location: osada.php?ok");
}
elseif($go=='kick'){
if($st['time']>$dat){
header("Location: osada.php"); exit;
}
if($st['step']>=4 and $st['activ']==0){
$time=time();
$sql=mysql_query("UPDATE `osada_city` SET `activ`='2',`clan`='".$row['clan']."',`step`='1',`time`='".$time."' WHERE `city`='".$row['city']."'");
$guild_sql=mysql_query("SELECT `name`,`id` FROM `clan` WHERE `id`='".$row['clan']."'");
$guild=mysql_fetch_array($guild_sql);
$msg='<font color="#3490a4">Город захвачен гильдией <a href="clan.php?go=info&id='.$guild['id'].'"><strong><font color="#3490a4">'.$guild['name'].'!</font></strong></a></font>';
$log=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$row['id']."',`msg`='".$msg."',`city`='".$row['city']."'");
$title='Город Захвачен';
include'inc/up.php';
echo'<div class="under">
Схватка за город '.$row['name'].' закончена!<br/>
Победила гильдия: <a href="clan.php?go=info&id='.$guild['id'].'"><strong>'.$guild['name'].'</strong></a>
</div>';
echo'<div class="post">- <a href="osada.php">Обновить</a></div>';
include'inc/foot.php';
exit;
}elseif($st['activ']==2 and $user['step']==0){
$msg='<font color="#3490a4">Город захвачен гильдией <a href="clan.php?go=info&id='.$guild['id'].'"><strong><font color="#3490a4">'.$guild['name'].'!</font></strong></a><font color="#3490a4">';
$log=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$row['id']."',`msg`='".$msg."',`city`='".$row['city']."'");
$up=mysql_query("UPDATE `osada_users` SET `step`='1' WHERE `id_user`='".$_SESSION['id']."'");
$title='Город Захвачен';
include'inc/up.php';
echo'<div class="post">- <a href="osada.php">Обновить</a></div>';
$ek_sql=mysql_query("SELECT * FROM `osada_logs` WHERE `id_user`='".$_SESSION['id']."' ORDER BY `id` DESC LIMIT 10");
while($ms=mysql_fetch_array($ek_sql)){
echo'<div class="post">'.$ms['msg'].'</div>';
}
include'inc/foot.php';
exit;
}elseif($st['activ']==2){
$title='Город Захвачен';
include'inc/up.php';
echo'<div class="post">- <a href="osada.php">Обновить</a></div>';
$ek_sql=mysql_query("SELECT * FROM `osada_logs` WHERE `id_user`='".$_SESSION['id']."' ORDER BY `id` DESC LIMIT 10");
while($ms=mysql_fetch_array($ek_sql)){
echo'<div class="post">'.$ms['msg'].'</div>';
}
include'inc/foot.php';
exit;
}
$time=time();
$dat=time()-3;
if($row['last_kick']>$dat){
$dat=time()-3;
$msg='Ваша команда не готова к атаке.';
$log=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$row['id']."',`msg`='".$msg."',`city`='".$row['city']."'");
header("Location: osada.php"); exit;
}
$power=round($row['power']*1.4);
$udar=$power-$osada['def']; if ($udar<0) $udar=0;
$bot=$osada['power']-$row['def']; if($bot<0) $bot=0;
$udar=$udar+rand(1,20);
$bot=$bot+rand(1,20);
/////////////////Удары бота //////////////////
$rand_bot=rand(1,3);
if($rand_bot==2){
$hp=$row['hp']-$bot;
}else{
$hp=$row['hp']; }
////////////////////////////////////////////////
$hp_bot=$osada['hp']-$udar;
$last=time();
////exp
$lvl=$user['lvl'];
if ($lvl >=1 and $lvl <=10) $rand=rand(50,100);
if ($lvl >=11 and $lvl <=20) $rand=rand(100,300);
if ($lvl >=21) $rand=rand(300,600);
$exp=$row['exp']+$udar;
$exp=$exp+$rand;
$exp=$exp+$lvl;
/////////////Следующий шаг
if($hp_bot<=0){
$step=$st['step']+1; $up=mysql_query("UPDATE `osada_city` SET `step`='".$step."' WHERE `city`='".$row['city']."'");
$msg='<font color="#3490a4">'.$osada['kil'].'</font>';
$msg_sql=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$_SESSION['id']."',`msg`='".$msg."',`city`='".$row['city']."'");
header("Location: osada.php"); exit; }
///////////////////////////ЗАПИСЫВАЕМ Логи
$sql=mysql_query("UPDATE `users` SET `hp`='".$hp."', `exp`='".$exp."', `last_kick`='".$last."' WHERE `id`='".$_SESSION['id']."'");
$comp=mysql_query("UPDATE `osada` SET `hp`='".$hp_bot."' WHERE `id`='".$osada['id']."'");
if($rand_bot==2){
$msg_bot='<font color="#5f2626"><img class="ico" src="img/pics/sword.png" alt="">Вас атаковал <strong>'.$osada['name'].'</strong> на '.$bot.'.</a></font>';
$log_bot=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$_SESSION['id']."', `msg`='".$msg_bot."',`city`='".$row['city']."'");
}
$msg='<font color="#406e03"><img class="ico" src="img/pics/sword.png" alt="">Вы атаковали <strong>'.$osada['name'].'</strong> на '.$udar.'.</a></font>';
$log=mysql_query("INSERT INTO `osada_logs` SET `id_user`='".$_SESSION['id']."',`id_kil`='".$row['id']."',`msg`='".$msg."',`city`='".$row['city']."'");
header("Location: osada.php"); exit;
}
$ek_sql=mysql_query("SELECT * FROM `osada_logs` WHERE `id_user`='".$_SESSION['id']."' ORDER BY `id` DESC LIMIT 10");
while($ms=mysql_fetch_array($ek_sql)){
echo'<div class="post">'.$ms['msg'].'</div>';
}
echo'</div>';
}
include'inc/foot.php';
?>