<?
include 'system/bd.php';
include 'system/cook.php';
include ("system/gzip.php");
if(isset($_SESSION['auth']) && $_SESSION['auth']==1){
include 'system/head.php';
include 'system/head1.php';

?>
<style>
.enemy-hp2 {
    position: relative;
    overflow: hidden;
    margin-left: 3px;
    margin-top: 5px;
    height: 4px;
    background: none repeat scroll 0% 0% #2B2B2B;
    border: 2px solid #000;
}

.enemy-hp-remain2 {
    float: left;
    height: 4px;
}
.hp-green {
    background: none repeat scroll 0% 0% #0D6822 !important;
}

</style>


<?

$my_atk = $user[attack]/5+rand($user[lvl],6);


if ($my_atk<1)
{
    $my_atk = $user[attack]/5+rand($user[lvl],6);
}
//
if($user[spells1]=="0"){
$attack_1=0;
$sec_1=45; }
if($user[spells1]=="1"){
$attack_1=5; 
$sec_1=45; }
if($user[spells1]=="2"){
$attack_1=12;
$sec_1=41; }
if($user[spells1]=="3"){
$attack_1=19; 
$sec_1=36; }
if($user[spells1]=="4"){
$attack_1=27; 
$sec_1=32; }
if($user[spells1]=="5"){
$attack_1=36; 
$sec_1=29; }
if($user[spells1]=="6"){
$attack_1=42;
$sec_1=25; }
if($user[spells1]=="7"){
$attack_1=54; 
$sec_1=22; }
if($user[spells1]=="8"){
$attack_1=66;
$sec_1=19; }
if($user[spells1]=="9"){
$attack_1=75; 
$sec_1=16; }
if($user[spells1]=="10"){
$attack_1=80; 
$sec_1=15; }

$spells1 = rand(1,13)+($user[attack]/5)/100* $attack_1;

if ($m_atk<1)
{
   $m_atk = $user[attack]/5+$spells1;
}

//////атака босса///
if ($boss_atk<1) 
{
    $boss_atk = $user[lvl]+rand($user[lvl]*10,$user[lvl]/2*10);
}

   
if($user[hp] <= 0){
echo '<div class="main"><div class="block_zero center"><center><img class="img_ares" src="/img/ares.png">
    <font color="green">Вы убиты!</font></div></div></center>';
    include './system/foot.php';
header ("Location: dead.php");
    exit;
    }


$ares = mysql_fetch_assoc(mysql_query("SELECT * FROM `ares` ORDER BY `id` LIMIT 1"));




    if($ares[hp]<=0){
echo' 
<center><img class="img_ares" src="/img/ares.png">
<div class="empty_block del_bottom item_center">    Арес убит!</div></center>';
    include './system/foot.php';
    exit;
    }
    
if($my_atk >$ares[hp] && $ares[hp]>0)
{
    mysql_query("UPDATE `ares` SET `hp`=0 WHERE `id`='".$ares['id']."'")or die (mysql_error());
    echo ' <img class="img_ares" src="/img/ares.png">
<div class="empty_block del_bottom item_center"> <center>
        Арес повержен! </center> </div>';
    
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `ares_log`"),0);
        if($total>0){
$q_nagr = mysql_query("SELECT * FROM `ares_log` GROUP BY `user_id` ORDER BY RAND()");
        /*3 лучших */
$top_q  = mysql_query("SELECT SUM( user_uron ) , `user_id`     FROM  `ares_log` GROUP BY  `user_id` ORDER BY  SUM( user_uron ) DESC LIMIT 3");
    
            $topes_us = 'Лучшие в борьбе с Аресом:<br> ';
            
            while($top= mysql_fetch_assoc($top_q)){
$max_uron = mysql_result(mysql_query("SELECT SUM( user_uron ) FROM `ares_log` WHERE `user_id`='".$top['user_id']."'"),0);
$moneyReward = $max_uron/20;
             
mysql_query("UPDATE `user` SET     `gold`=`gold`+".$moneyReward."  WHERE `id`='".$top['user_id']."'");

mysql_query("UPDATE `user` SET     `exp`=`exp`+".$ares[exp].",`gold`=`gold`+".$moneyReward*rand(2,3)."  WHERE `id`='".$top['user_id']."'");
                


$name_top = mysql_fetch_assoc(mysql_query("SELECT `login` FROM `user` WHERE `id`='".$top['user_id']."' LIMIT 1"));
$topes_us.= '<span class="login">'.$name_top['login'].'</span>('.$max_uron.'- <img src="images/icon/gold.png"> '.$ares[gold].')<br>'; 
                $ares[gold]=$ares[gold]-4;
                $ares[exp]= round($ares[exp]/2);

            }
            mysql_query("INSERT INTO `chat` SET
            `user_id`='1',
            `text`='".$topes_us."',
            `time`='".time()."'");

            while($nagr = mysql_fetch_assoc($q_nagr)){
                mysql_query("INSERT INTO `journal` SET 
`user_id`='".$nagr['user_id']."', `text`='За победу над Аресом Вы получаете <img src=\"images/icon/gold.png\"> ".$ares[gold]."',
                `time`='".time()."'");    

mysql_query("UPDATE `user` SET `gold`=`gold`+".$ares[gold].",`journal`=`journal`+1 WHERE `id`='".$nagr['user_id']."'");


                $ares[gold]= round($ares[gold]/2);
mysql_query("DELETE FROM `ares_log` WHERE `user_id`='".$nagr['user_id']."'");
            }
            mysql_query("TRUNCATE TABLE  `ares_log`");
                    }
    include './system/foot.php';
    exit;
    }
    
$ares[hp] = $ares[hp]-$my_atk;    
$ares_sl = array('тынул в глаз','нанес урон','порезал','ударил','царапнул');
shuffle($ares_sl);
$rand_m = rand(15,15);

$user[hp] = $user[hp]-$boss_atk;    
$ares_sll = array('босс тыкнул в глаз','босс нанес урон','босс порезал','босм ударил','босс царапнул');
shuffle($ares_sll);
$rand_mm = rand(15,15);




/**
* Атака написанная не таким ГК
* @author Alex Priadko
*/

if (isset($_GET['attack']))
{
    mysql_query("INSERT INTO `ares_log` SET
    `user_id`='".$user[id]."',
    `text`='".$ares_sl[0]."
 <b>Аресу</b> на <b>".$my_atk."</b><br>
 <b>Арес</b> проатачил на <b>".$boss_atk."</b>',
    `time`='".time()."',
    `user_uron`='".$my_atk."',
`boss_uron`='".$boss_atk."' ");


mysql_query("UPDATE `user` SET `exp`=`exp`+'".$my_atk."',
`hp`=`hp`-'".$boss_atk."'
 WHERE `id` = '$user[id]'");//опыт за урон

    mysql_query("UPDATE `ares` SET `hp`=`hp`-".$my_atk." 
 WHERE `id`='".$ares['id']."'");
    mysql_query("UPDATE `user` SET `mp`=`mp`-".$rand_m.",`mana_resp`='".time()."' WHERE `id`='".$user['id']."'");
    $all_uron = mysql_result(mysql_query("SELECT SUM( user_uron )FROM `ares_log` WHERE `user_id`='".$user['id']."'"),0);
    $perc_health_aluko = round($ares[hp]/$ares[hpfull]*100,2);
    header("Location:?");
    exit;
}


if (isset($_GET['attack2']))
{

    mysql_query("INSERT INTO `ares_log` SET
    `user_id`='".$user[id]."',
    `text`='".$ares_sl[0]."
 <b>Аресу</b> на <b>".$m_atk."</b><br>
 <b>Арес</b> проатачил на <b>".$boss_atk."</b>',
    `time`='".time()."',
    `user_uron`='".$m_atk."',
`boss_uron`='".$boss_atk."' ");

$s_1=time() + $sec_1;

mysql_query("UPDATE `user` SET `exp`=`exp`+'".$my_atk."',
`hp`=`hp`-'".$boss_atk."',
`spells_time1` = '".$s_1."'
 WHERE `id` = '$user[id]'");
//опыт за урон



    mysql_query("UPDATE `ares` SET `hp`=`hp`-".$m_atk."
 WHERE `id`='".$ares['id']."'");
    mysql_query("UPDATE `user` SET `mp`=`mp`-".$rand_m.",`mana_resp`='".time()."' WHERE `id`='".$user['id']."'");
    $all_uron = mysql_result(mysql_query("SELECT SUM( user_uron )FROM `ares_log` WHERE `user_id`='".$user['id']."'"),0);
    $perc_health_aluko = round($ares[hp]/$ares[hpfull]*100,2);
    header("Location:?");
    exit;
}



echo' <div class="empty_block item_center bottom">Арес</div>';
   $ares_progress = round(100/($ares[hpfull]/$ares[hp]));

    echo '    
<div class="block_zero center">  
<center> <img class="img_ares" src="/img/ares.png"><br>
</div>';
echo'
      
<div class="line"></div>

  <div class="empty_block item_center bottom">
  <div class="enemy-hp2">
<div class="enemy-hp-remain2 hp-green" style="width:'.$ares_progress.'%"></div>
</div>
<center>Здоровье:

<font color="green"> 

'.$ares[hp].'

</font>

/

<font color="green">

'.$ares[hpfull].'

</font>
</div>';


echo'<div class="empty_block top item_center">
    <a href="?attack"><div class="spell_container attack bord"></div></a>';

$s1=$user[spells_time1]-time();

 if($s1 >= '0'){ echo'  <a href="?attack">';
}else{
 echo'  <a href="?attack2">';
}
echo' <div class="spell_container spell_2 bord">
<div class="spell_text"> ';       
  if($s1 >= '0'){ echo" $s1 "; }                                                         
echo'</div></div> </a>';
 echo'  <a href="new_game?use_spell=3"><div class="spell_container spell_11 bord">
<div class="spell_text">                                                                                            </div></div> </a>
      </div>

</span>

</span>  <div class="line"></div>';
    


$ares_log_q = mysql_query("SELECT * FROM `ares_log` ORDER BY `time` DESC LIMIT 5");

echo '</div>';
$self = 'Воин Арес';
$inFight = mysql_num_rows(mysql_query("SELECT `id`,`self` FROM `user` 
                                    WHERE `self`='".($self)."' and 
                                    `online`>'".(time()-300)."'"));

?>

<?
echo' <div class="empty_block item_center bottom">Лог боя</div>';

while($ares_log = mysql_fetch_array($ares_log_q))
{

   $us = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id`='".$ares_log[user_id]."'"));



    //echo '<a href="user.php?ank='.$user['id'].'">'.$user['login'].'</a> '.$ares_log['text'].'<br>';
    ?>
    <div class ='block'>
    <span class ='float:left;'/>  
 Ты   
    </span>
    
    <?=$ares_log['text'];?>


    </div>

    <?
}

/**
* Вывод лидеров в бою!
*
*@author AlexPriadko
*/
$queryLiders  = mysql_query("SELECT SUM( user_uron ) , `user_id`  FROM  `ares_log`
                             GROUP BY  `user_id`
                             ORDER BY  SUM( user_uron ) DESC LIMIT 3");

?>
<div class="empty_block item_center bottom">Топ 3 бойцов:</div>
<?

$alPos = 0;
while ($liders = mysql_fetch_array($queryLiders))
{
   $alPos++;
    $us = mysql_fetch_array(mysql_query("SELECT * FROM `user` 
                                        WHERE `id`='".$liders['user_id']."'"));
    $damageUs = mysql_result(mysql_query("SELECT SUM( user_uron ) , `user_id`  
                            FROM  `ares_log`
                            WHERE `user_id`='".$liders['user_id']."'"),0);
    
    ?>  
    <div class ='block'>
    <span class ='float:left;'/>
    <?=$alPos;?>.
<img src='/img/icon/<?=$us['rasa']?>.png' alt='*'/>



   <a href="users.php?id='.$result['id'].'">
    <?=$us['login'];?>
    </a>
    </span>
    <span class ='float:right;'/>
    <?=$damageUs;?>
    </span>
    </div>
    <?
}

}


include './system/foot.php';


