<?php

include_once 'core/class.php';
require_once 'core/system.php';








head('Подземелье');







reg();

if($user['id']==1){ $bim = 70000; }else{ $bim =0;}
$weapo = $user['strength']+$user['dobav'];

$weapo = $weapo+$bim;


$bum = 5;
$param = new param;











$intro = $param->udar($weapo,$bum,$user['crit'],$user['sokru']);







list($weapon,$crit,$sokru) = $intro;










$plazma = $user['strength']+$user['dobav'];

$messi = ($crit==1) ? '<font color=red>(крит)</font>' : '';


$am1_time = $user['am1_time'] -time();
$am2_time = $user['am2_time'] -time();
$apteka_time = $user['apteka_t'] -time();

if($user['s_pet']==1){

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


$rast = ($next>0 and $pet['spec']==2) ? $next : 0 ;

























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



$clan_id = $clan['id'];

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

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



if($banda['priz']==0){

if($banda['dung']==1){  $dbc->query("UPDATE `dop` SET `dung1`='".(time() +18000)."' WHERE `banda`='".$user['banda']."'"); }


if($banda['dung']==2){  $dbc->query("UPDATE `dop` SET `dung2`='".(time() +22000)."' WHERE `banda`='".$user['banda']."'"); }
 

if($banda['dung']==3){  $dbc->query("UPDATE `dop` SET `dung3`='".(time() +32000)."' WHERE `banda`='".$user['banda']."'"); }


if($banda['dung']==4){  $dbc->query("UPDATE `dop` SET `dung4`='".(time() +86400)."' WHERE `banda`='".$user['banda']."'"); }





}









$dbc->query("UPDATE `users` SET `banda`=0 WHERE `id`='".$user['id']."'");
$dbc->query("UPDATE `dop` SET `banda`=0 WHERE `user`='".$user['id']."'");


$dbc->query("UPDATE `banda` SET `lim`=`lim`-1 WHERE `id`='".$user['banda']."'");



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


} 


if($banda['dung']==1){
$inf = array('','Прислужник','Страх','Злобный Дух','Призрак Мага');



    $sila = array (0,150,200,200,250,250,1000);



    $brony = array (0,50,50,100,100,150,1000);



    $hp = array (0,10000,15000,20000,20000,25000,1000);











}

if($banda['dung']==2){
$inf = array('','Гоблин','Гоблин Страж','Чума Болот','Сабр','Владыка Болот');




    $sila = array (0,350,450,500,600,800,1000);


    $brony = array (0,150,250,300,350,400,1000);


    $hp = array (0,50000,60000,75000,75000,85000,95000);












} 

if($banda['dung']==3){
$inf = array('','Демоническая Химера','Лорд Заргуб','Хранитель Времени','Дракон');



    $sila = array (0,550,600,800,950,950,1000);




    $brony = array (0,300,400,500,550,500,1000);




    $hp = array (0,40000,55000,70000,80000,75000,1000);












} 
if($banda['dung']==4){
$inf = array('','Кровавый Архимаг','Хранитель Мрака');




    $sila = array (0,900,1500,800,950,950,1000);




    $brony = array (0,400,600,500,550,500,1000);




    $hp = array (0,120000,120000,70000,80000,75000,1000);}



$sila = $sila[$banda['etap']];

$prot = $brony[$banda['etap']];


$name = $inf[$banda['etap']];
$hp = $hp[$banda['etap']];

    if($banda['priz']==1){


if($banda['tip']==1){

$igro=$dbc->query("SELECT * FROM `users` where `id`= '".$banda['use']."' ")->fetch_assoc();  
$it=$dbc->query("SELECT * FROM `dung_item` where `id`= '".$banda['item']."' ")->fetch_assoc();  

?><center><img src="img/sob/dung.jpg" width="100%" height="120" alt="*"></center>





<div class="b-panel-new dblue-panel bordered mt2"><div class="panel-inner-2"><center>Победитель  <a href="/pers.php?ank=<?=$igro['id']?>"> <img src="img/class/<?=$igro['storona']?>/<?=$igro['pers']?>/pers.png" width="13" height="13" alt="*"><?=$igro['login']?></a> Награда <a href="dung_item.php?ids=<?=$it['id']?>" class="<?=$it['lite']?>"><?=$it['nik']?></a></center></div></div><?

}

if($banda['tip']==2){

$igro=$dbc->query("SELECT * FROM `users` where `id`= '".$banda['use']."' ")->fetch_assoc();  
?><center><img src="img/sob/dung.jpg" width="100%" height="120" alt="*"></center>

<div class="b-panel-new dblue-panel bordered mt2"><div class="panel-inner-2"><center>Победитель  <a href="/pers.php?ank=<?=$igro['id']?>"> <img src="img/class/<?=$igro['storona']?>/<?=$igro['pers']?>/pers.png" width="13" height="13" alt="*"><?=$igro['login']?></a> Награда <?=$banda['info']?></center></div></div><?






}

?><center><a href="dung_war.php?exit"><input class="btn big" type="submit" value="Покинуть Бой "></a></center><?








    foot();
    exit;
    }
function dead_bos(){
global $user;
global $dbc;

global $banda;
global $hp;



if($banda['etap']<$banda['max_etap']){



$dbc->query("UPDATE `banda` SET `hp`='".$hp."', `etap`=`etap`+1 WHERE `id`='".$user['banda']."'"); header('location:dung_war.php');exit;}






$ger = $dbc->query("SELECT * FROM `users` where `banda` ='".$user['banda']."' ORDER BY RAND() LIMIT 1 ")->fetch_assoc();


$pers = $ger['id'];


if($banda['tip']==1){ 
$shmot = $dbc->query("SELECT * FROM `dung_item` where `class`='".$ger['pers']."' and `dung` = '".$banda['dung']."' ORDER BY RAND() LIMIT 1 ")->fetch_assoc();




$dbc->query("INSERT INTO `artefact` (user_id,status,nik,strong,hp,prot,crit,regen,level,tip,class,lite,coin,img) values('".$ger['id']."','".$shmot['status']."','".$shmot['nik']."','".$shmot['strong']."','".$shmot['hp']."','".$shmot['prot']."','".$shmot['crit']."','".$shmot['regen']."','".$shmot['level']."','".$shmot['tip']."','".$shmot['class']."','".$shmot['lite']."','".$shmot['coin']."','".$shmot['img']."')");




$last = $dbc->insert_id;

}


$kuz = mt_rand(1,4); 
if($banda['tip']==2){ 


if($kuz==1){



$info = '<img src=/img/res/mag.png>4';

$dbc->query("UPDATE `banda` SET `info`='".$info."' WHERE `id`='".$user['banda']."'");
$dbc->query("UPDATE `dop` SET `kam`=`kam`+4 WHERE `user`='".$pers."'");



}

if($kuz==2){



$info = '<img src=/img/res/med.png>10';

$dbc->query("UPDATE `banda` SET `info`='".$info."' WHERE `id`='".$user['banda']."'");
$dbc->query("UPDATE `dop` SET `med`=`med`+10 WHERE `user`='".$pers."'");



} 



if($kuz==3){



$info = '<img src=/img/res/min.png>25';

$dbc->query("UPDATE `banda` SET `info`='".$info."' WHERE `id`='".$user['banda']."'");
$dbc->query("UPDATE `dop` SET `min`=`min`+25 WHERE `user`='".$pers."'");



} 


if($kuz==4){



$info = 'Свиток Охотника 3';

$dbc->query("UPDATE `banda` SET `info`='".$info."' WHERE `id`='".$user['banda']."'");
$dbc->query("UPDATE `dop` SET `boi`=`boi`+3 WHERE `user`='".$pers."'");



} 




}








    

$dbc->query("UPDATE `banda` SET `priz`=1,`item`='".$shmot['id']."',`use`='".$ger['id']."' WHERE `id`='".$user['banda']."'");



$dbc->query("UPDATE `users` SET `serebro`=`serebro`+2000 WHERE `banda`='".$user['banda']."'");



if($banda['dung']==1){  $dbc->query("UPDATE `dop` SET `dung1`='".(time() +18000)."' WHERE `banda`='".$user['banda']."'"); }

if($banda['dung']==2){  $dbc->query("UPDATE `dop` SET `dung2`='".(time() +22000)."' WHERE `banda`='".$user['banda']."'"); }

if($banda['dung']==3){  $dbc->query("UPDATE `dop` SET `dung3`='".(time() +22000)."' WHERE `banda`='".$user['banda']."'"); }


if($banda['dung']==4){  $dbc->query("UPDATE `dop` SET `dung4`='".(time() +86400)."' WHERE `banda`='".$user['banda']."'"); }

            




                
$gold = $clan['level']*2;
$sera = 5000;




                






                
//$dbc->query("UPDATE `clan` SET `ob_hp`=0,`kazna`=`kazna`+'".$gold."',`sera`=`sera`+'".$sera."' WHERE `id`='".$user['clan']."'");



//$dbc->query("INSERT INTO `clan_stena` SET `clan_id`='".$clan['id']."', `user_id`='".$user['id']."', `text`='<span class=info>Оборотень убит, награда в казну клана <img src=\"img/money/money.png\">".$gold."  <img src=\"img/stat/sera.png\"> ".$sera."!</span>',        `time`='".time()."'");





                





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


}




/////Элексир
    if(isset($_GET['el'])){
                if ($user['apteka_t'] > time()) {   
header('location:dung_war.php');exit;}



If($user['apteka']<=0){
$loki = '<font color=grey> У вас нет зелий</font>'; 


 $_SESSION['logi']="$loki";  header('location:dung_war.php');exit;}else{





$min = '<font color=green> Вы использовали зелье, здоровье восстановлено</font>'; 



$_SESSION['logi']="$min";


$dbc->query("UPDATE `users` SET `health`='".$user['max_health']."',`apteka_t` = '" .
(time() + 40) . "' ,`apteka`=`apteka`-1 WHERE `id`='".$user['id']."'");header('location:dung_war.php');exit;}}







/////////Простой Удар

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



If($user['udar']>time()){
$loki = '<font color=grey> Промах!</font>'; 

$_SESSION['logi']="$loki"; header('location:dung_war.php');exit;}





$lolvamp = mt_rand(1,100);
$lolpet = mt_rand(1,100);

$hill = $user['strength'] * $user['vampir'] / 100; $hill = ceil($hill);



$hill = ($lolvamp<=20) ? $hill : 0;








$last_pet = ($lolpet<=25) ? $pet['str'] : 0;




$conf=$hill+$last_pet;



$conf=$conf+$user['health']; 


$itog = ($conf>=$user['max_health']) ? $user['max_health'] : $conf; 













$ma = ($lolvamp<=20) ? ' ,похитив '.$hill.' здоровья' : '';



if($user['health']<$user['max_health'] and $lolpet<=25 || $lolvamp<=20){






$dbc->query('UPDATE `users` SET `health` = "' .$itog. '" WHERE `id` = "' . $user[id] . '"'); }


$rix = 50+$prot;
$vi ='';
$re = $weapon;
$re = $re - $rix;

$weapon = ($re>0) ? $re : 1;

$wep = $weapon;
if($lolpet<=25 and $pet['spec']==1){

$vi = '</br><font color=green>Ваш питомец '.$pet[name].' зацепил '.$name.'  на  '.$pet['str'].'</font>'; $weapon = $weapon+$pet['str']; }







if ($weapon >= $banda['hp']) {



Oput($weapon);
$_SESSION['logi']='Вы убили '.$name.'';
dead_bos(); }

else{
$dbc->query("UPDATE `banda` SET `hp`=`hp`-".$weapon." WHERE `id`='".$user['banda']."'");


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

$maxty = ($sokru==1) ? 'Сокрушил' : Ударил;


$suk = '<font color=green> Ты '.$maxty.' '.$name.' на  '.$wep.' '.$messi.'</font>'.$ma.''; }






If($user['s_pet']==1 and $user['health']<$user['max_health'] and $lolpet<=25){



If($pet['spec']==2){ 



$vi = '</br><font color=lime> '.$pet['name'].' Исцелил тебя на  '.$last_pet.'</font>'; 











}}

Oput($weapon);


$mob_udar = mt_rand(1,2);


$tf = 100; 
$tf = $tf+$sila;


$tf = $tf - $user['defense'];
$mob_uron = ($tf>0) ? $tf : 0;





if($mob_udar == 2){
$wow = array('ударил','укусил','ранил');
shuffle($wow);
$tanki = '</br><font color=red> '.$name.' '.$wow[0].' тебя на  '.$mob_uron.'</font>'; 




if($mob_uron>0){
                if ($mob_uron > $user['health']) {

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

header ('location:death.php');exit();
}else{ $dbc->query("UPDATE `users` SET `health`=`health`-".$mob_uron." WHERE `id`='".$user['id']."'");}
}

}

$suk.=$tanki;
$suk.=$vi;
$_SESSION['logi']="$suk";





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




//////Душа Тени


    if(isset($_GET['dusha'])){
                if($user['am1_time'] > time()) {  header('location:dung_war.php');exit;}else{



$basik = 0;
$inf ='';

if($user['pers']==1 and $user['amulet1']>4){ 



$basik = $user['defense'] * 30 / 100;
$basik = ceil($basik);

 $ins ='<span class=iLegendary>дополнительно + '.$basik.' силы , Эффект: Ярость Воина</span>'; }




$astor = $plazma * $user['ten'] / 100;


$astor = ceil($astor);
$sin = $astor;
$astor = $astor+$basik;



$dbc->query('UPDATE `users` SET `am1_time` = "' .(time() + 60) . '",`dobav`=`dobav`+"'.$astor.'" WHERE `id` = "' . $user[id] . '"');

$maw = '<font color=green> Ты активировал Душа Теней (Сила +'.$sin.') '.$ins.'</font>'; 



$_SESSION['logi']="$maw"; header('location:dung_war.php');exit;}}












////// Плазма

    if(isset($_GET['plazm'])){
                if($user['am2_time'] > time()) { header('location:dung_war.php');exit;}else{



$dbc->query('UPDATE `users` SET `am2_time` = "' . (time() + 60) . '" WHERE `id` = "' . $user['id'] . '"');
$astor = $plazma * $user['plazm'] / 100;


$astor = ceil($astor);
$astor = $astor+$plazma;
if($crit==1){$tali= $astor * 50 / 100; $tali = ceil($tali); $astor = $astor+$tali;$mess =' <font color=red>(крит)</font>';}

$in ='';
$sh = mt_rand(1,3);
if($user['pers']==2 and $user['amulet2']>4 and $sh==2){ 
$astor = $astor*2;
$in =' <span class=iLegendary>Сила удвоена, Эффект: Гнев Мага</span>';}

if ($astor >= $banda['hp']) { $_SESSION['logi']='<font color=blueviolet>Лучи плазмы сожгли '.$name.'
 '.$in.'</font>';        dead_bos();






Oput($astor);

}else{


Oput($astor);
$dbc->query("UPDATE `banda` SET `hp`=`hp`-".$astor." WHERE `id`='".$user['banda']."'");


$dbc->query("UPDATE `users` SET `sob`=`sob`+".$astor." WHERE `id`='".$user['id']."'");
$maw = '<font color=blueviolet> Лучи плазмы пронзили '.$name.'  раня на '.$astor.' '.$mess.' '.$in.'</font>';   $_SESSION['logi']="$maw"; header('location:?');exit;}}}









    


?><div class="panel-inner"><img src="/img/dung/<?=$banda['dung']?>/<?=$banda['etap']?>.png" width="32" height="32" alt="."/><span class="major"><?=$name?><img src="img/stat/hp.png"><strong><?=$banda['hp']?></strong></span><br/></div><?





?><div class="combat-line"><a href="?jump" class="btn-aqua btn-potion"><img class="link-icon" src="/img/log/2.png" alt="" width="12" height="12"><span>Атаковать</span></a></div><?






If($am2_time <= 0){ ?><div class="combat-line"><a href="?plazm" class="btn-red"><img class="link-icon" src="/img/log/3.png" alt="" width="12" height="12"><span>Сияние Плазмы</span></a></div><?}else{?><div class="combat-line"><a href="?plazm" class="btn-red inactive inactive25"><img class="link-icon"src="/img/log/3.png" alt="" width="12" height="12"><span>Сияние Плазмы</span>&nbsp;<span class="locked-time"><?=Sec2Time($am2_time)?></span></a></div><?}







If($am1_time <= 0){?><div class="combat-line"><a href="?dusha" class="btn-red"><img class="link-icon" src="/img/log/4.png" alt="" width="12" height="12"><span>Душа Тени </span></a></div><?}else{?><div class="combat-line"><a href="?dusha" class="btn-red inactive inactive25"><img class="link-icon" src="/img/log/4.png" alt="" width="12" height="12"><span>Душа Тени</ span>&nbsp;<span class="locked-time"><?=Sec2Time($am1_time)?></span></a></div><?}  If($apteka_time <= 0){?><div class="combat-line"><a href="?el" class="btn-aqua btn-potion"><img class="link-icon" src="/img/log/5.png" alt="" width="12" height="12"><span>Зелье Здоровья(<?=$user['apteka']?>)</span></a></div><? }Else{ ?></div><div class="combat-line"><a href="?el" class="btn-aqua inactive-skill inactive50"><img class="link-icon" src="/img/log/5.png" alt="" width="12" height="12"><span>Зелье Здоровья(<?=$user['apteka']?>)</span>&nbsp;<span class="locked-time"><?=Sec2Time($apteka_time)?></span></a></div><?}





if($user['s_pet']==1){?><div class="info-box"><font color=orange>Помощник</font>: <font color=grey><?=$pet['name']?></br></div><?}

if (isset($_SESSION['logi'])){?>

<div class="b-panel-new dblue-panel bordered mt2">
<div class="panel-inner-2"><?=$_SESSION[logi]?></div></div><?   $_SESSION['logi']=NULL; }








    








$gogom = $dbc->query("SELECT * FROM `users` WHERE `banda`='".$user['banda']."' ORDER BY `health` DESC LIMIT 6");



?><div class="b-panel-new dblue-panel bordered mt2">
<div class="panel-inner-2"><center><span class="iLegendary">Состав Банды(<?=$banda['lim']?>/6)  </span></center><?





while($namf=$gogom->fetch_assoc()){


?><img src="img/class/<?=$namf['storona']?>/<?=$namf['pers']?>/pers.png" width="14" height="14" alt="*"><b><a href="pers.php?ank=<?=$namf['id']?>"<font color=green> <?=$namf['login']?></font></b></a> (<img src="img/stat/hp.png"><?=$namf['health']?>)<br><?}
?></div></div><? 


?><a class="btn" href="dung_war.php?exit">Сбежать с боя</a><?
















foot();
?>

