 <?php

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








head('Сражение');




reg();

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



$bum = 5;
$param = new param;






$tanki='';





$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();

$next = 0;
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 ;













if($user['pers']==1){ $dob=2; } else { $dob=1; }











$aluko = $dbc->query("SELECT `max_health`,`health`,`id` ,`name`,`time`,`money`,`strength`,`def` FROM `monster` WHERE `user`='".$user['id']."' LIMIT 1")->fetch_assoc();








if(!$aluko){ $_SESSION['message']=' Монстр убит или сбежал';


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



//if($user['pers']==1){ $dob=2; }esle{ $dob=1; }







function dead_bos(){
global $user;
global $dbc;
global $aluko;
global $dob;


$dbc->query("UPDATE `monster` SET `health`=0, `user` = 0, `time`=0 WHERE `id`='".$aluko['id']."'");



if($user['level']<10){ $limit = 5; }elseif($user['level']>=10){ $limit= 10; }


if($user['level']>=25){  $limit = 15; }
if($user['level']>=45){  $limit = 20; }



if($user['lim']<$limit){


$sp = mt_rand(1,100);
 }else{ $sp = 101; }
if($sp<=20){ $vi ='Вы нашли <img src="img/money/money.png"> 1'; 





$dbc->query("UPDATE `users` SET `gold`=`gold`+1,`lim`=`lim`+1 WHERE `id`='".$user['id']."'"); }else { $vi = '';



}


    

            
if($user['clan']>0 and $user['level']>14){ $dbc->query("UPDATE `clan` SET `tour`=`tour`+'".$dob."' WHERE `id`='".$user['clan']."'"); }





                
                // Начисляем рубины                
$dbc->query("UPDATE `users` SET     `serebro`=`serebro`+'".$aluko['money']."' WHERE `id`='".$user['id']."'");






                






                
                




$_SESSION['message']=' '.$aluko['name'].' убит.. <img src=img/stat/sera.png>'.$aluko['money'].' '.$vi.'';





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

}




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



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

 $_SESSION['logi']="$loki";  header('location:battle.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:battle.php');exit;}}






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

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



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

$_SESSION['logi']="$loki"; header('location:battle.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] . '"'); }


$vi ='';
$re = $weapon;
$re = $re - $aluko['def'];
$weapon = ($re>0) ? $re : 1;

$wep = $weapon;

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

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





if ($weapon >= $aluko['health']) {

Oput($weapon);
dead_bos(); }
else{
$dbc->query("UPDATE `monster` SET `health`=`health`-".$weapon." WHERE `id`='".$aluko['id']."'");

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




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



$suk = '<font color=green> Ты '.$maxty.' '.$aluko['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 = $aluko['strength']; 


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





if($mob_udar == 2){
$wow = array('ударил','укусил','ранил');
shuffle($wow);
$tanki = '</br><font color=red> '.$aluko['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:battle.php');exit();}



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


    if(isset($_GET['dusha'])){
   if($user['dobav'] > 0) {  header('location:sin.php');exit;}            


 if($user['am1_time'] > time()) {  header('location:sin.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:sin.php');exit;}}












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

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


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

$astor = $user['strength'] * $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 >= $aluko['health']) {         dead_bos();
$sukm = '<font color=blueviovet> Лучи плазмы сожгли  '.$mobik[name].'  '.$in.'</font>'; 


Oput($astor);
}else{


Oput($astor);
$dbc->query("UPDATE `monster` SET `health`=`health`-".$astor." WHERE `id`='".$aluko['id']."'");


$maw = '<font color=blueviolet> Лучи плазмы пронзили Ледяной Призрак  раня на '.$astor.' '.$mess.'  '.$in.'</font>';   $_SESSION['logi']="$maw"; header('location:?');exit;}}}





$tes = $aluko['time']-time();
if(Sec2Time($tes)>0){ ?><center><span class="iLegendary">Монстр под защитой <?=Sec2Time($tes)?></span></center><? }



    


?><div class="panel-inner"><img src="/img/at/tr.png" width="32" height="32" alt="."/><span class="major"><?=$aluko['name']?><img src="img/stat/hp.png"><strong><?=$aluko['health']?></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="/battle.php?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="/sin.php?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="/sin.php?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="/battle.php?el" class="btn-aqua btn-potion"><img class="link-icon" src="/img/log/5.png" alt="" width="12" height="12"><span>Элексир Раздора</span></a></div><? }Else{ ?></div><div class="combat-line"><a href="/battle.php?el" class="btn-aqua inactive-skill inactive50"><img class="link-icon" src="/img/log/5.png" alt="" width="12" height="12"><span>Элексир Раздора</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; }









    


























?></div></div><?
foot();
?> 
