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

reg();
head('Долина Мрака');


?><style>  .gg {

background: #3d3d3d;
width: 30px;



height: 30px;



margin: 0 auto;
line-height: 200px;
color: #fff;
font-size: 1.2em;
border-radius: 50%;
position: relative;
cursor: pointer;
text-align: center;
text-shadow: 1px 1px 1px #222;
} </style><? 

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


$wex = $pet['opp'];

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





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

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


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


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

if($tix1>=2){





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


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


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





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





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



if($inf1['dead']==0){ $west = '<img src='.$inf1['img'].' class="i100 ar_brd"><span class="info"><a href=pet.php?id='.$inf1['user_id'].'><span class="info">'.$inf1['name'].'</span></a>('.$inf1['login'].')  <img src=/img/stat/hp.png>'.$inf1['hp'].' <img src=/img/new/otr.png>'.$inf1['bon_snap'].'%  <img src=/img/stat/AKulak.png>+'.$inf1['bon_sila'].' <img src=/img/log/2.png>'.$inf1['damage'].' <img src=/img/icon/sk.png>'.$inf1['kil'].'</span>'; 








}else{ $west = '<img src='.$inf1['img'].' class="i100 ar_brd"><span class="info"><a href=pet.php?id='.$inf1['user_id'].'><span class="info">'.$inf1['name'].'</span></a>('.$inf1['login'].')  <font color=red>(Мёртв)</font><img src=/img/new/otr.png>'.$inf1['bon_snap'].'%  <img src=/img/stat/AKulak.png>+'.$inf1['bon_sila'].' <img src=/img/log/2.png>'.$inf1['damage'].' <img src=/img/icon/sk.png>'.$inf1['kil'].'</span>';}













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



}



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



<span class="iEpic">Питомцы</span>




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






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





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['hp'].'/'.$inf2['max_hp'].']</span>';








}else{ $west2 = '<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">Монстры</span><span class="iLegendary">(Победители)</span>


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




$sop.="$sop2";


















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






$dbc->query($sent); 



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







}




if($tix2>=$wex){






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




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










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





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


$hh = $inf1['kil']*5;



$gg = 50+$hh;



if($inf1['dead']==0){ $west = '<img src='.$inf1['img'].' class="i100 ar_brd">

<span class="info"><a href=pet.php?id='.$inf1['user_id'].'><span class="info">'.$inf1['name'].'</span></a>('.$inf1['login'].') 
 <img src=/img/stat/hp.png>'.$inf1['hp'].' <img src=/img/new/otr.png>'.$inf1['bon_snap'].'%  <img src=/img/stat/AKulak.png>+'.$inf1['bon_sila'].' <img src=/img/log/2.png>'.$inf1['damage'].' <img src=/img/icon/sk.png>'.$inf1['kil'].'</span> награда :<img src=/img/money/rubin.png>'.$gg.' слава +500'; 









}else{ $west = '<img src='.$inf1['img'].'  class="i100 ar_brd">
<span class="info"><a href=pet.php?id='.$inf1['user_id'].'><span class="info">'.$inf1['name'].'</span></a>('.$inf1['login'].')  <font color=red>(Мёртв)</font><img src=/img/new/otr.png>'.$inf1['bon_snap'].'%  <img src=/img/stat/AKulak.png>+'.$inf1['bon_sila'].' <img src=/img/log/2.png>'.$inf1['damage'].' <img src=/img/icon/sk.png>'.$inf1['kil'].'</span> награда :<img src=/img/money/rubin.png>'.$gg.' слава +500';}














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



}



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

<span class="iEpic">Питомцы</span><span class="iLegendary">(Победители)</span>



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




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





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



if($inf2['dead']==0){ $west2 = '<span class="info"><span class="info">'.$inf2['name'].'</span></a>['.$inf2['hp'].'/'.$inf2['max_hp'].']</span>';








}else{ $west2 = '<font color="grey">'.$inf2['name'].'</a>['.$inf2['hp'].'/'.$inf2['max_hp'].']</font>';}











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



}



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

<span class="iEpic">Монстры</span>


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




$sop.="$sop2";














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



$dbc->query($sent);







}



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

}

if($pet['fin']==0){
    
    ?>   <div class="form-field"> <form method='post' action='pohod_war.php'><select name="enemy"><?






$kom2=$dbc->query("SELECT * FROM `pohod_mob` where `bitv`= '".$pet['bitv']."' and `hp`>0");





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

?><option value=<?=$inf2['id']?>><?=$inf2['name']?>(<?=$inf2['hp']?>)</option><?








}
?>
</select></div><?


    
?><div class="form-submit mt5"><input class="btn" name="p::submit" id="id4" value="Атаковать" type="submit"></form></div><?



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



}else{



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


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



?><center><span class="info">Сражение Окончено</span></center><?
if($kos){ ?><center><span class="info">Победила Команда 1</span></center><?}
if($koa){ ?><center><span class="info">Победила Команда 2</span></center><?}




?><center><a href="pohod_war.php?exit"><input class="btn big" type="submit" value="Покинуть Сражение"></a></center><?








}

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



?><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(500,500);





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


$hh = $pet['kil']*5;

$gg = 50+$hh;




$dbc->query("UPDATE `users` SET `rub`=`rub`+'".$gg."' WHERE `id`='".$user['id']."'");


}



















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



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



}












if(isset($_POST['enemy'])){


$pers = int($_POST['enemy']);




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

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


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



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







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



$bas=$dbc->query("SELECT * FROM `pohod_mob` where `bitv`= '".$pet['bitv']."' AND `id` = '".$pers."'")->fetch_assoc(); 


$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['hp']<=0){ header('location:pohod_war.php');exit;}

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; 


$des = $des+$pet['bon_sila'];







$wow = array('ударил','укусил','ранил');
shuffle($wow);
$ma = '<img src="img/icons/pet.png"><font color=blueviolet><a href=pet.php?id='.$pet['user_id'].'> '.$pet['name'].'</a> '.$wow[0].' <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 `pohod_mob` SET `hp`=0,`dead`=1 WHERE `id`='".$bas['id']."'"); 

$dbc->query("UPDATE `pohod_pet` SET `damage`=`damage`+".$des." ,`kil`=`kil`+1 WHERE `id`='".$pet['id']."'");



}else{


$dbc->query("UPDATE `pohod_mob` SET `hp`=`hp`-".$des." WHERE `id`='".$bas['id']."'");

$dbc->query("UPDATE `pohod_pet` SET `damage`=`damage`+".$des." WHERE `id`='".$pet['id']."'");

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

$bay  = $bas['sila'];



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


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


$desi = $des+$ys;




$rand_bon = mt_rand(1,15);






if($rand_bon == 6){  $masy = '<img src="img/icons/pet.png"><font color=lime>'.$pet['name'].' Нашел Куб Силы</font>';




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


$dbc->query("UPDATE `pohod_pet` SET `bon_sila`=`bon_sila`+50 WHERE `id`='".$pet['id']."'"); 


}


$dbc->query("UPDATE `pohod_pet` SET `hp`=`hp`-".$desi." WHERE `id`='".$pet['id']."'");

$mas = '<img src="img/icons/pet.png"><font color=red>'.$bas['name'].'</a> ударил в ответ <img src="img/icons/pet.png"><a href=pet.php?id='.$pet['user_id'].'>'.$pet['name'].' </a></font><font color=green>- '.$desi.' </font>';


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

$life  = $pet['hp']-$desi;


if($life<=0){








$dbc->query("UPDATE `pohod_pet` SET `hp`=0,`dead`=1 WHERE `id`='".$pet['id']."'"); }  


}






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













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


}




   





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




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


if($inf1['dead']==0){ $west = '<img src='.$inf1['img'].' class="i100 ar_brd"><span class="info"><a href=pet.php?id='.$inf1['user_id'].'><span class="info">'.$inf1['name'].'</span></a>('.$inf1['login'].')  <img src=/img/stat/hp.png>'.$inf1['hp'].' <img src=/img/new/otr.png>'.$inf1['bon_snap'].'%  <img src=/img/stat/AKulak.png>+'.$inf1['bon_sila'].' <img src=/img/log/2.png>'.$inf1['damage'].' <img src=/img/icon/sk.png>'.$inf1['kil'].'</span>';


















}else{ $west = '<img src='.$inf1['img'].' class="i100 ar_brd"><span class="info"><a href=pet.php?id='.$inf1['user_id'].'><span class="info">'.$inf1['name'].'</span></a>('.$inf1['login'].')  <font color=red>(Мёртв)</font><img src=/img/new/otr.png>'.$inf1['bon_snap'].'%  <img src=/img/stat/AKulak.png>+'.$inf1['bon_sila'].' <img src=/img/log/2.png>'.$inf1['damage'].' <img src=/img/icon/sk.png>'.$inf1['kil'].'</span>';}









?>

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

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



}








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












?><div class="b-panel-new dblue-panel bordered mt2">
<span class="iEpic">Монстры</span>


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

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




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


if($inf2['dead']==0){ $west2 = '<span class="info"><span class="info">'.$inf2['name'].'</span> ['.$inf2['hp'].'/'.$inf2['max_hp'].']</span>';












}else{ $west2 = '<font color="grey">'.$inf2['name'].' ['.$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 `pohod_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><?

?><?=$_POST['enemy']?><?

foot();
