<?php
session_start();
include ('private/mysql.php');
include ('tmp/head.php');


switch($sd){
default:

if($id=='0' or $id==''){$mid='';}else{$mid="and `id`='$id'";}
$q = mysql_query("SELECT * FROM `mobs` WHERE `loc`='$user[hunter]' $mid and `hp`>'0' and `user`='' or `user`='0' LIMIT 1");

While($mob = mysql_fetch_assoc($q)){
        $minid = mysql_fetch_assoc(mysql_query("SELECT * FROM `mobs` WHERE `loc`='$user[hunter]' and `hp`>'0' and `user`='' or `user`='0' ORDER BY `id` ASC LIMIT 1"));
        $maxid = mysql_fetch_assoc(mysql_query("SELECT * FROM `mobs` WHERE `loc`='$user[hunter]' and `hp`>'0' and `user`='' or `user`='0' ORDER BY `id` DESC LIMIT 1"));
        $mobid = rand($minid['id'],$maxid['id']);
        
        
        if($id=='0' or $id==''){
            
            echo "<a href='/battle2/ataka/$mobid'> Бить любого</a>";
            
        }else{
            
            echo "$mob[name] <font size=2 color=red>$mob[hp]</font> <small>[<a href='/info/mob/$mob[id]'>инфо</a>]</small><br>";
            echo "<img src='/img/uron.png'> <a href='/battle2/ataka/$mob[id]'>Атаковать</a><br>";
            
        }
        
        
}
    
    
break;


case 'ataka':

    $mob = mysql_fetch_assoc(mysql_query("SELECT * FROM `mobs` WHERE `id`='$id' and `hp`>'0'"));

    $muron = rand($user['min_u'],$user['max_u']);
    $uron1 = round($muron+(($muron/100)*25));
    
    if($user['time_udar']>=time()){
        $muron = rand($user['min_u'],$user['max_u']);
        $uron2 = round($muron+(($muron/100)*25));
        $uron1 = $uron2/10;
    }else{
        $muron = rand($user['min_u'],$user['max_u']);
        $uron1 = round($muron+(($muron/100)*25));
    }
    if($game['winopp']==$user['storona']){$oppbonus=($uron1['uron']/100)*25;}else{$oppbonus=0;}
    
          
    if($user['krit']>='50'){
        $kr = rand(2,4);
        if($kr=='3'){
            $krit=round(($uron1/100)*$user['int']);
            $uron=$uron1+$krit+$oppbonus;
        }else{
            $uron=$uron1+$oppbonus;
        }
    }else{
        $uron=$uron1+$oppbonus;
    }
    
    
    $tu = time()+1;
    mysql_query("UPDATE `users` SET `time_udar`='$tu' WHERE `id`='$uid'");
    
    $mobu = rand($mob['u_min'],$mob['u_max']);
    
    $mans = $user['mp']+$user['mana'];
    
    if($mans>=$user['mpall']){
        $mana = $user['mpall'];
    }else{
        $mana = $user['mp']+$user['mana'];
    }
    
    if($user['hp']<='0' or $user['hp']<=$mobu){
        $_SESSION['rez'] = "<font color=red></center>Вы проиграли бой</center></font><hr>";
        mysql_query("UPDATE `users` SET `lose`=`lose`+'1' WHERE `id`='$uid'");
        mysql_query("UPDATE `mobs` SET `user`='',`time`='0' WHERE `id`='$id'");
        header('Location: /battle2');
        exit;
    }
    
    if($mob['hp']<='0' or $mob['hp']<=$uron){
        mysql_query("UPDATE `mobs` SET `hp`='0' WHERE `id`='$mob[id]'");
        header('Location: /battle2/win/'.$mob['id'].'');
        exit;
    }
    
    
    mysql_query("UPDATE `users` SET `hp`=`hp`-'$mobu',`mp`='$mana' WHERE `id`='$uid'");
    
    
    mysql_query("UPDATE `mobs` SET `hp`=`hp`-'$uron' WHERE `id`='$mob[id]'") or die(mysql_error());
  
    header('Location: /battle2/'.$mob['id'].'');
    exit;

break;



}
include ('tmp/foot.php');
?>