<?  
//
//
if($user['premium_time'] > time()){ 
$prem = 2;
}else{
$prem =1;
}
//
//
$rand_sneg = rand(1,4);
//
//
$res_rand_win1 = rand(90,150);
$res_rand_win = intval($res_rand_win1*$prem);
//
//
$res_rand_lose1 = rand(40,80);
$res_rand_lose = intval($res_rand_lose1*$prem);
//
//
$skill = number($_GET['skill']);
if($skill >= 1){
//
//
$active = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `id` = ? LIMIT 1", array($uid,$skill)); 
if(!active){
header('location:?');
exit();
}
//
//
if($active['reset'] > time()){
header('location:?');
exit();
}
//
//
if($active['time'] > time()){
header('location:?');
exit();
}
// 
// 
$kill1 = intval($user['kill']*5); 
$kill2 = intval($active['param']*$kill1/100); 
$kill = intval($active['param']+$kill2);
// 
// 
$medik1 = intval($user['medik']*5); 
$medik2 = intval($active['param']*$medik1/100); 
$medik = intval($active['param']+$medik2);
// 
// 
$mag1 = intval($user['mag']*5); 
$mag2 = intval($active['param']*$mag1/100); 
$mag = intval($active['param']+$mag2);
//
//
if($active['type'] == 1){
//
//
$attack = intval($lec_fight['bot_power']*$kill/100);
//
//
qry("UPDATE `lec_fight` SET `bot_hp` = `bot_hp` - ? WHERE `id_user` = ? LIMIT 1", array($attack,$uid)); 
//
//
}
//
//
if($active['type'] == 2){
//
//
$attack = intval($lec_fight['bot_power']*$kill/100);
//
//
qry("UPDATE `lec_fight` SET `bot_power` = `bot_power` - ?, `bot_block` = `bot_block` - ?, `s2` = ? WHERE `id_user` = ? LIMIT 1", array($attack,$attack,$attack,$uid));
//
//
}
//
//
if($active['type'] == 3){
//
//
$attack= rand(round($lec_fight['power']/4), round($lec_fight['power']/3)); 
//
//
qry("UPDATE `lec_fight` SET `bot_hp` = `bot_hp` - ? WHERE `id_user` = ? LIMIT 1", array($attack,$uid)); 
//
//
}
//
//
if($active['type'] == 4){
//
//
$attack = intval($lec_fight['power']*$kill/100);
//
//
qry("UPDATE `lec_fight` SET `power` = `power` + ?, `s4` = ? WHERE `id_user` = ? LIMIT 1", array($attack,$attack,$uid)); 
//
//
}
//
//
if($active['type'] == 5){
//
//
$attack = intval($lec_fight['block']*$kill/100);
//
//
qry("UPDATE `lec_fight` SET `block` = `block` + ?, `s5` = ? WHERE `id_user` = ? LIMIT 1", array($attack,$attack,$uid)); 
//
//
}
//
//
if($active['type'] == 6){
//
//
if($lec_fight['hp'] >= $lec_fight['power']){
err2("<div style='clear:both;'></div><div class='b-notice trsmgr'><div class='notify-inner'>У вас полный запас здоровья!</div></div>");
header('location:?');
exit();
}
//
//
$attack = intval($lec_fight['power']*$medik/100);
//
//
qry("UPDATE `lec_fight` SET `hp` = `hp` + ? WHERE `id_user` = ? LIMIT 1", array($attack,$uid)); 
//
//
}
//
//
if($active['type'] == 7){
//
//
$attack = intval($lec_fight['power']*$medik/100);
//
//
qry("UPDATE `lec_fight` SET `hp` = `hp` + ?, `bot_hp` = `bot_hp` - ? WHERE `id_user` = ? LIMIT 1", array($attack,$attack,$uid)); 
//
//
}
//
//
if($active['type'] == 11){
//
//
$attack = intval($lec_fight['bot_power']*$mag/100);
//
//
qry("UPDATE `lec_fight` SET `power` = `power` + ?, `bot_power` = `bot_power` - ?, `s11` = ? WHERE `id_user` = ? LIMIT 1", array($attack,$attack,$attack,$uid)); 
//
//
}
//
//
if($active['type'] == 13){
//
//
$attack = intval($lec_fight['default2']*50/100);
//
//
qry("UPDATE `lec_fight` SET `clon_hp` = ? WHERE `id_user` = ? LIMIT 1", array($attack,$uid)); 
//
//
}
//
//
qry("UPDATE `skills` SET `reset` = ?, `time` = ?, `fight` = ?, `fight_time` = ? WHERE `id` = ? LIMIT 1", array(time()+$active['reset_max'],time()+$active['time_max'],1,time()+5,$active['id']));
//
//
header('location:?ok');
exit();
}
// 
// 
//
$active2 = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `type` = ? LIMIT 1", array($uid,2)); 
if($active2['reset'] <= time() && $active2['fight'] == 1 && $lec_fight['bot_power'] != $lec_fight['default']){
qry("UPDATE `lec_fight` SET `bot_block` = `bot_block` + ?, `bot_power` = `bot_power` + ? WHERE `id_user` = ? LIMIT 1", array($lec_fight['s2'],$lec_fight['s2'],$uid)); 
qry("UPDATE `skills` SET `fight` = ? WHERE `id` = ? LIMIT 1", array(0,$active2['id'])); 
header('location:?');
exit();
}
//
//
$active4 = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `type` = ? LIMIT 1", array($uid,4)); 
if($active4['reset'] <= time() && $active4['fight'] == 1 && $lec_fight['power'] != $lec_fight['default2']){
qry("UPDATE `lec_fight` SET `power` = `power` - ? WHERE `id_user` = ? LIMIT 1", array($lec_fight['s4'],$uid)); 
qry("UPDATE `skills` SET `fight` = ? WHERE `id` = ? LIMIT 1", array(0,$active4['id'])); 
header('location:?');
exit();
}
//
//
$active5 = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `type` = ? LIMIT 1", array($uid,5)); 
if($active5['reset'] <= time() && $active5['fight'] == 1 && $lec_fight['block'] != $lec_fight['default2']){
qry("UPDATE `lec_fight` SET `block` = `block` - ? WHERE `id_user` = ? LIMIT 1", array($lec_fight['s5'],$uid)); 
qry("UPDATE `skills` SET `fight` = ? WHERE `id` = ? LIMIT 1", array(0,$active5['id'])); 
header('location:?');
exit();
}
// 
//
$active8 = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `type` = ? LIMIT 1", array($uid,8)); 
$act8 = 0; 
if($active8['reset'] > time()){
$act8 = 1;
}
//
//
$active9 = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `type` = ? LIMIT 1", array($uid,9)); 
$act9 = 0; 
if($active9['reset'] > time()){
$act9 = 1;
}
//
//
$active10 = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `type` = ? LIMIT 1", array($uid,10)); 
$act10 = 2; 
if($active10['reset'] > time()){
$act10 = 1;
}
// 
//
$active11 = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `type` = ? LIMIT 1", array($uid,11)); 
if($active11['reset'] <= time() && $active11['fight'] == 1 && $lec_fight['power'] != $lec_fight['default2']){
qry("UPDATE `lec_fight` SET `power` = `power` - ?, `bot_power` = `bot_power` + ? WHERE `id_user` = ? LIMIT 1", array($lec_fight['s11'],$lec_fight['s11'],$uid)); 
qry("UPDATE `skills` SET `fight` = ? WHERE `id` = ? LIMIT 1", array(0,$active11['id'])); 
header('location:?');
exit();
}
//
//
$active12 = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `type` = ? LIMIT 1", array($uid,12)); 
$act12 = 0; 
if($active12['reset'] > time()){
$act12 = 1;
}
//
//
//
//
$active14 = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `type` = ? LIMIT 1", array($uid,14)); 
$act14 = 0; 
if($active14['reset'] > time()){
$act14 = 1;
}
//
//
$active15 = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `type` = ? LIMIT 1", array($uid,15)); 
//
//
$act15 = 0; 
if($active15['reset'] > time()){
$act15 = 1;
}
//
//
$power_opp = rand(round($lec_fight['bot_power']/4), round($lec_fight['bot_power']/3)); 
$block_opp = rand(round($lec_fight['bot_block']/10), round($lec_fight['bot_block']/8)); 
// 
// 
$power = rand(round($lec_fight['power']/4), round($lec_fight['power']/3)); 
$block = rand(round($lec_fight['block']/10), round($lec_fight['block']/8)); 
// 
// 
$power_opp = $power_opp - $block; 
if($power_opp < 0)$power_opp = 0; 
$power = $power - $block_opp ; 
if($power < 0)$power = 0; 
// 
//
//
// 
if(isset($_GET['attack_get'])){ 
//
//
if($lec_fight['fight_time'] > time() && $lec_fight['bot_hp'] >= 1){
err2("<div style='clear:both;'></div><div class='b-notice trsmgr'><div class='notify-inner'> Атаковать можно раз в 2 секунды! </div></div>");
header('location:?');
exit();
}
//
//
if($power >= $lec_fight['bot_hp']){ //win 
//  
//
$m1 = $lec[$lec_fight['type']];
$m2 = $lec['level']*5;
$m3 = $lec_fight['type'];
//
//
if($m1 < $m2){  
//
//
if($m3 == 'metal'){
//
//
$q_3 = fch("SELECT * FROM `quest_user` WHERE `id_quest` = ? AND `id_user` = ? LIMIT 1", array(3,$uid));
if($q_3['last'] < time())qry("UPDATE `quest_user` SET `koll` = `koll` + ? WHERE `id` = ? LIMIT 1", array(1,$q_3['id']));
//
//
}
//
//
if($m3 == 'tkan'){
//
//
$q_4 = fch("SELECT * FROM `quest_user` WHERE `id_quest` = ? AND `id_user` = ? LIMIT 1", array(4,$uid));
if($q_4['last'] < time())qry("UPDATE `quest_user` SET `koll` = `koll` + ? WHERE `id` = ? LIMIT 1", array(1,$q_4['id']));
//
//
}
//
//
if($m3 == 'kamen'){
//
//
$q_5 = fch("SELECT * FROM `quest_user` WHERE `id_quest` = ? AND `id_user` = ? LIMIT 1", array(5,$uid));
if($q_5['last'] < time())qry("UPDATE `quest_user` SET `koll` = `koll` + ? WHERE `id` = ? LIMIT 1", array(1,$q_5['id']));
//
//
}
//
//
if($m3 == 'swit'){
//
//
$q_6 = fch("SELECT * FROM `quest_user` WHERE `id_quest` = ? AND `id_user` = ? LIMIT 1", array(6,$uid));
if($q_6['last'] < time())qry("UPDATE `quest_user` SET `koll` = `koll` + ? WHERE `id` = ? LIMIT 1", array(1,$q_6['id']));
//
//
}
//
//
qry("UPDATE `users` SET `".$lec_fight['type']."` = `".$lec_fight['type']."` + ? WHERE `id` = ? LIMIT 1", array(1,$uid));    
qry("UPDATE `lec_user` SET `".$lec_fight['type']."` = `".$lec_fight['type']."` + ? WHERE `id_user` = ? LIMIT 1", array(1,$uid));  
// 
//
$resource ="<img src='/images/".$lec_fight['type'].".png' width='16' height='16'> 1";
//
//
}
//
//
// 

//
// 

//
// 
qry("UPDATE `users` SET `exp` = `exp` + ?, `silver` = `silver` + ?, `tour` = `tour` + ? WHERE `id` = ? LIMIT 1", array($res_rand_win/2,$res_rand_win,1,$uid));  
// 
// 
qry("DELETE FROM `lec_fight` WHERE `id_user` = ?", array($uid));
// 
// 
msg2("<div style='clear:both;'></div><div class='b-notice trsmgr'><div class='notify-inner'> Вы победили!</span><br>".$resource." <img class='img2' src='/images/gold.png' width='15px' height='15px' > ".intval($res_rand_win)." <img class='img2' src='/images/exp.png' width='15px' height='15px'> ".intval($res_rand_win/2)." </div></div>
");
// 
// 
} 
elseif($power_opp >= $lec_fight['hp'] && $act8 == 0 && $act9 == 0  && $act14 == 0 && $lec_fight['clon_hp'] <= 0){ //lose 
// 
// 
qry("DELETE FROM `lec_fight` WHERE `id_user` = ?", array($uid));
// 
// 
qry("UPDATE `users` SET `exp` = `exp` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($res_rand_lose/2,$res_rand_lose,$uid));  
// 
// 
err2("Вы проиграли!</span><br><img class='img2' src='/images/gold.png' width='15px' height='15px'> ".intval($res_rand_lose)." <img class='img2' src='/images/exp.png' width='15px' height='15px'> ".intval($res_rand_lose/2)."
"); 
// 
// 
} 
// 
// 
if($act8 == 0 && $act9 == 0  && $act14 == 0){
//
//
if($lec_fight['clon_hp'] >= 1){
//
//
qry("UPDATE `lec_fight` SET `clon_hp` = `clon_hp` - ? WHERE `id_user` = ? LIMIT 1", array($power_opp,$uid)); //атака бота
//
//
}else{
//
//
qry("UPDATE `lec_fight` SET `hp` = `hp` - ? WHERE `id_user` = ? LIMIT 1", array($power_opp,$uid)); //атака бота
//
//
}
//
//
}
//
//
qry("UPDATE `lec_fight` SET `bot_hp` = `bot_hp` - ? WHERE `id_user` = ? LIMIT 1", array($power,$uid)); //атака игрока
//
//
qry("UPDATE `lec_fight` SET `fight_time` = ? WHERE `id` = ? LIMIT 1", array(time()+$act10,$lec_fight['id']));
// 
// 
header('location:?'); 
exit(); 
} 
//
//
if($lec_fight['bot_hp'] <= 0 && $lec_fight['bot_power'] >= 1){
header('location:?attack_get');
exit();
}
//
//
?>
<div class="tophead">
<div class = "ohh">
<img class='imgSkill' src = '/images/lec/<?=$lec_fight['id_bot'];?>.png' widht='40' height='40'>
</div>
<span class="orange">
<?=$lec_fight['name'];?>
</span>
<br>
<img src="/images/power.png" width='15px' height='15px'> <?=$lec_fight['bot_power'];?> 
<img src="/images/block.png" width='15px' height='15px'> <?=$lec_fight['bot_block'];?> 
<img src="/images/health.png" width='15px' height='15px'> <?=$lec_fight['bot_hp'];?>
<br>
<div class="hrs"></div>
   <div class="progress-bar exp">
                                    <div style="width:<? echo ''.round($lec_fight['bot_hp']/$lec_fight['default']*100,1).''; ?>%;" class="progress _red"></div>
                                </div>

</div>
<div class="list2 cntr">
<div class="hrs">
</div>

<a href="?attack_get">
<img class='imgSkill' src = '/images/attack.png' widht='46' height='46'>
</a>

<?
// 
// 
for($i = 1;$i < 5;$i++){   
// 
// 
$fight = fch("SELECT * FROM `skills_fight` WHERE `id_user` = ? AND `type` = ? LIMIT 4", array($uid,$i)); 
//
//
$info = fch("SELECT * FROM `skills` WHERE `id_user` = ? AND `id` = ? LIMIT 4", array($uid,$fight['id_skills'])); 
// 
// 
if($fight['id_skills'] == 0){ 
?> 
<div class = "items-icons imgSkill"></div> 
<? 
}else{ 
//
if($info['time'] > time()){
$color= 'SkillReload';
$link = '#';
}
if($info['reset'] > time()){
$color= 'SkillActive';
$link = '#';
}
if($info['time'] <= time()){
$color= 'imgSkill';
$link = '?skill='.$info['id'];
}
//
?> 
<a href="<?=$link;?>">
<img class="<?=$color;?>" 
src="/images/skills/<?=$info['type'];?>.png" width="46" height="46"> 
</a>
<? 
} 
} 
// 
// 
?>
<div class="hrs">
</div>
</div>


<div class="tophead">
<div class = "ohh">
<img class="imgSkill" src="/images/avatar/<?=$user['sex'];?>/<?=$user['avatar'];?>.png" width="40" height="40" alt="*">
</div>


<span class="orange">
<?=$user['login'];?>
</span>
<br>
<img src="/images/power.png"> <?=$lec_fight['power'];?> 
<img src="/images/block.png"> <?=$lec_fight['block'];?> 
<img src="/images/health.png"> <?=$lec_fight['hp'];?>

<div class="hrs"></div>
   <div class="progress-bar exp">
                                    <div style="width:<? echo ''.round($lec_fight['hp']/$user['health']*100,1).''; ?>%;" class="progress _red"></div>
                                </div>

</div>
<?
if($lec_fight['clon_hp'] >= 1){
?>
<div class="tophead">
<span class="yellow">
Ваш клон 
</span>
<img src="/images/health.png"> <?=$lec_fight['clon_hp'];?>
<br>
<div class="hrs"></div>
   <div class="progress-bar exp">
                                    <div style="width:<? echo ''.round($lec_fight['clon_hp']/($lec_fight['default2']*35/100)*100,1).''; ?>%;" class="progress _red"></div>
                                </div>

</div>
<?
}
?>