<?
    
    include './system/common.php';
    
 include './system/functions.php';
        
      include './system/user.php';
    
if(!$user OR $user['level'] < 3) {

  header('location: /');
    
exit;

}


    $title = 'Колизей';    

include './system/h.php';  

?>

 
<?
 
if($user['level'] > 9) {

  $member = mysql_query('SELECT * FROM `coliseum_member` WHERE `user` = "'.$user['id'].'" ORDER BY `time` DESC LIMIT 1');
  $member = mysql_fetch_array($member);

  if($member) {

  $battle = mysql_query('SELECT * FROM `coliseum` WHERE `id` = "'.$member['battle'].'"');
  $battle = mysql_fetch_array($battle);

  }

  
  if($member['exit'] == 0 && $battle['start'] == 1 && $battle['end'] == 0) {

  if(mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'" AND `dead` = "0"'),0) == 1) {
     
    mysql_query('UPDATE `coliseum` SET `end` = "1" WHERE `id` = "'.$battle['id'].'"');
  
      header('location: /coliseum/');
  
  exit;
  
  }
  
?>
  
  

<?

    if($member['dead'] == 1) {
    
?>

 <div class='line'></div>

<div class='content' align='center'>
<a href='/coliseum/?' class='button'>Обновить</a>

<br/><br/>
<font color='#999'>Вы были убиты во время сражения, ожидайте окончания боя</font>
</div>

<?

    

    }
    else
    {
  
  if($_GET['exit'] == true) {

    $log = '<img src=\'/images/icon/race/'.$user['r'].'.png\' alt=\'\'/> <b>'.$user['login'].'</b> покидает бой';    
    mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                               `user`,
                                             `object`,
                                               `text`) VALUES ("'.$battle['id'].'",
                                                                 "'.$user['id'].'",
                                                               "'.$object['id'].'",
                                                                        "'.$log.'")');

    mysql_query('UPDATE `coliseum_member` SET `dead` = "1" WHERE `battle` = "'.$battle['id'].'" AND `user` = "'.$user['id'].'"');
  
      header('location: /coliseum.php');
  
  exit;
  
  }
  
  if($member['object'] == 0) {
  
    $rand_object = mysql_query('SELECT * FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'" AND `dead` = "0" AND `user` != "'.$user['id'].'" ORDER BY RAND() LIMIT 1');
    $rand_object = mysql_fetch_array($rand_object);


    mysql_query('UPDATE `coliseum_member` SET `object` = "'.$rand_object['id'].'" WHERE `battle` = "'.$battle['id'].'" AND `user` = "'.$user['id'].'"');

  }

if($member['object']) {

  if($_GET['last'] == true) {
  
    $rand_object = mysql_query('SELECT * FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'" AND `dead` = "0" AND `user` != "'.$user['id'].'" ORDER BY RAND() LIMIT 1');
    $rand_object = mysql_fetch_array($rand_object);


    mysql_query('UPDATE `coliseum_member` SET `object` = "'.$rand_object['id'].'" WHERE `battle` = "'.$battle['id'].'" AND `user` = "'.$user['id'].'"');

  header('location: /coliseum/');

  }


    $member_object = mysql_query('SELECT * FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'" AND `id` = "'.$member['object'].'"');
    $member_object = mysql_fetch_array($member_object);

    $object = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$member_object['user'].'"');
    $object = mysql_fetch_array($object);

  
  if($_GET['attack'] == true && $member_object['dead'] == 0) {
  
    $dmg = 0;
    
    $object_dmg = 0;
  
  if($user['ability_1'] > 0) {
  switch($user['ability_1']) {
    case 0:
    $a_1_bonus = 25;
   $a_1_chanse = 5;
     break;
    case 1:
    $a_1_bonus = 25;
   $a_1_chanse = 5;
     break;
    case 2:
    $a_1_bonus = 30;
   $a_1_chanse = 5;
     break;
    case 3:
    $a_1_bonus = 35;
   $a_1_chanse = 5;
     break;
    case 4:
    $a_1_bonus = 40;
   $a_1_chanse = 5;
     break;
    case 5:
    $a_1_bonus = 45;
   $a_1_chanse = 5;
     break;
    case 6:
    $a_1_bonus = 45;
   $a_1_chanse = 8;
     break;
    case 7:
    $a_1_bonus = 50;
   $a_1_chanse = 8;
     break;
    case 8:
    $a_1_bonus = 55;
   $a_1_chanse = 8;
     break;
    case 9:
    $a_1_bonus = 60;
   $a_1_chanse = 8;
     break;
    case 10:
    $a_1_bonus = 65;
   $a_1_chanse = 8;
     break;
    case 11:
    $a_1_bonus = 65;
   $a_1_chanse = 11;
     break;
    case 12:
    $a_1_bonus = 70;
   $a_1_chanse = 11;
     break;
    case 13:
    $a_1_bonus = 75;
   $a_1_chanse = 11;
     break;
    case 14:
    $a_1_bonus = 80;
   $a_1_chanse = 11;
     break;
    case 15:
    $a_1_bonus = 85;
   $a_1_chanse = 11;
     break;
    case 16:
    $a_1_bonus = 85;
   $a_1_chanse = 14;
     break;
    case 17:
    $a_1_bonus = 90;
   $a_1_chanse = 14;
     break;
    case 18:
    $a_1_bonus = 95;
   $a_1_chanse = 14;
     break;
    case 19:
    $a_1_bonus = 100;
   $a_1_chanse = 14;
     break;
    case 20:
    $a_1_bonus = 105;
   $a_1_chanse = 14;
     break;
    case 21:
    $a_1_bonus = 105;
   $a_1_chanse = 17;
     break;
    case 22:
    $a_1_bonus = 145;
   $a_1_chanse = 20;
     break;
    case 23:
    $a_1_bonus = 165;
   $a_1_chanse = 23;
     break;
    case 24:
    $a_1_bonus = 165;
   $a_1_chanse = 23;
     break;
  }
  
  if(mt_rand(0, 100) <= $a_1_chanse) {

    $a_1 = true;

  }
  
  }

  if($user['ability_3'] > 0) {

  switch($user['ability_3']) {
    case 0:
      $a_3_bonus = 5;
$a_3_crit_chanse = 5;
     $a_3_chanse = 20;
     break;
    case 1:
      $a_3_bonus = 5;
$a_3_crit_chanse = 5;
     $a_3_chanse = 20;
     break;
    case 2:
      $a_3_bonus = 8;
$a_3_crit_chanse = 5;
     $a_3_chanse = 20;
     break;
    case 3:
      $a_3_bonus = 11;
$a_3_crit_chanse = 5;
     $a_3_chanse = 20;
     break;
    case 4:
      $a_3_bonus = 14;
$a_3_crit_chanse = 5;
     $a_3_chanse = 20;
     break;
    case 5:
      $a_3_bonus = 17;
$a_3_crit_chanse = 5;
     $a_3_chanse = 20;
     break;
    case 6:
      $a_3_bonus = 17;
$a_3_crit_chanse = 7;
     $a_3_chanse = 25;
     break;
    case 7:
      $a_3_bonus = 20;
$a_3_crit_chanse = 7;
     $a_3_chanse = 25;
     break;
    case 8:
      $a_3_bonus = 23;
$a_3_crit_chanse = 7;
     $a_3_chanse = 25;
     break;
    case 9:
      $a_3_bonus = 26;
$a_3_crit_chanse = 7;
     $a_3_chanse = 25;
     break;
    case 10:
      $a_3_bonus = 29;
$a_3_crit_chanse = 7;
     $a_3_chanse = 25;
     break;
    case 11:
      $a_3_bonus = 29;
$a_3_crit_chanse = 9;
     $a_3_chanse = 30;
     break;
    case 12:
      $a_3_bonus = 32;
$a_3_crit_chanse = 9;
     $a_3_chanse = 30;
     break;
    case 13:
      $a_3_bonus = 35;
$a_3_crit_chanse = 9;
     $a_3_chanse = 30;
     break;
    case 14:
      $a_3_bonus = 38;
$a_3_crit_chanse = 9;
     $a_3_chanse = 30;
     break;
    case 15:
      $a_3_bonus = 41;
$a_3_crit_chanse = 9;
     $a_3_chanse = 30;
     break;
    case 16:
      $a_3_bonus = 41;
$a_3_crit_chanse = 11;
     $a_3_chanse = 35;
     break;
    case 17:
      $a_3_bonus = 44;
$a_3_crit_chanse = 11;
     $a_3_chanse = 35;
     break;
    case 18:
      $a_3_bonus = 47;
$a_3_crit_chanse = 11;
     $a_3_chanse = 35;
     break;
    case 19:
      $a_3_bonus = 50;
$a_3_crit_chanse = 11;
     $a_3_chanse = 35;
     break;
    case 20:
      $a_3_bonus = 53;
$a_3_crit_chanse = 11;
     $a_3_chanse = 35;
     break;
   case 21:
      $a_3_bonus = 53;
$a_3_crit_chanse = 13;
     $a_3_chanse = 40;
     break;
    case 22:
      $a_3_bonus = 77;
$a_3_crit_chanse = 15;
     $a_3_chanse = 45;
     break;
    case 23:
      $a_3_bonus = 89;
$a_3_crit_chanse = 17;
     $a_3_chanse = 50;
     break;
    case 24:
      $a_3_bonus = 89;
$a_3_crit_chanse = 17;
     $a_3_chanse = 50;
     break;

  }

  if(mt_rand(0, 100) <= $a_3_chanse) {

    $a_3 = true;

  }

  }

  function quality_color($i) {
  
    switch($i) {
    case 0:
 
$color = "#908060";
     break;
    case 1:

$color = "#60c030";
     break;

    case 2:
 
$color = "#6090c0";
     break;

    case 3:
 
$color = "#c060f0";
     break;

    case 4:
 
$color = "#f06000";
     break;


    case 5:
 
$color = "#909090";
     break;


    case 6:
 
$color = "#909090";
     break;

  }

  return $color;
  }
  
  
      $dmg +=round(rand(($user['str']/6),($user['str']/4)));

      if($a_1 == true) {
      
        $dmg += round(($dmg / 100) * $a_1_bonus);
      
      }

$dmg -= round(rand(($object['def']/12),($object['def']/7)));

    if($dmg < 0) {
    
      $dmg = 0;
    
    }
    
    if($dmg > $object['hp']) {
    
      $dmg = $object['hp'];
    
    }
    

    if($a_3 == true) {
    
    $crit = ( (rand(1,2) * ($user['agi'] / 100) + $a_3_crit_chanse ) - (rand(1,2) * ($opponent['agi'] / 100)));
    
    }
    else
    {

    $crit = ( (rand(1,2) * ($user['agi'] / 100) ) - (rand(1,2) * ($opponent['agi'] / 100)));

    }

    if(mt_rand(0, 100) <= $crit) {
   
      $dmg *= 2;

    if($a_3 == true) {
   
      $dmg += round(($dmg / 100) * $a_3_bonus);
    
    }

  $log_crit = true;
    
    }

    $dodge = ( (rand(1,2) * ($opponent['agi'] / 100) ) - (rand(1,2) * ($user['agi'] / 100)));

    if(mt_rand(0, 100) <= $dodge) {
   
      $dmg = 0;
      
    }
    
    

    
    $dmg_time = time() - $member['time'];
    
    if($dmg_time < 2) {
    
      $dmg = 0;
    
    }
    
    if($dmg_time > 1 && $dmg_time < 4) {
    
      $dmg -= round($dmg / 2);
    
    }

    if($a_1 == true) {
    
    $log = 'Вы применили <img src=\'/images/icon/quality/'.$user['ability_1_quality'].'.png\'> <font color=\''.quality_color($user['ability_1_quality']).'\'>Ярость титана</font>';    

    mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                               `user`,
                                             `object`,
                                               `text`,
                                               `show`) VALUES ("'.$battle['id'].'",
                                                                 "'.$user['id'].'",
                                                               "0",
                                                                        "'.$log.'",
                                                                 "'.$user['id'].'")');
                                                                 
                                                                 
    $log = '<img src=\'/images/icon/race/'.$user['r'].'.png\' alt=\'\'/> <b>'.$user['login'].'</b> применил <img src=\'/images/icon/quality/'.$user['ability_1_quality'].'.png\'> <font color=\''.quality_color($user['ability_1_quality']).'\'>Ярость титана</font>';    
    mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                               `user`,
                                             `object`,
                                               `text`) VALUES ("'.$battle['id'].'",
                                                                 "'.$user['id'].'",
                                                               "0",
                                                                        "'.$log.'")');

    }

    if($a_3 == true) {
    
    $log = 'Вы применили <img src=\'/images/icon/quality/'.$user['ability_3_quality'].'.png\'> <font color=\''.quality_color($user['ability_3_quality']).'\'>Вихрь критов</font>';    

    mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                               `user`,
                                             `object`,
                                               `text`,
                                               `show`) VALUES ("'.$battle['id'].'",
                                                                 "'.$user['id'].'",
                                                               "0",
                                                                        "'.$log.'",
                                                                 "'.$user['id'].'")');

    $log = '<img src=\'/images/icon/race/'.$user['r'].'.png\' alt=\'\'/> <b>'.$user['login'].'</b> применил <img src=\'/images/icon/quality/'.$user['ability_3_quality'].'.png\'> <font color=\''.quality_color($user['ability_3_quality']).'\'>Вихрь критов</font>';    
    mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                               `user`,
                                             `object`,
                                               `text`) VALUES ("'.$battle['id'].'",
                                                                 "'.$user['id'].'",
                                                               "0",
                                                                        "'.$log.'")');

                                                                 
    }
    
    if($dmg == 0) {
      $log = 'Вы промахнулись';
    }
    else
    {
      $log = 'Вы ударили <img src=\'/images/icon/race/'.$object['r'].'.png\' alt=\'*\'/> <b>'.$object['login'].'</b> на <b>'.$dmg.'</b> '.($log_crit == true ? '(крит)':'');    
    }
    
    mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                               `user`,
                                             `object`,
                                               `text`,
                                               `show`) VALUES ("'.$battle['id'].'",
                                                                 "'.$user['id'].'",
                                                               "'.($dmg > 0 ? $object['id']:0).'",
                                                                        "'.$log.'",
                                                                 "'.$user['id'].'")');
    
    if($dmg > 0) {
      $log = '<img src=\'/images/icon/race/'.$user['r'].'.png\'/> <b>'.$user['login'].'</b> ударил Вас на <b>'.$dmg.'</b> '.($log_crit == true ? '(крит)':'');    
    mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                               `user`,
                                             `object`,
                                               `text`,
                                               `show`) VALUES ("'.$battle['id'].'",
                                                               "'.$object['id'].'",
                                                                 "'.$user['id'].'",
                                                                        "'.$log.'",
                                                               "'.$object['id'].'")');
    }

    if($dmg > 0) {
    $log = '<img src=\'/images/icon/race/'.$user['r'].'.png\' alt=\'\'/> <b>'.$user['login'].'</b> ударил <img src=\'/images/icon/race/'.$object['r'].'.png\' alt=\'*\'/> <b>'.$object['login'].'</b> на <b>'.$dmg.'</b> '.($log_crit == true ? '(крит)':'');    
    mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                               `user`,
                                             `object`,
                                               `text`) VALUES ("'.$battle['id'].'",
                                                                 "'.$user['id'].'",
                                                               "'.$object['id'].'",
                                                                        "'.$log.'")');
    }



    mysql_query('UPDATE `users` SET `hp` = "'.($object['hp'] - $dmg).'" WHERE `id` = "'.$object['id'].'"');
    mysql_query('UPDATE `coliseum_member` SET `time` = "'.time().'" WHERE `battle` = "'.$battle['id'].'" AND `user` = "'.$user['id'].'"');






    if($dmg >= $object['hp']) {

      $log = 'Вы убили <img src=\'/images/icon/race/'.$object['r'].'.png\' alt=\'*\'/> <b>'.$object['login'].'</b>';        
      mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                                 `user`,
                                               `object`,
                                                 `text`,
                                                 `show`) VALUES ("'.$battle['id'].'",
                                                                   "'.$user['id'].'",
                                                                 "'.$object['id'].'",
                                                                          "'.$log.'",
                                                                   "'.$user['id'].'")');

      $log = '<img src=\'/images/icon/race/'.$user['r'].'.png\' alt=\'*\'/> <b>'.$user['login'].'</b> убил Вас';    
      mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                                 `user`,
                                               `object`,
                                                 `text`,
                                                 `show`) VALUES ("'.$battle['id'].'",
                                                                 "'.$object['id'].'",
                                                                   "'.$user['id'].'",
                                                                          "'.$log.'",
                                                                 "'.$object['id'].'")');
    
    
      $log = '<img src=\'/images/icon/rip.png\' alt=\'*\'/> <img src=\'/images/icon/race/'.$user['r'].'.png\' alt=\'*\'/> <b>'.$user['login'].'</b> убил <img src=\'/images/icon/race/'.$object['r'].'.png\' alt=\'*"\'> <b>'.$object['login'].'</b>';    
      mysql_query('INSERT INTO `coliseum_log` (`battle`,
                                                 `user`,
                                               `object`,
                                                 `text`) VALUES ("'.$battle['id'].'", 
                                                                 "'.$user['id'].'",
                                                               "'.$object['id'].'",
                                                                        "'.$log.'")');


      mysql_query('UPDATE `coliseum_member` SET `dead` = "1" WHERE `battle` = "'.$battle['id'].'" AND `user` = "'.$object['id'].'"');
      mysql_query('UPDATE `coliseum_member` SET `kills` = `kills` + 1 WHERE `battle` = "'.$battle['id'].'" AND `user` = "'.$user['id'].'"');

      $rand_object = mysql_query('SELECT * FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'" AND `dead` = "0" AND `user` != "'.$user['id'].'" ORDER BY RAND() LIMIT 1');
      $rand_object = mysql_fetch_array($rand_object);

      mysql_query('UPDATE `coliseum_member` SET `object` = "'.$rand_object['id'].'" WHERE `battle` = "'.$battle['id'].'" AND `user` = "'.$user['id'].'"');

    }

  }

?>  


<table><tr><td style="width:52px;padding:4px;padding-top:6px"><img src="http://213.239.195.28/xaos/style2/prf_1.jpg" alt="" style="border:1px solid #ac0000;border-radius:3px"/></td><td style="padding:2px;font-size:12px;color:#a5a5a5"><table><tr><td><div style="color:khaki;font-size:16px"><span style="color:#skyblue"><img src="http://213.239.195.28/xaos/16x16/crown_gold.png" alt=""/> <?=$object['login']?></span>   <span style="color:#a5a5a5;font-size:12px"></span></div></td></tr></table><table><tr><td style="font-size:14px"><img src="http://213.239.195.28/xaos/style2/force.png" alt=""/> Урон <?=n_f($object['str'])?> <img src="http://213.239.195.28/xaos/style/heart.png" alt=""/> <span style="color:red"><?=n_f($object['hp'])?> хп</span> <img src="http://213.239.195.28/xaos/style2/shield1.png" alt=""/> <?=n_f($object['def'])?></td></tr></table><div style="padding:5px;padding-left:0px;padding-bottom:0"><div style="border:1px solid #131313;background:#232323;border-radius:3px;background-image:url(http://xaos.mobi/style2/exp5.png);background-position:center center;"><div style="border-radius:3px;height:8px;background:#009a00;width:<?=(100/($hp/$object['hp']))?>%;border-right:1px solid #191919;background-image:url(http://xaos.mobi/style/exp5.png);background-position:left center;"></div></div></div></td></tr></table></div><div class="separ3"></div><div class="menu_link3" style="text-align:left"><a href="/coliseum/?attack=true" class="mybutt_att"><img src="http://213.239.195.28/xaos/style2/dsword.png" alt=""/> Атаковать</a> <a href="/coliseum/?last=true" class="mybutt_att"><img src="http://213.239.195.28/xaos/16x16/arrow_refresh.png" alt=""/> Другой</a> <a href="" class="mybutt_att"><img src="http://213.239.195.28/xaos/16x16/exclamation.png" alt=""/> Бьют меня (1)</a> </div><div class="separ"></div><div class="menu_link2" style="padding-bottom:0"><table><tr><td style="width:52px;padding:4px;padding-top:6px"><img src="http://213.239.195.28/xaos/style2/prf_1.jpg" alt="" style="border:1px solid #131313;border-radius:2px;height:50px;width:50px"/></td><td style="padding:2px;font-size:14px;color:#a5a5a5"><table><tr><td><div style="color:khaki;font-size:16px"> <?=$user['login']?> <span style="color:red">-689 хп</span></div></td></tr></table><img src="http://213.239.195.28/xaos/style2/force.png" alt=""/> Урон <?=n_f($user['str'])?> <img src="http://213.239.195.28/xaos/style/heart.png" alt=""/> <span style="color:green"><?=n_f($user['hp'])?> хп</span> <img src="http://213.239.195.28/xaos/style2/shield1.png" alt=""/> <?=n_f($user['def'])?><div style="padding:5px;padding-left:0px;padding-bottom:0"><div style="border:1px solid #131313;background:#232323;border-radius:3px;background-image:url(http://xaos.mobi/style2/exp5.png);background-position:center center;"><div style="border-radius:3px;height:8px;background:#009a00;width:<?=(100/($hp/$user['hp']))?>%;border-right:1px solid #191919;background-image:url(http://xaos.mobi/style/exp5.png);background-position:left center;"></div></div></td></tr></table></div></div><div class="separ"></div><div class="menu_link3" style="font-size:16px;color:#a5a5a5">Бутылки не найдены.</div></div><div class="separ"></div><div  class="menu_link2" style="color:#a5a5a5;color:#a5a5a5"><table><tr><td style="width:20px;text-align:right"><span style="color:red">[вы]</span></td><td style="padding-left:6px"><span style="color:skyblue"><?=$user['login']?></span>, атакует <span style="color:khaki"><?=$object['login']?></span></td><td style="text-align:right"><?=n_f($object['hp'])?> <img src="http://213.239.195.28/xaos/style/heart.png" alt=""/></td></tr></table>


<?

  if($a_1 == true OR $a_2 == true OR $a_3 == true OR $a_4 == true OR $a_5 == true) {
  
?>

<div class="menu_link2">

<?

  if($a_1 == true) echo ' <img src=\'/images/ability/1.'.$user['ability_1_quality'].'.png\' width=\'25px\' height=\'25px\' alt=\'*\'/> ';
  if($a_2 == true) echo ' <img src=\'/images/ability/2.'.$user['ability_2_quality'].'.png\' width=\'25px\' height=\'25px\' alt=\'*\'/> ';
  if($a_3 == true) echo ' <img src=\'/images/ability/3.'.$user['ability_3_quality'].'.png\' width=\'25px\' height=\'25px\' alt=\'*\'/> ';
  if($a_4 == true) echo ' <img src=\'/images/ability/4.'.$user['ability_4_quality'].'.png\' width=\'25px\' height=\'25px\' alt=\'*\'/> ';
  if($a_5 == true) echo ' <img src=\'/images/ability/5.'.$user['ability_5_quality'].'.png\' width=\'25px\' height=\'25px\' alt=\'*\'/> ';

  }

?>

</div>

<?

  }

?>




</div>

<?

  }


  $count = mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_log` WHERE `battle` = "'.$battle['id'].'"'),0);

if($count > 0) {

?>


<div class="separ"></div><div class="menu_link2"><div class="menu_link3">


<?

$q = mysql_query('SELECT * FROM `coliseum_log` WHERE `battle` = "'.$battle['id'].'" ORDER BY `id` DESC LIMIT 15');

  while($row = mysql_fetch_array($q)) {

    if($row['user'] == $user['id'] && $row['show'] == $user['id'] OR $row['object'] == $user['id'] && $row['show'] == $user['id']) {
  
      echo '<font color=\'#'.($row['object'] == 0 ? 'ffffff':'c06060').'\'>'.$row['text'].'</font><br/>';
  
    }
    elseif($row['show'] == 0)
    {
    
    if($row['user'] == $user['id']) {
        

    }
    else
    {

    if($row['object'] == $user['id']) {
    
    }
    else
    {
    
      echo $row['text'].'<br/>';
  
    }
  
    }
  
    }

  }
  
?>

</div>

<?
  
  }

  if($member['dead'] == 0) {

?>

<div class="separ"></div><div class="jour2"><div class="jour" style="padding:4px;font-size:14px;text-align:center;color:#a5a5a5;border:1px solid #090909;border-radius:3px"><div style="font-size:14px;"><img src="http://213.239.195.28/xaos/16x16/time_go.png" alt=""/> Время: <span style="color:khaki">10:00</span> <img src="http://213.239.195.28/xaos/16x16/boxing_glove.png" alt=""/> Сила: <span style="color:red">100%</span> <img src="http://213.239.195.28/xaos/16x16/user_knight.png" alt=""/> Игроков: <span style="color:orange"><?=mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'"'),0)?> / 5</span></div></div></div><div class="separ2"></div><a href="/coliseum/?exit=true" class="menu_link"><img src="http://213.239.195.28/xaos/16x16/cross.png" alt=""/> Покинуть бой</a>  
</div>

<?

  }
  
  }
  else
  {

  if($member['exit'] == 0 && $battle['start'] == 1 && $battle['end'] == 1) {

$q = mysql_query('SELECT * FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'" ORDER BY `kills` DESC  LIMIT '.mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'"'),0).'');

  while($row = mysql_fetch_array($q)) {
  
  $i++;
  
  if($i == 1) {
    
    $best = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$row['user'].'"');
    $best = mysql_fetch_array($best);
  
  }
  
  if($row['user'] == $user['id']) {
  
      $place = $i;
  
  }

  }

    $_s = round(rand(1,180) + (150 / $place) + (130* $member['kills']));

  $_exp = round(rand(1,140) + (400 / $place) + (250 * $member['kills']));
    
    if($clan_memb && $clan_memb['v'] > 0) {
    
      $_exp += round($_exp/100) * $_clan_memb['v'];
    
    }

  if($premium) {
  
  $_exp+= round($_exp/ 150) * 250;
  
  }

  mysql_query('UPDATE `users` SET `s` =   `s` + '.$_s.',
                                `exp` = `exp` + '.$_exp.' WHERE `id` = "'.$user['id'].'"');


      if($clan) {
        
       mysql_query('UPDATE `clans`     SET `exp` = `exp` + '.$_exp.' WHERE `id` = "'.$clan['id'].'"');
       mysql_query('UPDATE `clan_memb` SET `exp` = `exp` + '.$_exp.' WHERE `clan` = "'.$clan['id'].'" AND `user` = "'.$user['id'].'"');

      }

    // Place
    // 6 - Колизей
    // Type
    // 0 - Провести бой
    // 1 - Убить n-е кол-во противников
    $q = mysql_query ('select * from `user_q` WHERE (`user`="' . $user['id'] . '") AND (`complete`="0")');
    if (mysql_num_rows ($q) != 0) {
        
        while ($user_q = mysql_fetch_array ($q)) {
                
            // 
            $q_ = mysql_query ('SELECT * FROM `quest` WHERE (`id`="' . $user_q['q'] . '")');
            $quest = mysql_fetch_array ($q_);
            
            if ($user_q['c']<$quest['c']) {
                
                if ($quest['place']=='6') {
                
                
                    if ($quest['type']=='0') {
                        mysql_query ('UPDATE `user_q` SET `c`=`c`+1 WHERE (`user`="' . $user['id'] . '") AND (`q`="' . $quest['id'] . '")');
                    }
                    if ($quest['type']=='1') {
                        if ($member['kills']>=$quest['c']) {
                            mysql_query ('UPDATE `user_q` SET `c`=`c`+' . ($member['kills']>$quest['c']?$quest['c']:$member['kills']) . ' WHERE (`user`="' . $user['id'] . '") AND (`q`="' . $quest['id'] . '")');
                        }
                    }            
                
                
                }
            
            }

        }

    }



?>


<?

$q = mysql_query('SELECT * FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'" ORDER BY `kills` DESC LIMIT '.mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'"'),0).'');

  while($row = mysql_fetch_array($q)) {

    $coliseum_user = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$row['user'].'"');
    $coliseum_user = mysql_fetch_array($coliseum_user);

  $_rating = 5 * $row['kills'];

  mysql_query('UPDATE `users` SET `coliseum_rating` = "'.($coliseum_user['coliseum_rating'] + $_rating).'" WHERE `id` = "'.$coliseum_user['id'].'"');

?>

  <div class='block'>
  
<div class="title-top">Бой окончен</div>
<div class="separ2"></div><div class="menu_link2" style="text-align:center"><img src="http://213.239.195.28/xaos/style2/astral_1.jpg" alt="" style="border:1px solid #131313;border-radius:3px"/></div><div class="separ"></div>
  
  <font color='#90b0c0'>Награда за <b><?=$place?></b> место:</font><br/>
  <img src="http://213.239.195.28/xaos/16x16/purse.png" alt=""/> <?=$_s?> монет <img src="http://213.239.195.28/xaos/icons/exp2.png" alt="" style="width:16px"/> <?=$_exp?> опыта
  


  <img src='/images/icon/premium.png' alt='*'/> <b>Лучший: <img src='/images/icon/race/<?=$best['r']?>.png' alt='*'/> <?=$best['login']?></b> <img src='/images/icon/premium.png' alt='*'/>
  <div class='separator'></div>
  <b>Итог боя:</b><br/>

<td style="padding-left:6px">
<span style="color:khaki"><a href='/user.php?id=<?=$coliseum_user['id']?>'><?=$coliseum_user['login']?></tr><?=$coliseum_user['level']?></a></span>

</td><td style="text-align:right">+<?=$_rating?><img src="http://213.239.195.28/xaos/16x16/medal_bronze_1.png" alt=""/>

<?

  }

?>

  </div>

<?

    mysql_query('UPDATE `coliseum_member` SET `exit` = "1" WHERE `battle` = "'.$battle['id'].'" AND `user` = "'.$user['id'].'"');
    
  }
  else
  {

?>


<?
  
  }


if(mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum` WHERE `start` = "0"'),0) == 0) {

  mysql_query('INSERT INTO `coliseum` (`start`,
                                         `end`,
                                        `time`) VALUES ("0",
                                                        "0",
                                        "'.(time() + 60).'")');

}

  $battle = mysql_query('SELECT * FROM `coliseum` WHERE `start` = "0"');
  $battle = mysql_fetch_array($battle);  

?>

</div></div><div class="title-top">Колизей</div>
<div class="separ2"></div><div style="text-align:center;padding:3px" class="menu_link2"><div style="border:1px solid #131313;padding:1px;background:#232323;border-radius:3px;display:inline-block"><img src="http://213.239.195.28/xaos/style2/duel_1.jpg" alt="" style="border:1px solid #1b1b1b;border-radius:3px;"/></div></div><div class="separ"></div>
<?


  if($_GET['exit'] == true && mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'"'),0) < 5) {

    mysql_query('DELETE FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'" AND `user` = "'.$user['id'].'"');
   
        header('location: /coliseum/');
    
    exit;

  }
  
  if(mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'"'),0) > 1) {
  
  if($battle['time'] > time()) {
  
?>
<div class="jour2"><div class="jour" style="color:#a5a5a5;text-align:center"><span style="font-size:16px">Следующий бой через <?=($battle['time'] - time())?> секунд.</span><div style="padding:3px"></div>
<?
  
  }
  else
  {

    mysql_query('UPDATE `coliseum` SET `start` = "1" WHERE `id` = "'.$battle['id'].'"');
  
  header('location: /coliseum/');
  
  }
  
  }
  else
  {
  
  if($battle['time'] < time()) {
  
    mysql_query('UPDATE `coliseum` SET `time` = "'.(time() + 60).'" WHERE `id` = "'.$battle['id'].'"');
  
  }
  
  }

?>

<center><div class="separ"></div><div class="menu_link3" style="text-align:center;font-size:16px;color:#a5a5a5"><a href='?' class='mybutt_att'>Обновить</a>
</div></div></center></div><div class="separ"></div><div class="menu_link3" style="text-align:center;font-size:16px;color:#a5a5a5">Ожидают бой <?=mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'"'),0)?> героев</div>
<?


?> 



<?

}

?>


<?
  

  }

?> 

<?

if(mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'"'),0) < 5 && mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'" AND `user` = "'.$user['id'].'"'),0) == 0) {

    if($user['hp'] > (($user['vit'] / 100) * 10) && $_GET['enter'] == true && mysql_result(mysql_query('SELECT COUNT(*) FROM `coliseum_member` WHERE `battle` = "'.$battle['id'].'"'),0) < 5) {
    
      mysql_query('INSERT INTO `coliseum_member` (`battle`,
                                                    `user`,
                                                    `time`) VALUES ("'.$battle['id'].'",
                                                                      "'.$user['id'].'",
                                                                           "'.time().'")');
    
        header('location: /coliseum/');
    
    exit;
    
   }

?>

<div class="separ"></div><div class="menu_link3" style="text-align:center;font-size:16px;color:#a5a5a5"><a href="?enter=true" class="mybutt_att"><img src="http://213.239.195.28/xaos/style2/dsword.png" alt=""/> Отправиться в Колизей!</a></div></div><div class="separ"></div></div>

<div class="separ"></div><div class="jour2"><div class="jour" style="color:#a5a5a5;text-align:center;font-size:16px;"></div></div></div><div class="separ"></div><div class="menu_link2"><img src="http://213.239.195.28/xaos/style2/dsword.png" alt=""/> <span style="color:khaki">Звание отсутствует</span>, <img src="http://213.239.195.28/xaos/16x16/medal_bronze_1.png" alt=""/> Рейтинг: <span style="color:khaki"><?=$user['coliseum_rating']?></span>, <img src="http://213.239.195.28/xaos/style2/dsword.png" alt=""/> Убито: <span style="color:khaki"><?=$member['kills']?></span></div><div class="separ3"></div></div></div>
<?

 }
 else
 {
 
?>


<?
 
 }
  
include './system/f.php';

?>