Просмотр файла game/battle.php

Размер файла: 14.41Kb
<?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'])));
if ($id == $row['id'] and md5($pass)==$row['pass']){
$date=time();
////////////////////////////////////////////////////////////////

$sql3 = mysql_query("SELECT * FROM `more`");
$sql2 = mysql_query("SELECT * FROM `more`");

$more = mysql_fetch_array($sql2);


if(empty($_GET)){ 

header("Location: battle.php?go=war");

}


if($go=='war'){


$sql2 = mysql_query("SELECT * FROM `more` WHERE `id` = '".$row['more']."' ");


if(empty($row['more'])){ header("Location: battle.php"); exit; }
////Определяем окрестность

$sql4 = mysql_query("SELECT * FROM `more_user` WHERE `id_user` = '".$id."'");
$us = mysql_fetch_array($sql4);


$user = mysql_query("SELECT * FROM `more_user` WHERE `id_user`='".$id."'"); 
$user_s=mysql_num_rows($user); 


if($user_s==0){
$sql= mysql_query("INSERT INTO `more_user` SET `nick`='".$row['login']."', `hp`='".$row['hp']."', `id_user`='".$id."', `last_activ`='".$date."', `more`='".$row['more']."'");
}else{


$up = mysql_query("UPDATE `more_user` SET `last_activ` = '".$date."', `hp` = '".$row['hp']."',`more`='".$row['more']."' WHERE `id_user` = '".$_SESSION['id']."',`more`='".$row['more']."'");

}

$title=''.$more['name'].'';
include_once'inc/up.php';

$sql3 = mysql_query("SELECT * FROM `more_user` WHERE `id_user` = '".$_SESSION['id']."'");
$user = mysql_fetch_array($sql3);

$time=time();
$up_activ=mysql_query("UPDATE `more_user` SET `last_activ`='".$time."' WHERE `id_user`='".$_SESSION['id']."'");

///if($row['login']!==$user['nick']){

echo'<div class="post">';
$time=time()-1000;
$sql32 = mysql_query("SELECT * FROM `more_user` WHERE `more` = '".$row['more']."' AND `last_activ` >= '".$time."'");
$user_count=mysql_num_rows($sql32); 

echo'<img class="ico2" src="img/pics/pirat.png" alt="">'.$user_count.'';

echo'</div>';
echo'<div class="post">';

echo'
<a href="battle.php?go=all&amp;id='.$user['kil'].'">Атаковать противников</a>';

$dat=time()-3;
$time=time()-3;
$ost=$row['last_kick']-$time;
$ost=@date("i",$ost);
if(!empty($user['kil'])){
$sql4 = mysql_query("SELECT `server` FROM `users` WHERE `id` = '".$user['kil']."'");
$ser = mysql_fetch_array($sql4); }

if(!empty($user['kil']) and $ser['server']=='battle.php'){
$sql4 = mysql_query("SELECT `id`,`login`,`hp` FROM `users` WHERE `id` = '".$user['kil']."'");
$kil = mysql_fetch_array($sql4); 




$user2 = mysql_query("SELECT `id`,`hp` FROM `users` WHERE `id`='".$user['kil']."'"); 
$stop = mysql_fetch_array($user2); 
if($stop['hp']>=1){
echo'<br/>
<a href="battle.php?go=kick&amp;id='.$user['kil'].'">Атаковать '.$kil['login'].' ('.$kil['hp'].' HP)</a>';$dat=time()-3;
}
} 
echo'<br/>
<a href="location.php">В порт</a>';

echo'</div>';

$in=mysql_query("SELECT * FROM `logs` WHERE `id_user`='".$_SESSION['id']."' ORDER BY `id` DESC LIMIT 10");

while($ms=mysql_fetch_array($in)){

echo'<div class="post">'.$ms['msg'].'</div>';
}

}


if($go=='okr'){
$user = mysql_query("SELECT * FROM `more` WHERE `id`='".$item."'"); 
$user_s=mysql_num_rows($user); 
if($user_s==0){
echo'<div class="opis">Ошибка.</div>';
 exit;
}

$more = mysql_fetch_array($user);

if($row['lvl']<$more['lvl_min'])
{
header("Location: battle.php");
 exit; }
 if($row['lvl']>$more['lvl_max'])
{
header("Location: battle.php?max");
 exit; }
$sq = mysql_query("SELECT * FROM `users` WHERE `more` = '".$item."'"); 
$okr = mysql_fetch_array($sq);


$up=mysql_query("UPDATE `more_user` SET more='".$item."' WHERE `id_user`='".$_SESSION['id']."'");
$sss=mysql_query("UPDATE `users` SET more='".$item."' WHERE `id`='".$_SESSION['id']."'");
header("Location: battle.php?go=war"); exit;




}

if($go=='kick'){
if(!empty($_GET['id'])){
$ids=mysql_real_escape_string(htmlspecialchars(stripslashes(intval($_GET['id']))));
}else{ 
$sql3 = mysql_query("SELECT `id`,`id_user` FROM `more_user` WHERE `more` = '".$row['more']."' ORDER BY `last_activ` ASC");
$user = mysql_fetch_array($sql3);

}

$user = mysql_query("SELECT `id`,`server`,`hp` FROM `users` WHERE `id`='".$ids."'"); 
$user_s=mysql_num_rows($user); 

if($user_s==0){
header ("Location: battle.php?go=war");
 exit;

}
$ser=mysql_fetch_array($user);
if ($ser['server']!='battle.php'){
header ("Location: battle.php?go=war&er=page");
 exit;
}
if($ser['hp']<=0){

$msg='Противник разбит.';
$log=mysql_query("INSERT INTO `logs` SET `id_user`='".$row['id']."',`msg`='".$msg."'");

header ("Location: battle.php?go=war");
exit;
}


/*ЧИСТИМ ТАБЛИЦУ ПРИ НАБОРЕ 300 ЛОГОВ*/

$user2 = mysql_query("SELECT * FROM `logs` WHERE `id_user`='".$_SESSION['id']."'"); 
$user_s=mysql_num_rows($user2); 
if($user_s>=300){

$del=mysql_query("DELETE FROM `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 `logs` SET `id_user`='".$row['id']."',`msg`='".$msg."'");

header("Location: battle.php?go=war"); exit;
}

////////////////////////////////////////////////////
//////////////////////////////////////////////////

include "inc/drop_xsl.php";

$ids=mysql_real_escape_string(htmlspecialchars(stripslashes(intval($_GET['id']))));

$sql = mysql_query("UPDATE `users` SET `last_kick` = '".$time."' WHERE `id` = '".$row['id']."'");
$aska = mysql_query("UPDATE `more_user` 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;

$sql_clan = mysql_query("SELECT * FROM `clan` WHERE `id` = '".$row['clan']."'"); 
$spclan=mysql_fetch_array($sql_clan);
$expclan=$spclan['exp']+$udar+$rand+$lvl;
$expclan=round($expclan);
$plus_exp=$spclan['exp']+$expclan;

$slq_up=mysql_query("UPDATE `clan` SET `exp`='".$plus_exp."' WHERE `id` ='".$row['clan']."'");

//$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 `logs` SET `id_user`='".$row['id']."',`id_kill`='".$ids."',`msg`='".$msg."'");
$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 `logs` SET `id_user`='".$ids."',`id_kill`='".$row['id']."',`msg`='".$msg2."'");

$del_sql=mysql_query("DELETE FROM `more_user` WHERE `id_user`='".$user['id']."'");

header("Location: battle.php?go=war&id=".$ids."");
exit;
 } 
$ids=mysql_real_escape_string(htmlspecialchars(stripslashes(intval($_GET['id']))));
 //////////////////////Если НЕЕ убивает
$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 `logs` SET `id_user`='".$row['id']."',`id_kill`='".$ids."',`msg`='".$msg."'");
$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 `logs` SET `id_user`='".$ids."',`id_kill`='".$row['id']."',`msg`='".$msg2."'");
//////////////////////

$exp=$row['exp']+$udar+$rand+$lvl;

$sql_clan = mysql_query("SELECT * FROM `clan` WHERE `id` = '".$row['clan']."'"); 
$spclan=mysql_fetch_array($sql_clan);
$expclan=$spclan['exp']+$udar+$rand+$lvl;
$expclan=round($expclan/2);
$plus_exp=$spclan['exp']+$expclan;

$slq_up=mysql_query("UPDATE `clan` SET `exp`='".$plus_exp."' WHERE `id` ='".$row['clan']."'");


/*
$exp2=$exp*$row['predok'];
$exp2=$exp2/100;
*/ //Вкл на хостинге
$up = mysql_query("UPDATE `users` SET `exp` = '".$exp."' WHERE `id` = '".$_SESSION['id']."'");

header("Location: battle.php?go=war&id=".$ids."");  }elseif(!empty($_GET['id']) and !is_numeric($_GET['id'])){ header("Location: battle.php"); } ///можно удалить


if($go=='all'){
$ids=mysql_real_escape_string(htmlspecialchars(stripslashes(intval($_GET['id']))));

$sql7 = mysql_query("SELECT `id`,`id_user` FROM `more_user` WHERE `id_user` = '".$ids."' ");
$prot = mysql_fetch_array($sql7);


$sql2 = mysql_query("SELECT * FROM `more` WHERE `id` = '".$row['more']."' ");
$more = mysql_fetch_array($sql2);

$time=time()-1000;
$sql3 = mysql_query("SELECT * FROM `more_user` WHERE `more` = '".$row['more']."' AND `last_activ` >= '".$time."'");
while($user = mysql_fetch_array($sql3)){

if($user['id_user']!=$_SESSION['id']){ 
$us=$user['id_user'];
}
}
if(empty($us)){

header("Location: battle.php?go=bot");

}else{

header("Location: battle.php?go=kick&id=".$us.""); exit;
}




}elseif ($go=='bot'){

$sql22 = mysql_query("SELECT * FROM `bot` WHERE `more` = '".$row['more']."' ");
$bot = mysql_fetch_array($sql22);

if($bot['hp']<=0){

$bot['hp']=$bot['hp_max'];

}
$dat=time()-3;
if($row['last_kick']>$dat){ 

$dat=time()-3;
$msg1='Ваша команда не готова к атаке.';
$log=mysql_query("INSERT INTO `logs` SET `id_user`='".$row['id']."',`msg`='".$msg1."'");

header("Location: battle.php?go=war"); exit;
}


$time=time()-1000;
$sql32 = mysql_query("SELECT * FROM `more_user` WHERE `more` = '".$row['more']."' AND `last_activ` >= '".$time."'");
$user_count=mysql_num_rows($sql32); 

if($user_count>1){ header("Location: battle.php?go=war&er=users");  }else{

$rand_udar=rand(1,2);
if($rand_udar==2){

$kick=round($row['def']/3);
$hp=$row['hp']-$kick;

if($hp<=0) {  

$sql_bot=mysql_query("UPDATE `users` SET `hp`='".$hp."',`lost_activ`='1' WHERE `id`='".$row['id']."'");
$msg2='<font color="#8c3636"><img class="ico" src="img/pics/sword.png" alt="">Вас убил Пират.</font>';
$log_bot_kick=mysql_query("INSERT INTO `logs` SET `id_user`='".$_SESSION['id']."',`id_kill`='".$row['id']."',`msg`='".$msg2."'"); header("Location: location.php"); exit;
 }

$sql_bot=mysql_query("UPDATE `users` SET `hp`='".$hp."' WHERE `id`='".$row['id']."'");



$msg2='<font color="#8c3636"><img class="ico" src="img/pics/sword.png" alt="">Вас атаковал Пират на '.$kick.'.</font>';
$log_bot_kick=mysql_query("INSERT INTO `logs` SET `id_user`='".$_SESSION['id']."',`id_kill`='".$row['id']."',`msg`='".$msg2."'");
}

$you=round($row['power']/3);
$hp_bot=$bot['hp']-$you;
$sql=mysql_query("UPDATE `bot` SET `hp`='".$hp_bot."' WHERE `id` = ' ".$bot['id']."' ");



$msg='<img class="ico" src="img/pics/sword.png" alt="">Вы атаковали <font color="#aa4400">Пирата</font> на '.$you.'.';
$log_bot=mysql_query("INSERT INTO `logs` SET `id_user`='".$_SESSION['id']."',`id_kill`='".$row['id']."',`msg`='".$msg."'");


//////////////////////
include "inc/drop_xsl.php";
//////////////////////
$sql22 = mysql_query("SELECT * FROM `bot` WHERE `more` = '".$row['more']."' ");
$bot = mysql_fetch_array($sql22);

$tim=time();
$lvl=$row['lvl'];

if ($lvl >=1 and $lvl <=10) $rand=rand(23,74);
if ($lvl >=11 and $lvl <=20) $rand=rand(77,123);
if ($lvl >=21) $rand=rand(129,289);
$plus_exp=$rand+$you+$row['lvl'];
$exp=$row['exp']+$plus_exp;
$sql_kick=mysql_query("UPDATE `users` SET `last_kick`= '".$tim."',`exp`='".$exp."' WHERE `id`='".$_SESSION['id']."'");
if(!empty($row['clan'])){
$sql_clan=mysql_query("SELECT * FROM `clan` WHERE `id`='".$row['clan']."'");
$clan=mysql_fetch_array($sql_clan);

$you_clan=mysql_query("SELECT * FROM `clan_list` WHERE `id_user`='".$row['id']."'");
$so=mysql_fetch_array($you_clan);

$clan_exp=$plus_exp+rand(1,21);
$plus_clan=$clan['exp']+$clan_exp;
$you_exp=$so['exp']+$clan_exp;
$sql_so_up=mysql_query("UPDATE `clan_list` SET `exp`='".$you_exp."' WHERE `id_user`='".$you_exp."'");
$sql_up=mysql_query("UPDATE `clan` SET `exp`='".$exp."' WHERE `id`='".$clan['id']."'");

}

header("Location: battle.php?go=war&id=1");




exit;

}



}


}

include'inc/foot.php';


?>