Файл: _gladiators2_/gladiators2/gladiators/gladiators/battle.php
Строк: 570
<?
@session_start();
if( !isset($_SESSION["id"]) ) {
    echo"<script language=javascript>top.window.location='../index.php';</script>";
    exit();
}
@include("connect.php");
@include("system/config/values.php");
@include("system/config/servers.php");
@include("system/class/main_class.php");
$db = new DBconn;
@include("system/class/class_BattleUser.php");
@include("system/class/class_battle.php");
$myself = new user;
$opponent = new user;
$kick_opponent = new user;
$battle = new battle;
@include("includes/std.h.php");
@include("system/includes/gzip.php");
if( $myself->get_info($_SESSION["id"],"normal")==false )
{
    echo"Ошибка: невозможно получить данные о персонаже, возможно сервер в данный момент перегружен, попробуйте обновить страницу через несколько минут. ";
    exit();
}
if( !$myself->battle_id ) {
    @Header("Location: /home.php");
    exit();
}
if( $battle->get_info($myself->battle_id)==false )
{
    echo"<html>
        <head>
            <link rel=stylesheet href=/css/index.css>
            <meta http-equiv="Content-type" content="text/css; charset=window-1251;">
        </head>
        <body bgcolor=#e5e1be>
            <br>
            <table border=0 width=100% height=100%>
                <tr>
                    <td align=center valign=middle><b>Сервер сильно перегружен!</b><br> Это временное явление, попробуйте обновить страницу через пару минут!</b><br><input type=button value='Обновить' onclick='window.location=window.location.href' class=button></td>
                </tr>
            </table>
        </body>
    </html>";
    exit();
}
$myself->param($myself->id); // Узнаем параметры оружия
if( preg_match("/(^|;)(".$_SESSION["id"].";)/",$battle->side1) )
{
    $myside="side1";
    $opp_side="side2";
}
else
{
    $myside="side2";
    $opp_side="side1";
}
if( !$battle->winner )
{
    $a_mass = explode(";",$battle->kick_time);
    for($i=0;$i<=count($a_mass)-2;$i++)    {
        
        $b_mass = explode("=",$a_mass[$i]);
        if((time()-$b_mass[1] > $battle->timeout) && ($battle->type!="bot" || $i==0)) {
            
            $request = @mysql_query("select login,level,hp from users where id='".$b_mass[0]."'");
            $get = @mysql_fetch_array($request);
            if($get["hp"] > 0) {
                
                @mysql_query("update users set hp='0',last_update_uron='".time()."' where id=".$b_mass[0]);
                if($get["login"]==$_SESSION["login"])
                $myself->get_info($_SESSION["id"],"normal");
                @mysql_query("insert into battle_logs values('".$battle->id."','2','".time()."','greating','".$b_mass[0]."','','0','0','1','0','0')");
                $battle->winner();
            }
        }
    }
}
if($act=="kick" && !$battle->winner)
{
    $_POST["opponent_id"] = intval($_POST["opponent_id"]);
    if(eregi("^(".$_POST["opponent_id"].";)",$battle->$opp_side) || eregi("(;".$_POST["opponent_id"].";)",$battle->$opp_side))
    {
        $opponent->get_info($_POST["opponent_id"],$battle->type);
        $opponent->param($_POST["opponent_id"]);
        if(eregi("^[1-5]{1}$",$_POST["f"]) && eregi("^[1-5]{1}$",$_POST["b"]) && !$battle->winner && $opponent->hp)
        {
            $battle->kick($_POST["f"],$_POST["b"],$opponent->id,$myself->id,$opp_side,$myself,$opponent);
            $myself->get_info($_SESSION["id"],"normal");
        }
    }
    if( $battle->type == "bot" )
    {
        $opp_id = str_replace(";","",$battle->side2);
        $opponent->get_info($opp_id,$battle->type);
        $opponent->param($myself->id);
        if(mt_rand(1,2)==2)
            $battle->kick(mt_rand(1,5),mt_rand(1,5),$myself->id,$opponent->id,$myside,$opponent,$myself);
    }
    $battle->write();
    $battle->winner(); // проверка на окончание боя
    $opponent->Clear();
    $myself->get_info($_SESSION["id"],"normal"); // Обновляет параметры мои
}
@include("system/modules/mod_battle.php");
$action_mass = explode(";",$battle->action);
$mass_opponent_unavaible = array();
for($i=0;$i<=count($action_mass)-2;$i++)
{
    $a_mass = explode("(",$action_mass[$i]);
    $id_mass = explode(":",$a_mass[0]);
    $b_mass = explode(")",$a_mass[1]);
    $kick_mass = explode(":",$b_mass[0]);
    if($id_mass[0]==$myself->id && $kick_mass[0])
    $mass_opponent_unavaible[] = $id_mass[1];
    elseif($id_mass[1]==$myself->id && $kick_mass[1])
    $mass_opponent_unavaible[] = $id_mass[0];
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
// Список игроков
$list_side1 = array();
$list_side2 = array();
$players_mass = $battle->side1.$battle->side2;
$players_mass = explode(";",$players_mass);
$pms1 = explode(";",$battle->side1);
$pms2 = explode(";",$battle->side2);
for($i=0;$i<=count($pms1)-2;$i++)
{
    if(!$i)
    $query = " id='".$pms1[$i]."'";
    else
    $query .= " or id='".$pms1[$i]."'";
}
$res_users = @mysql_query("select id,login,hp,maxhp from users where ".$query);
$num_users = @mysql_num_rows($res_users);
for($i=1;$i<=$num_users;$i++)
{
    $row_users = @mysql_fetch_array($res_users);
    if($row_users["hp"]>0)
    $list_side1[] = "<a style='cursor:hand;font-weight:bold;color:#A0522D'>".$row_users["login"]."</a>(".$row_users["hp"]."/".$row_users["maxhp"].")";
    else
    $mass_opponent_unavaible[] = $row_users["id"];
}
for($i=0;$i<=count($pms2)-2;$i++)
{
    if(!$i)
    $query = " id='".$pms2[$i]."'";
    else
    $query .= " or id='".$pms2[$i]."'";
}
if($battle->type=="bot")
$from="temp";
else
$from="users";
$res_users = @mysql_query("select id,login,hp,maxhp from ".$from." where ".$query);
$num_users = @mysql_num_rows($res_users);
for($i=1;$i<=$num_users;$i++)
{
    $row_users = @mysql_fetch_array($res_users);
    if($row_users["hp"]>0)
    $list_side2[]="<a style='cursor:hand;font-weight:bold;color:#708090'>".$row_users[login]."</a>(".$row_users[hp]."/".$row_users[maxhp].")";
    elseif($battle->type=="bot" && $battle->winner=="side2")
    $list_side2[]="<a style='cursor:hand;font-weight:bold;color:#708090'>".$_SESSION[login]."(клон)</a>";
    else
    $mass_opponent_unavaible[] = $row_users["id"];
}
function list_players($list_side1,$list_side2,$battle)
{
    echo"<u>Первая команда</u>: ";
    if($battle->winner!="side2")
    {
        for($i=0;$i<=count($list_side1)-1;$i++)
        {
            if($i)echo", ";
            echo $list_side1[$i];
        }
    }
    if(count($list_side1)==0 || $battle->winner=="side2")echo"<i>вся команда убита</i> ";
    echo"<br><u>Вторая команда</u>: ";
    if( $battle->winner=="side2" && $battle->type=="bot" )
    echo"<a style='cursor:hand;font-weight:bold;color:#708090'>".$_SESSION["login"]."(клон)</a>";
    else if((count($list_side2)==0 || $battle->winner=="side1"))
    echo"<i>вся команда убита</i> ";
    if($battle->winner != "side1")
    {
        for($i=0;$i<=count($list_side2)-1;$i++)
        {
            if($i)echo", ";
            echo $list_side2[$i];
        }
    }
}
$mass_opponent = array();
$side_mass = explode(";",$battle->$opp_side);
if(count($mass_opponent_unavaible)==0)
{
    for($i=0;$i<=count($side_mass)-2;$i++)
    {
        $mass_opponent[] = $side_mass[$i];
    }
}
elseif(count($mass_opponent_unavaible)>0)
{
    for($i=0;$i<=count($side_mass)-2;$i++)
    {
        $ins = 0;
        for($j=0;$j<=count($mass_opponent_unavaible)-1;$j++)
        {
            if($side_mass[$i]==$mass_opponent_unavaible[$j])
            $ins=1;
        }
        if(!$ins)
        $mass_opponent[] = $side_mass[$i];
    }
}
// **********
// Одежда
//
if(count($mass_opponent) && $myself->hp && !$battle->winner)
{
    $opponent_id = rand(0,(count($mass_opponent)-1));
    if($opponent->get_info($mass_opponent[$opponent_id],$battle->type)==false)
    {
        echo"Ошибка: невозможно получить данные о персонаже(2), возможно сервер в данный момент перегружен, попробуйте обновить страницу через несколько минут. ";
        exit();
    }
    else
    $opponent->param($myself->id);
}
echo"<html>
<head>
 <META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=windows-1251'>
 <link rel=stylesheet href=/css/index.css>
 <script language=JavaScript>
     
     function UnSetKick() {
     
         document.all('kick_on').value = '0';
     }
     
     function SetKick() {
     
         if( document.all('kick_on').value=='0' ) {
          
             document.all('kick_on').value = '1';
             setTimeout('UnSetKick();',30*1000);
             return true;
         }
         else {    
             return false;
         }     
     }
 </script>
</head>
<body bgcolor=#e5e1be>
<input type=hidden name=kick_on value='0'>
<script language=javascript>
var inf='';
function lifeline(now,max)
{
 var grn_life_pr = (now*100)/max;
 var grn_life_width = (grn_life_pr*160)/100;
 var red_life_width = 160 - grn_life_width;
 document.write('<table border=0 cellspacing=0 cellpadding=0><tr><td><img src=".$config["img_server"]."/grn_life.gif width='+grn_life_width+' height=10></td><td><img src=".$config["img_server"]."/red_life.gif width='+red_life_width+' height=10></td><td align=right>'+now+'/'+max+'</td></tr></table>');
}";
?>
function altt(text)
{
 var el = document.getElementById("altt");
 document.all("altt").innerHTML = '<table border=0 cellspacing=1 cellpadding=3 bgcolor=#000000><tr><td bgcolor=#ffffff style="color:#000000;font-size:70%">'+text+'</td></tr>';
 document.all("altt").style.visibility = "visible";
 var x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft + 3;
 var y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop+5;
 el.style.left = x + "px";
 el.style.top  = y + "px";
 if (window.event.clientX + el.offsetWidth + 3 > document.body.clientWidth)
 {
  x -= (window.event.clientX + el.offsetWidth + 3 - document.body.clientWidth);
  el.style.left = x + "px";
 }
 document.all("altt").focus();
}
<?
echo"
function altt_close()
{
 document.all("altt").style.visibility = "hidden";
}
</script>
<center><br>
<span id=altt style="position:absolute;z-index: 100;"></span>
<table border=0 width=95% cellspacing=0 cellpadding=0>
<tr>
<td width=220 valign=top>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td>".ch_info($myself->login,$myself->level,$myself->align,$myself->klan,$config["img_server"])."</td></tr><tr><td>
<script language=javascript>lifeline("".$myself->hp."","".$myself->maxhp."");</script>
</td></tr></table>
<table border='1' width=220 height=200 bordercolor=#dfd78f cellpadding=1 bordercolordark='#000000' bordercolorlight='#000000'>
<tr>
<td height='200' width=220 valign='middle' align=left bgcolor=#000000>
<img align=right src='".$config["img_server"]."/icons/".$myself->icon.".gif' border='0' alt='".$myself->login."' onmousemove="altt('<b>Параметры:</b><br>Удар: ".$myself->u." <br>Гибкость: ".$myself->g."<br>Логика: ".$myself->l." <br>Здоровье: ".$myself->z."');" onmouseout="altt_close();">
<span style='color:#c0c0c0;position:relative;z-index: 1; left:2px;width:220px; height:200px' class=comm>
";
$items = array(array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array());
$db = new DBconn;
$db->Conn("greece",$server_conf);
if($battle->type=="bot")
$db->query("select id from bag where owner='".$myself->id."' and dressed='y' order by id desc");
else
$db->query("select id from bag where owner='".$myself->id."' and dressed='y' order by id desc");
$db->num_rows();
$count_items = $db->num;
$items = SetItems($db,$items);
for($i=1;$i<=10;$i++)
{
    $w = "w".$i;
    $return = ShowItem($w,$count_items,$items,"");
    if(!strstr($return,"ничего не одето"))
    {
        $return = str_replace("href","style='font-size:95%;color:#d0cea2' href",$return);
        echo "<small>".$return."</small><br>";
        if(!$exists)
        $exists = 1;
    }
}
if(!$exists)
echo"<small><b>ничего не одето</b></small></span>";
$exists = 0;
echo"</span>";
echo"
</span>
</td>
</tr>
</table>
</td>
<td valign=top width=100%><br>";
if($battle->winner && $myself->battle_id==$battle->id)
echo $result_battle;
elseif($myself->hp<=0)
echo"<center><span style='color:darkred;font-weight:bold'>Вы убиты. Ждите окончания поединка!</span><br><input type=image src='".$config["img_server"]."/b_refresh.gif' value='обновить' onclick='if(SetKick()==true)location.href="battle.php"'></center>";
elseif(!$opponent->id)
{
    $mass_kick_time = explode(";",$battle->kick_time);
    for($i=0;$i<=count($mass_kick_time)-1;$i++)
    {
        $a_mass = explode("=",$mass_kick_time[$i]);
        if($a_mass[0]==$myself->id)
        {
            $new_time = time();
            $mass_kick_time[$i]=$myself->id."=".$new_time;
        }
    }
    $battle->kick_time=implode(";",$mass_kick_time);
    echo"<center><span style='font-weight:bold'>Ожидаем хода соперника</span><br><input type=image src='".$config["img_server"]."/b_refresh.gif' value='обновить' onclick='if(SetKick()==true)location.href="battle.php?act=kick"'></center>n";
}
else
{
    echo"<form action=battle.php method=post onsubmit='return SetKick();'>
<input type=hidden name=act value=kick>
<input type=hidden name=opponent_id value=".$opponent->id.">
<center>
<table border=0 width=230 cellspacing=1 cellpadding=0 height=20>
<tr><td width=100 bgcolor=#cbcbb0 style='color:#000000;font-weight:bold' align=center>Удар</td>
<td width=130 bgcolor=#cbcbb0 style='color:#000000;font-weight:bold' align=center>Блок</td>
</tr><tr><td>
<input type=radio name=f value=1> в голову<br>
<input type=radio name=f value=2> в грудь<br>
<input type=radio name=f value=3> в живот<br>
<input type=radio name=f value=4> в пояс<br>
<input type=radio name=f value=5> в ноги<br>
</td><td><input type=radio name=b value=1> голова и грудь<br>
<input type=radio name=b value=2> грудь и живот<br>
<input type=radio name=b value=3> живот и пояс<br>
<input type=radio name=b value=4> пояса и ног<br>
<input type=radio name=b value=5> головы и ног<br>
</td></tr><tr><td colspan=2 align=center><input type=image src='/img/b_fight.gif' value='нанести удар' style='font-weight:bold' class=button></td></tr>
</table></form>     
</center>";
}
if(!$battle->winner)
{
    $myhp = array();
    preg_match_all("/(".$_SESSION["id"]."=)[0-9]+/",$battle->hp,$myhp);
    $hp = explode("=",$myhp[0][0]);
    echo"<br><center>Вами нанесено: <b>".$hp[1]."</b> HP</center>";
}
echo"</td><td valign=top align=right>
<table border=0 cellspacing=0 cellpadding=0 width=220>
<tr><td>";
if(!$opponent->id)
{
    $images = array("1.gif","2.jpg","3.jpg");
    randomize;
    $rand = rand(0,2);
    echo"<img src=".$config["img_server"]."/battle/".$images[$rand]." border=0 align=right>";
}
else
{
    echo"<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td>".ch_info($opponent->login,$opponent->level,$opponent->align,$opponent->klan,$config["img_server"])."</td></tr><tr><td>
<script language=javascript>lifeline("".$opponent->hp."","".$opponent->maxhp."");</script>
</td></tr></table>
<table border='1' width=220 height=200 bordercolor=#dfd78f cellpadding=1 bordercolordark='#000000' bordercolorlight='#000000'>
<tr>
<td height='200' width=220 valign='middle' bgcolor=#000000>";
    $items = array(array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array());
    $db = new DBconn;
    $db->Conn("greece",$server_conf);
    if($battle->type=="bot")
    $db->query("select id from bag where owner='".$myself->id."' and dressed='y' order by id desc");
    else
    $db->query("select id from bag where owner='".$opponent->id."' and dressed='y' order by id desc");
    $db->num_rows();
    $count_items = $db->num;
    $items = SetItems($db,$items);
    $exists = 0;
    echo"
<img align=right src='".$config["img_server"]."/icons/";
    if($battle->type=="bot")
    echo $myself->icon;
    else
    echo $opponent->icon;
    echo".gif' border='0' alt='".$opponent->login."' onmousemove="altt('<b>Параметры:</b><br>Удар: ".$opponent->u." <br>Гибкость: ".$opponent->g."<br>Логика: ".$opponent->l." <br>Здоровье: ".$opponent->z."');" onmouseout="altt_close();">
<span style='color:#c0c0c0;position:relative;z-index: 1; left:2px;width:220px; height:200px' class=comm>
";
    for($i=1;$i<=10;$i++)
    {
        $w = "w".$i;
        $return = ShowItem($w,$count_items,$items,"");
        if(!strstr($return,"ничего не одето"))
        {
            $return = str_replace("href","style='font-size:95%;color:#d0cea2' href",$return);
            echo "<small>".$return."</small><br>";
            if(!$exists)
            $exists = 1;
        }
    }
    if(!$exists)
    echo"<small><b>ничего не одето</b></small>";
    echo"</span>
</td>
</tr>
</table>";
}
echo"</td></tr></table>
</td></tr>
<tr><td colspan=3>
<br>";
echo list_players($list_side1,$list_side2,$battle);
echo"<br><br>
<table border=0 cellspacing=0 cellpadding=1>";
$db->query("select battle_logs.* from battle_logs where battle_id='".$battle->id."' ORDER BY time desc LIMIT 20");
$db->num_rows();
$log["attack"] = file("battle/comment/attack.dat");
$log["block"] = file("battle/comment/block.dat");
$log["evade"] = file("battle/comment/evade.dat");
$log["dead"] = file("battle/comment/dead.dat");
$log["greating"] = file("battle/comment/greating.dat");
$plc_kick = array("голову","грудь","живот","пояс","ноги");
$time_before = "";
for($i=1;$i<=$db->num;$i++) {
    $db->fetch_array();
    $frase = $log[$db->row["type"]][$db->row["cmt_id"]];
    preg_match_all("/(^|;)".$db->row["ch1"]."#[-a-zA-Zа-яА-Я0-9()_s]+/",$battle->data,$ch1_data);
    preg_match_all("/(^|;)".$db->row["ch2"]."#[-a-zA-Zа-яА-Я0-9()_s]+/",$battle->data,$ch2_data);
    $ch1_data = explode("#",$ch1_data[0][0]);
    $ch2_data = explode("#",$ch2_data[0][0]);
    if( preg_match("/(^|;)".$db->row["ch1"].";/",$battle->side1) ) {
        $ch1_color = "#A0522D";
        $ch2_color = "#708090";
    }
    else {
        $ch1_color = "#708090";
        $ch2_color = "#A0522D";
    }
    $frase = str_replace("{p1}","<span style='color:".$ch1_color.";font-weight:bold;cursor:pointer;cursor:hand;'>".$ch1_data[1]."</span>",$frase);
    $frase = str_replace("{p2}","<span style='color:".$ch2_color.";font-weight:bold;cursor:pointer;cursor:hand'>".$ch2_data[1]."</span>",$frase);
    $frase = str_replace("{pl}",$plc_kick[$db->row["kick_in"]-1],$frase);
    if( $db->row["kick_type"]=="0" && $db->row["type"]=="attack" )
    $frase .= "<b>-".$db->row["kick_power"]."</b>";
    else if( $db->row["type"]=="attack" )
    $frase .= "<span style='color:darkred;font-weight:bold'>-".$db->row["kick_power"]."</span>";
    if( $db->row["type"]=="attack" )
    $frase .= " (".$db->row["hp"]."/".$db->row["maxhp"].")";
    if( $db->row["time"]!=$time_before && $i > 1)
    echo"<tr><td height=10><hr size=1></td></tr>";
    echo"<tr><td><span style='font-weight:bold;";
    if( ($db->row["ch1"]==$_SESSION["id"] || $db->row["ch2"]==$_SESSION["id"]) && $battle->type!="normal" && $battle->type!="bot" )
    echo"background-color:darkred;color:#ffffff;";
    else
    echo"color:62665c;text-decoration:underline;font-weight:bold;";
    echo"'>".Date("H:i",$db->row["time"])."</span> ".$frase;
    echo"</td></tr>";
    $time_before = $db->row["time"];
}
if($db->num==20)
{
    echo"<tr><td height=30 valign=bottom><i>Комментарий был обрезан для ускорения загрузки страницы, полностью комментарий вы можете увидеть <a href='/inform/battle_".$battle->id.".html' target=_blank><b>здесь »</b></a></i></td></tr>";
}
echo"</td></tr></table>
<br><br>     
</body></html>";
$battle->write();
?>