<?php

//include_once 'core/class.php';

require_once 'core/system.php';








head('Осада');



 




reg();

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












$weapon = $weapo;
if($user['vip']==1){ $weapon = $weapon+1000;} 
$bb = mt_rand(1,100);
$crit = ($bb<=$user['crit']) ? true : false;


$bbb = mt_rand(1,100);
$sok = ($bbb<=30) ? true : false;





if($sok==1){ $takt= $weapon * $user['sokru'] / 100; $takt = ceil($takt); $weapon = $weapon +$takt;}






if($crit == 1){ $weapon = $weapon  * 1.5; $weapon = ceil($weapon); }



















$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']."' LIMIT 1")->fetch_assoc(); $next = $pet['str']; }



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

























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


if($osada['etap']==5){ $dop=$dbc->query("SELECT * FROM `dop`where `user`= '".$user['id']."' LIMIT 1")->fetch_assoc(); }



$clan_id = $clan['id'];




if($osada['etap']<5){ $vie_hp = $osada['stena_hp'];

$opp_name = 'Лучник'; $luk =150; $tis ='Разрушил';



 }else{ 

$opp_name = 'Страж'; $luk =0; $tis ='Убил';

$vie_hp = $dop['osada'];}









$inf = array('','Южная Стена','Западная Стена','Северная Стена','Восточная Стена');

$lim = array('','Южную Стену','Западную Стену','Северную Стену','Восточную Стену','Стража');






    $sila = array (0,2500,3000,4000,5000,5000,5000);



    $brony = array (0,500,500,500,1000,1500,10000);



    $hp = array (0,150000,260000,275000,275000,285000,295000);














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


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



$name = $inf[$osada['etap']];
$bak = $lim[$osada['etap']];


$hp = $hp[$banda['etap']];
if($osada['opp']<=0 and $osada['fin']==0){ 



$win = $dbc->query("SELECT * FROM `users` WHERE `osada`>1 ORDER BY `osada` DESC LIMIT 1")->fetch_assoc();
$win_clan = $dbc->query("SELECT * FROM `clan` WHERE `osada`>1 ORDER BY `osada` DESC LIMIT 1")->fetch_assoc();

            

$dbc->query("UPDATE `clan` SET `sera`=`sera`+50000 WHERE `id`='".$win_clan['id']."'");

$dbc->query("UPDATE `dop` SET `boi`=`boi`+2 WHERE `user`='".$win['id']."'");





$dbc->query("UPDATE `osada` SET     `fin`=1
,`clan_lord`='".$win_clan['id']."',`lord`='".$win['id']."' WHERE `id`=1");




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

}


    if($osada['fin']==1){





$igro=$dbc->query("SELECT * FROM `users` where `id`= '".$osada['lord']."' ")->fetch_assoc();  
$guli=$dbc->query("SELECT * FROM `clan` where `id`= '".$osada['clan_lord']."' ")->fetch_assoc();  



?><center><img src="img/ivent/victoriosada.png" width="100%" height="180" 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> <span class="iEpic"> <img src="/img/res/mag.png">+2</center></div></div><?






?><div class="b-panel-new dblue-panel bordered mt2"><div class="panel-inner-2"><center>Клан Захватчик :  <a href="/clan.php?clan=<?=$guli['id']?>"> <img src="img/clan_s/<?=$guli['storona']?>.png" width="13" height="13" alt="*"><?=$guli['name']?></a> <img src="img/stat/sera.png"><span class="info">+10000</center></div></div><?















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

global $osada;

global $hp;


if($osada['etap']==1){
$dbc->query('UPDATE `osada` SET `stena_hp` = 1000000,`etap`=`etap`+1 , `stena_1`=1 WHERE `id` = 1');}





if($osada['etap']==2){
$dbc->query('UPDATE `osada` SET `stena_hp` = 3000000,`etap`=`etap`+1 , `stena_2`=1 WHERE `id` = 1'); }






if($osada['etap']==3){
$dbc->query('UPDATE `osada` SET `stena_hp` = 5000000,`etap`=`etap`+1 , `stena_3`=1 WHERE `id` = 1'); }





if($osada['etap']==4){
$dbc->query('UPDATE `osada` SET `stena_hp` = 7000000,`etap`=`etap`+1 , `stena_4`=1 WHERE `id` = 1'); }




if($osada['etap']==5){
$dbc->query('UPDATE `osada` SET `opp`=`opp`-1 WHERE `id` = 1'); 

$dbc->query("UPDATE `dop` SET `osada`=500000 , `med`=`med`+1 WHERE `user` ='".$user['id']."' ");






}




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



}




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




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


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








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

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



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

$_SESSION['logi']="$loki"; header('location:osada_bat.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].' атаковал '.$bak.'  на  '.$pet['str'].'</font>'; $weapon = $weapon+$pet['str']; }








if ($weapon >= $vie_hp) {




Oput($weapon);
$_SESSION['logi']='Вы '.$tis.' '.$bak.'';

dead_bos(); }

else{
if($osada['etap']<5){

$dbc->query("UPDATE `osada` SET `stena_hp`=`stena_hp`-".$weapon." WHERE `id`=1");

$dbc->query("UPDATE `clan` SET `osada`=`osada`+".$weapon." WHERE `id`='".$user['clan']."'");


}
if($osada['etap']==5){

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


}


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


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



$suk = '<font color=green> Ты '.$maxty.' '.$bak.' на  '.$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']+$luk;

$mob_uron = ($tf>0) ? $tf : mt_rand(300,400);





if($mob_udar == 2){
$wow = array('ударил','укусил','ранил');
shuffle($wow);
$tanki = '</br><font color=red> '.$opp_name.' Атаковал тебя на  '.$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:osada_bat.php');exit();}





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


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













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

    if(isset($_GET['plazm'])){
                if($user['am2_time'] > time()) { header('location:osada_bat.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 >= $vie_hp) { $_SESSION['logi']='<font color=blueviolet>Лучи плазмы сожгли '.$bak.'




 '.$in.'</font>';        dead_bos();






Oput($astor);

}else{


Oput($astor);
if($osada['etap']<5){

$dbc->query("UPDATE `osada` SET `stena_hp`=`stena_hp`-".$astor." WHERE `id`=1");

$dbc->query("UPDATE `clan` SET `osada`=`osada`+".$astor." WHERE `id`='".$user['clan']."'");




}
if($osada['etap']==5){

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



}




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

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











    
 

if($osada['etap']<5){


?><div class="panel-inner"><img src="/img/osada/osadavictory.png "width="100%" height="180" alt="*" ><img src="/img/osada/stena.png" width="32" height="32" alt="."/><span class="major"><?=$name?><img src="img/stat/hp.png"><strong><?=$vie_hp?></strong></span><br/></div><?}else{ ?>
<div class="panel-inner"><img src="/img/ivent/stragwar.png" width="100%" height="180"> <img src="/img/osada/voin.png" width="32" height="32" alt="."/><span class="major">Страж<img src="img/stat/hp.png"><strong><?=$vie_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; }








    



?><div class="b-panel-new dblue-panel bordered mt2">
<div class="panel-inner-2"><center><span class="iLegendary">Лучшие Кланы  </span></center><?





$gogom = $dbc->query("SELECT * FROM `clan` WHERE `osada`>0 ORDER BY `osada` DESC LIMIT 3");

$i =0;
while($namf=$gogom->fetch_assoc()){


?><a class="link-panel no-arr" href="/clan.php?clan=<?=$namf['id']?>"> <?=++$i?>.<img src="img/clan_s/<?=$namf['storona']?>.png" width="14" height="14" alt="*"><?=$namf['name']?>(<?=$namf['osada']?>)</a><?}





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




?><a class="btn" href="view_osada.php">События Осады</a><?












foot();
?>

