<?

if(empty($conf['battle_arena']) AND empty($conf['battle_result'])){header("Location: /arena");exit;}
if(empty($conf['battle_result']) AND isset($_GET['result'])){header("Location: /arena");exit;}
if(isset($_GET['tomato'])){
$tomato = intval($_GET['tomato']);
$fruts=unserialize($conf['battle_plant_atak']);
if (in_array("$tomato", $fruts))mysql_query("UPDATE `kolhoz_setting` SET `battle_tomato`='$tomato' WHERE `id_user`='$ku[id]' LIMIT 1");
header("Location: /arena/list/".passgen());
exit;
}
if(!isset($_GET['result'])){
require_header ('Бой');
echo'<div class="content">
<div class="block">';

$sharkms=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective_heli` WHERE `id_collective` = '$mc[id]' AND `heli` = '5'"));
echo''.(isset($sharkms['id'])?'<img width="16" height="16" alt="o" src="/images/icons/heli5n.png"/>
'.($ku['time_shark']<$time?'<a href="/arena/shark">Вызвать</a>':'<span class="epic">Акула </span><span class="minor">'.(time_left($ku['time_shark']-$time)).' (сила овощей +10%)</span>').'':null).'


<div>
<img width="16" height="16" src="/images/icons/refresh.png" alt="*"/>
<a href="/arena/list/reflesh/'.(rand(1000000,9999999)).'">Обновить</a><span class="minor"></span>
</div>';
////////////////////Ataka
include_once 'inc/arena_list_ataka.php';
//////////////////////////////////
$i=0;
While($i<count($fruts)){
$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '$fruts[$i]'"));
if($fruts_kol[$i]>0)echo '<li><img width="16" height="16" src="/images/icons/tomato.png" alt="*"/> '.($conf['battle_tomato']!==$plant['id']?'<a class="line" href="/arena/list/tomato-'.$plant['id'].'"><span >Использовать '.(!empty($plant['tname'])?''.$plant['tname'].'':''.$plant['name'].'').'</span></a>':'<span >Использовать '.(!empty($plant['tname'])?''.$plant['tname'].'':''.$plant['name'].'').'</span>').'<span class="title"> ('.$fruts_kol[''.$i.''].')</span></li>';
$i++;
}
echo'<div class="pt"></div>Моя команда: ';
echo " ".on_k($ku['id'])." <a class='' href='/user/$ku[id]'><span>".nc($ku['id'])."</span></a><span class='info'> ($conf[battle_hp])</span></br>Противники:";
$prot=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_setting` WHERE `battle_arena` = '$conf[battle_arena]' AND `id_user`!='$ku[id]'"));
echo " ".on_k($prot['id_user'])." <a class='' href='/user/$prot[id_user]'><span>".nc($prot['id_user'])."</span></a><span class='info'> ($prot[battle_hp])</span></br>";
}else{
require_header ('Бой');
echo'<div class="content">
<div class="block">';
echo'<h3>Бой окончен</h3>
<div>
<div>'.($conf['battle_result']=='lose'?'<span class="major">Вы проиграли!':''.($conf['battle_result']=='drawn'?'<span class="title">Ничья!':'<span class="info">Вы победили!').'').'</span></div>
<div>Ваш рейтинг: <span class="info">'.$ku['arena_rating'].'</span><span class="title"> ('.($conf['battle_result']=='lose'?'-':'+').''.$conf['battle_exit_rate'].')</span></div>';
if($conf['battle_result']=='win'){
if($ku['level']>=20)$exp=1;
if($ku['level']>=35)$exp=2;
if($ku['level']>=45)$exp=3;
echo '<div>Боевой опыт: <span class="info">'.$conf['arena_exp'].'</span><span class="title"> (+'.$exp.')</span></div>
';
}
echo'<div><img width="16" height="16" src="/images/icons/tomato.png" alt="*"/> <a href="/arena/bitva/no_rate">Играть еще</a></div>
<div><img width="16" height="16" src="/images/icons/chat.png" alt="*"/> <a href="/chat-3235">Обсудить в чате</a></div>
<div><img width="16" height="16" src="/images/icons/back.png" alt="*"/> <a href="/arena/exit">Выход</a></div>
</div>';
}
if(!isset($aren)){
$ar = mysql_fetch_array(mysql_query("SELECT `id_arena` FROM `kolhoz_arena_log` WHERE `id_user`='$ku[id]' ORDER by `time` DESC LIMIT 1"));
if(!empty($ar['id_arena']))$aren=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_arena_batle` WHERE `id` = '$ar[id_arena]'"));
}
if(isset($aren)){
echo'<h3>События</h3>';
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_arena_log` WHERE ".(!isset($_GET['result'])?"`id_arena` = '$conf[battle_arena]' AND ":null)." (`id_user`='$ku[id]' OR `id_who`='$ku[id]')"),0);
if ($k_post==0)
{
if($aren['time']-$time+15==1)$sloy = 'секунду';
elseif($aren['time']-$time+15>=2 AND $aren['time']-$time+15<=4)$sloy = 'секунды';
else $sloy = 'секунд';
echo "<span class='minor'>Бой начнется через ".($aren['time']-$time+15)." $sloy...</span>";
}
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `kolhoz_arena_log` WHERE ".(!isset($_GET['result'])?"`id_arena` = '$conf[battle_arena]' AND ":null)."(`id_user`='$ku[id]' OR `id_who`='$ku[id]') ORDER by `time` DESC LIMIT $start, $set[p_str]");

echo "<ul>";
if($page==1)$i=1;else$i=($page-1)*$set['p_str']+1;
while($post=mysql_fetch_array($q))
{
if($post['id_user']==$ku['id']){ 
$span='rare'; 
$oponame=mysql_fetch_array(mysql_query("SELECT `nick`,`pol` FROM `kolhoz_user` WHERE `id`='$post[id_who]'"));
$plantname=mysql_fetch_array(mysql_query("SELECT `name`,`last_name` FROM `kolhoz_plant` WHERE `id`='$post[plant]'"));
if($post['type']==1){$msg='Я бросил'.($ku['pol']==0?'а':null).' в <em>'.$oponame[0].'</em> '.(!empty($plantname[1])?''.$plantname[1].'':''.$plantname[0].'').' -'.$post['sila'].'';}
if($post['type']==2){$msg='Я отбил'.($ku['pol']==0?'а':null).' щитом часть овощей и попал'.($ku['pol']==0?'а':null).' в  <em>'.$oponame[0].'</em> '.(!empty($plantname[1])?''.$plantname[1].'':''.$plantname[0].'').' -'.$post['sila'].'';}
if($post['type']==3){
if($post['id_who']==$ku['id']){$span='info'; $msg = 'Я исцелил'.($ku['pol']==0?'а':null).' себя '.(!empty($plantname[1])?''.$plantname[1].'':''.$plantname[0].'').' +'.$post['sila'].'';}else{
$span='title'; $msg = 'Я исцелил'.($ku['pol']==0?'а':null).' <em>'.$oponame[0].'</em> '.(!empty($plantname[1])?''.$plantname[1].'':''.$plantname[0].'').' +'.$post['sila'].'';}
}
 }else{ 
$span='major';
$oponame=mysql_fetch_array(mysql_query("SELECT `nick`,`pol` FROM `kolhoz_user` WHERE `id`='$post[id_user]'"));
$plantname=mysql_fetch_array(mysql_query("SELECT `name`,`last_name` FROM `kolhoz_plant` WHERE `id`='$post[plant]'")); 
if($post['type']==1){$msg='<em>'.$oponame[0].'</em> бросил'.($oponame[1]==0?'а':null).' в меня '.(!empty($plantname[1])?''.$plantname[1].'':''.$plantname[0].'').' -'.$post['sila'].'';}
if($post['type']==2){$msg='<em>'.$oponame[0].'</em> отбил'.($oponame[1]==0?'а':null).' щитом часть овощей и попал'.($oponame[1]==0?'а':null).' в меня '.(!empty($plantname[1])?''.$plantname[1].'':''.$plantname[0].'').' -'.$post['sila'].'';}
if($post['type']==3){$span='info'; $msg = '<em>'.$oponame[0].'</em> исцелил'.($oponame[1]==0?'а':null).' меня '.(!empty($plantname[1])?''.$plantname[1].'':''.$plantname[0].'').' +'.$post['sila'].'';}
}
if($post['krit']==1)$krit='<img width="16" height="16" src="/images/icons/lightning.png" alt="!"/>'; else $krit='';
echo "<span class='$span'>$krit $msg</span> <span class='minor'>(".time_left($time-$post['time'])." назад)</span> <br/>";
}
echo "</ul>";
if ($k_page>1){echo'<ul class="pt"></ul>'; new_str("arena/list/".(isset($_GET['result'])?"result/":null)."",$k_page,$page);} // Вывод страниц
}
echo'<li class="pt"><span class="minor">Мои способности:</span>
<span>
<img width="16" height="16" src="/images/icons/sword.png" alt="Мощн" title="Мощн"/>&nbsp;<span class="title">'.$conf['arena_sila'].'</span>&nbsp;
</span><span>
<img width="16" height="16" src="/images/icons/heart.png" alt="Жив" title="Жив"/>&nbsp;<span class="title">'.$conf['arena_hp'].'</span>&nbsp;
</span><span>
<img width="16" height="16" src="/images/icons/lightning.png" alt="Крит" title="Крит"/>&nbsp;<span class="title">'.$conf['arena_kr'].'</span>&nbsp;
</span><span>
<img width="16" height="16" src="/images/icons/shield.png" alt="Защита" title="Защита"/>&nbsp;<span class="title">'.$conf['arena_body'].'</span>&nbsp;
</span><span>
<img width="16" height="16" src="/images/icons/money.png" alt="Эконом" title="Эконом"/>&nbsp;<span class="title">'.$conf['arena_econom'].'</span>&nbsp;
</span>
</span></li>';
include_once 'inc/foot.php';
?>