
<?php
include 'core/system.php';

reg();
head('Сражение Питомцев');


$pet=$dbc->query("SELECT * FROM `pet_tour` where `user_id`= '".$user['id']."' ")->fetch_assoc(); 


if($pet['war']==0){ header('location:index.php');exit;}





$dis = $pet['time'] - time(); 
if($pet['fin']==0){

$kom1=$dbc->query("SELECT * FROM `pet_tour` where `bitv`= '".$pet['bitv']."' AND `komand`=1 AND `dead` =1 ");

$kom2=$dbc->query("SELECT * FROM `pet_tour` where `bitv`= '".$pet['bitv']."' AND `komand`=2 AND `dead` =1 ");

$tix1  = $kom1->num_rows;
$tix2  = $kom2->num_rows;

if($tix1>=2){





$dbc->query("UPDATE `pet_tour` SET `fin`=1 WHERE `bitv`='".$pet['bitv']."'");

$dbc->query("delete from `pet_log` `bitv`='".$pet['bitv']."'");

$dbc->query("UPDATE `pet_tour` SET `win`=1 WHERE `bitv`='".$pet['bitv']."' AND `komand`=2 ");




$komn1=$dbc->query("SELECT * FROM `pet_tour` where `bitv`= '".$pet['bitv']."' AND `komand`=1 ");




while($inf1=$komn1->fetch_assoc()){ 



if($inf1['dead']==0){ $west = '<span class="info"><a href=pet.php?id='.$inf1['user_id'].'><span class="info">'.$inf1['name'].'</span></a>('.$inf1['login'].')['.$inf1['hp'].'/'.$inf1['max_hp'].']</span>';







}else{ $west = '<a href=pet.php?id='.$inf1['user_id'].'><font color="grey">'.$inf1['name'].'</a>('.$inf1['login'].')['.$inf1['hp'].'/'.$inf1['max_hp'].']</font>';}










$key1.="$west<br/>";



}



$sop ='<div class="b-panel-new dblue-panel bordered mt2">



<span class="iEpic">Команда 1</span>



<div class="panel-inner-2"><div class="font-small text-italic c-verygray"> '.$key1.'</div></div></div>';






$komn2=$dbc->query("SELECT * FROM `pet_tour` where `bitv`= '".$pet['bitv']."' AND `komand`=2 ");




while($inf2=$komn2->fetch_assoc()){ 



if($inf2['dead']==0){ $west2 = '<span class="info"><a href=pet.php?id='.$inf2['user_id'].'><span class="info">'.$inf2['name'].'</span></a>('.$inf2['login'].')['.$inf2['hp'].'/'.$inf2['max_hp'].']</span>';







}else{ $west2 = '<a href=pet.php?id='.$inf2['user_id'].'><font color="grey">'.$inf2['name'].'</a>('.$inf2['login'].')['.$inf2['hp'].'/'.$inf2['max_hp'].']</font>';}









$key2.="$west2<br/>";



}



$sop2 ='<div class="b-panel-new dblue-panel bordered mt2">

<span class="iEpic">Команда 2</span><span class="iLegendary">(Победители)+200 славы</span>

<div class="panel-inner-2"><div class="font-small text-italic c-verygray"> '.$key2.'</div></div></div>';




$sop.="$sop2";


















$sent = ("INSERT INTO `history_pet` (name,bitv) values('".$sop."','".$pet['bitv']."')"); 





$dbc->query($sent); 



//$dbc->query("INSERT INTO `history_pet` SET `text`='".$sop."', `bitv`='".$pet['bitv']."'"); 







}




if($tix2>=2){







$dbc->query("UPDATE `pet_tour` SET `fin`=1 WHERE `bitv`='".$pet['bitv']."'");



$dbc->query("UPDATE `pet_tour` SET `win`=1 WHERE `bitv`='".$pet['bitv']."' AND `komand`=1 ");









$komn1=$dbc->query("SELECT * FROM `pet_tour` where `bitv`= '".$pet['bitv']."' AND `komand`=1 ");




while($inf1=$komn1->fetch_assoc()){ 



if($inf1['dead']==0){ $west = '<span class="info"><a href=pet.php?id='.$inf1['user_id'].'><span class="info">'.$inf1['name'].'</span></a>('.$inf1['login'].')['.$inf1['hp'].'/'.$inf1['max_hp'].']</span>';







}else{ $west = '<a href=pet.php?id='.$inf1['user_id'].'><font color="grey">'.$inf1['name'].'</a>('.$inf1['login'].')['.$inf1['hp'].'/'.$inf1['max_hp'].']</font>';}










$key1.="$west<br/>";



}



$sop ='<div class="b-panel-new dblue-panel bordered mt2">

<span class="iEpic">Команда 1</span><span class="iLegendary">(Победители)+200 славы</span>

<div class="panel-inner-2"><div class="font-small text-italic c-verygray"> '.$key1.'</div></div></div>';




$komn2=$dbc->query("SELECT * FROM `pet_tour` where `bitv`= '".$pet['bitv']."' AND `komand`=2 ");




while($inf2=$komn2->fetch_assoc()){ 



if($inf2['dead']==0){ $west2 = '<span class="info"><a href=pet.php?id='.$inf2['user_id'].'><span class="info">'.$inf2['name'].'</span></a>('.$inf2['login'].')['.$inf2['hp'].'/'.$inf2['max_hp'].']</span>';







}else{ $west2 = '<a href=pet.php?id='.$inf2['user_id'].'><font color="grey">'.$inf2['name'].'</a>('.$inf2['login'].')['.$inf2['hp'].'/'.$inf2['max_hp'].']</font>';}










$key2.="$west2<br/>";



}



$sop2 ='<div class="b-panel-new dblue-panel bordered mt2">

<span class="iEpic">Команда 2</span>

<div class="panel-inner-2"><div class="font-small text-italic c-verygray"> '.$key2.'</div></div></div>';




$sop.="$sop2";















$sent = ("INSERT INTO `history_pet` (name,bitv) values('".$sop."','".$pet['bitv']."')"); 


$dbc->query($sent);







}



$dbc->query("delete from `pet_log` `bitv`='".$pet['bitv']."'");
}

$sav = 0;
if($pet['fin']==1){ header('location:pet_war.php?exit');}


$sel=$dbc->query("SELECT * FROM `pet_tour` where `bitv`= '".$pet['bitv']."' AND `komand`!='".$pet['komand']."' AND `hp`>0 "); 



if(Sec2Time($dis)>0){ ?><center><span class="info">До Следующего Удара <?=Sec2Time($dis)?></center><?}

while($sell=$sel->fetch_assoc()){  

?><a href="?id=<?=$sell['id']?><??>&amp;at" class="btn-aqua btn-potion"><img class="link-icon" src="/img/log/2.png" alt="" width="12" height="12"><span>Атаковать (<?=$sell['login']?>)<?=$sell['hp']?></a><?




$sav++;


}


if($sav == 0){ ?><center><a class="btn" href="pet_war.php?12">Покинуть Сражение</a></center><? }





































?><div class="b-panel-new dblue-panel bordered mt2"><?

?><span class="iEpic">Команда 1</span><?
?><div class="panel-inner-2"><div class="font-small text-italic c-verygray"><?

if(isset($_GET['exit'])){ 
if($pet['fin']==0){ header('location:pet_war.php');exit;}



if($pet['win']==1){ 

$stat=$dbc->query("SELECT * FROM `alien` where `id`= 1 ")->fetch_assoc();  


if($stat['limite']<50){

$dbc->query("UPDATE `users` SET `gold`=`gold`+1 WHERE `id`='".$user['id']."'");
$dbc->query("UPDATE `alien` SET `limite`=`limite`+1 WHERE `id`=1");}
$fix = mt_rand(200,200);



$dbc->query("UPDATE `user_pets` SET `slava`=`slava`+'".$fix."',`slava_total`=`slava_total`+'".$fix."',`tour`=`tour`+'".$fix."' WHERE `id_user`='".$user['id']."'"); }




$dbc->query("delete from `pet_tour` where `user_id` = '".$user['id']."'");


header('location:view_war.php?history');exit;


}
































































































































if(isset($_GET['at']) and !empty($_GET['id'])){
    $atak = int($_GET['id']);


if($pet['fin']==1){ header('location:pet_war.php');exit;}
if($pet['dead']==1){ header('location:pet_war.php');exit;}

If($pet['time']>time()){



header('location:pet_war.php');exit;}






$dbc->query('UPDATE `pet_tour` SET `time` = "' .(time() + 3) . '" WHERE `user_id` = "' . $user[id] . '"'); 


$bas=$dbc->query("SELECT * FROM `pet_tour` where `id`= '".$atak."'")->fetch_assoc(); 

if($bas['hp']<=0){ header('location:pet_war.php');exit;}
if($bas['bitv']!=$pet['bitv']){ header('location:pet_war.php');exit;}
if($bas['komand']==$pet['komand']){ header('location:pet_war.php');exit;}


$bay  = $pet['sila'];
$bb = mt_rand(1,100);
$crit = ($bb<=$pet['crit']) ? true : false;

 $infg  ='';
if($crit == 1){ $bay = $bay  * 1.5; $bay = ceil($bay); $infg="<span class=iEpic>(Крит)</span>"; }


if($bas['prot'] < 2000){ $brony=$bas['prot'] * 2 / 100;}elseif($bas['prot'] >= 2000){ $brony = 30;} 







$ket = $bay*$brony/100;
$des = $bay-$ket;


$des = floor($des);
$ys = mt_rand(40,60);


$des = $des+$ys;

$ma = '<img src="img/icons/pet.png"><font color=blueviolet><a href=pet.php?id='.$pet['user_id'].'> '.$pet['name'].'</a> >> <img src="img/icons/pet.png"><a href=pet.php?id='.$bas['user_id'].'>'.$bas['name'].' </a></font><font color=red>- '.$des.' </font>'.$infg.'';














if($des>=$bas['hp']){

$ma = '<img src="img/icons/pet.png"><font color=green> <a href=pet.php?id='.$pet['user_id'].'>'.$pet['name'].'</a> убил <img src="img/icons/pet.png"><a href=pet.php?id='.$bas['user_id'].'>'.$bas['name'].'</a></font>';








$dbc->query("UPDATE `pet_tour` SET `hp`=0,`dead`=1 WHERE `user_id`='".$bas['user_id']."'"); }else{
$dbc->query("UPDATE `pet_tour` SET `hp`=`hp`-".$des." WHERE `user_id`='".$bas['user_id']."'");

}






$dbc->query("INSERT INTO `pet_log` SET `bitv`='".$pet['bitv']."', text='$ma' ");












header('location:pet_war.php');exit;

}


$kom1=$dbc->query("SELECT * FROM `pet_tour` where `bitv`= '".$pet['bitv']."' AND `komand`=1 ");



while($inf1=$kom1->fetch_assoc()){ 


if($inf1['dead']==0){ $west = '<span class="info"><a href=pet.php?id='.$inf1['user_id'].'><span class="info">'.$inf1['name'].'</span></a>('.$inf1['login'].')['.$inf1['hp'].'/'.$inf1['max_hp'].']</span>';







}else{ $west = '<a href=pet.php?id='.$inf1['user_id'].'><font color="grey">'.$inf1['name'].'</a>('.$inf1['login'].')['.$inf1['hp'].'/'.$inf1['max_hp'].']</font>';}








?>

</br><?=$west?><? 

$key1.="$west<br/>";



}








?></div></div></div><?












?><div class="b-panel-new dblue-panel bordered mt2">
<span class="iEpic">Команда 2</span>

<div class="panel-inner-2"><div class="font-small text-italic c-verygray"><?

$kom2=$dbc->query("SELECT * FROM `pet_tour` where `bitv`= '".$pet['bitv']."' AND `komand`=2 ");



while($inf2=$kom2->fetch_assoc()){ 


if($inf2['dead']==0){ $west2 = '<span class="info"><a href=pet.php?id='.$inf2['user_id'].'><span class="info">'.$inf2['name'].'</span></a>('.$inf2['login'].')['.$inf2['hp'].'/'.$inf2['max_hp'].']</span>';







}else{ $west2 = '<a href=pet.php?id='.$inf2['user_id'].'<font color="grey">'.$inf2['name'].'</a>('.$inf2['login'].')['.$inf2['hp'].'/'.$inf2['max_hp'].']</font>';}







?>
</br><?=$west2?><? 





}












































































?><center><div class="b-notice trsmgr"><span class="red">Лог </span></div> </center><?







?><div class="b-panel-new dblue-panel bordered mt2">


<div class="panel-inner-2"><div class="font-small text-italic c-verygray"><?

$ful=$dbc->query("SELECT * FROM `pet_log` where `bitv`= '".$pet['bitv']."' order by `id` DESC LIMIT 10");




$infe = $ful->num_rows;


if($infe>0){ $des=''; }else{ $des='лог пуст';}



?><?=$des?><?




while($log=$ful->fetch_assoc()){ 


?></br><?=$log['text']?><? }













?></div></div></div><?









?></div></div></div><?






foot();
