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

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



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



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



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

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


if($pet){  

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


$mes= $mes->num_rows; 


if($mes>=2){ $dbc->query("update `pohod_pet` set `war` = 1 where `bitv` = '".$pet['bitv']."'");  





$opp = mt_rand(3,6);


 for ($x=0; $x<$opp; $x++){

$name = array('','Зловещая Тень','Мрачный Лорд','Темная Валькирия','
Ликан','Нетопырь','Демон');


$key = mt_rand(1,6);

    $sila = array (0,150,200,300,350,450,500);



    $brony = array (0,50,100,200,250,300,300);



    $hp = array (0,5000,7000,8000,9000,10000,10000);


$sila = $sila[$key];

$prot = $brony[$key];


$name = $name[$key];

$hp = $hp[$key];


;


$dbc->query("INSERT INTO `pohod_mob` (name,hp,max_hp,sila,prot,kil,test,mag,login,komand,bitv,war) values('".$name."','".$hp."','".$hp."','".$sila."','".$prot."',0,0,0, '".$user['login']."',1,'".$pet['bitv']."',0)");  


}

$dbc->query("UPDATE `pohod_pet` SET `opp`='".$opp."' WHERE `bitv`='".$pet['bitv']."'");  
$sql =$dbc->query("SELECT * FROM `pohod_pet` WHERE `bitv`='".$pet['bitv']."' AND `user_id`!='".$user['id']."'"); 






while($inf=$sql->fetch_assoc()){ 


$dbc->query("INSERT INTO `journal` SET `user_id`='".$inf['user_id']."', `text`='Сражение в Долине Мрака началось. <br><a id=\"link_button\" href=\"pohod_war.php\">В Бой</a>',





    `time`='".time()."'");
$dbc->query("UPDATE `users` SET `journal`=`journal`+1 WHERE `id`='".$inf['user_id']."'"); }





$dbc->query("update `alien` set `pohod_bitv` = `pohod_bitv`+1 "); header('location:pohod_war.php');exit;}



}


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




$sqll =$dbc->query("SELECT * FROM `history_pohod` order by `id` desc limit 3"); 





?><center><a href="pohod_start.php?go"><input class="btn big" type="submit" value="Записаться На Бой"></a></center><?



while($kub=$sqll->fetch_assoc()){ 
?><div class="page-title">Битва #<?=$kub['bitv']?></div><? 
 ?><?=$kub['name']?><?  }


foot(); exit;

























}


?><center><img src="img/new/doll.png" width="100%" height="120" alt="*"></center><?



if(!$pet){ 
?><div class="b-panel-new dblue-panel bordered mt2">
<center><div class="panel-inner-2"><div class="font-small text-italic c-verygray">Долина Мрака доступна с 35 уровня... для начала боя вам нужна книга познаний</div></div></div></center><?









?><center><a href="pohod_start.php?go"><input class="btn big" type="submit" value="Записаться На Бой"></a></center><? }else{










?><div class="b-panel-new dblue-panel bordered mt2">
<center><div class="panel-inner-2"><div class="font-small text-italic c-verygray">Собрано <?=$mes?>/2</div></div></div></center><?







  ?><center><a href="pohod_start.php?"><input class="btn big" type="submit" value="Обновить"></a></center><? }



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

if($dop['saga_boi']<=0){ $_SESSION['message']='<center>У вас нет Книги Познаний</center>'; header('location: pohod_start.php');exit;} 


//if($user['level']<25){ header('location:view_war.php');exit;}




if($pet){ header('location:pohod_start.php');exit;}




$my = $dbc->query("SELECT * FROM `user_pets` WHERE `id_user` = '".$user['id']."'")->fetch_assoc(); $next = $pet['str'];  

if(!$my){ header('location:pohod_start.php');exit;}

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

$nix = $my['vit']*5;


$dbc->query("INSERT INTO `pohod_pet` (user_id,pet_id,uron,name,hp,max_hp,sila,prot,kil,test,mag,login,komand,bitv,war,img,crit) values('".$user['id']."','".$my['id_pets']."',0,'".$my['name']."','".$nix."','".$nix."','".$my['str']."','".$my['def']."',0,0,0, '".$user['login']."',1,'".$stat['pohod_bitv']."',0,'".$my['img']."','".$my['crit']."')"); 











$dbc->query("update `dop` set `saga_boi`=`saga_boi`-1 where `user`='".$user['id']."' ");    
























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








}








?><a class="btn" href="pohod_start.php?history">История Сражений</a><?

include 'next_pet.php';
foot(); 

