Файл: 3/battle.php
Строк: 144
<?php
require_once ('system/func.php');
$title = 'Окресности';
require_once ('system/header.php');
auth(); // Закроем от гостей
$trn = $db->query("SELECT * FROM `trenirovka` WHERE `user` = '".$user["id"]."' LIMIT 1");
$tren = $trn->fetch_assoc();
$id=num($_GET['id']);
$q = $db->query("SELECT * FROM `mobs` WHERE `id`='$id'");
$e = $q->num_rows;
if($e == 0){
header('Location: hunter.php');
exit;
}
$_hp = ceil((($user['max_health']*2)/100)*10);
if($user['energy'] <=1 or $user['health'] < $_hp){
$_SESSION['msg'] = "Для нападения необходимо минимум ".ico('icons','health.png')." 10% жизни и ".ico('icons','energy.png')." 2 энергии!<br><a href='/rinok?koldun&url=/battle.php' class='btn2' data-ajax>Восстановить ".ico('icons','gold.png')." 15</a>";
header('Location: /hunter.php');
exit();
}
$mob = $q->fetch_assoc();
if($mob['user']!==$myID and $mob['user']!=='' and $mob['user']!=='0'){
header('Location: hunter.php');
exit;
}
$q1 = $db->query("SELECT * FROM `mobs` WHERE `user`='$myID'");
$e1 = $q1->num_rows;
$w1 = $q1->fetch_assoc();
if($e1>='1'){
if($w1['id']!==$mob['id']){
header('Location: battle.php?id='.$w1['id'].'');
exit;
}
}
switch($_GET[sd]){
default:
$tb=time()+600;
$db->query("UPDATE `mobs` SET `time`='$tb' WHERE `id`=".$mob['id']."");
$db->query("UPDATE `users` SET `energy`=`energy`-2 WHERE `id`='$myID'");
//$db->query("UPDATE `mobs` SET `user`='$user[id]' WHERE `id`='$mob[id]'");
if($mob['hp']<='0'){
header('Location: battle.php?sd=win&id='.$mob['id'].'');
exit;
}
echo "<div class='block'><b>$mob[name]</b><br>$mob[level] уровень<br>Жизни: $mob[hp]";
$hpm = ($mob['hp']/$mob['hpall'])*100;
echo '<br><br><div style="height:7px;
background:#292929;
margin:5px;
border-radius: 4px;
border-top: 1px solid #000;
border-bottom: 1px solid #2b4364;">
<div style="height:7px;
background:#900;
border-top: 1px solid #000;
border-bottom: 1px solid #2b4364;
border-radius: 4px; width:'.$hpm.'%;"></div></div>';
if($_SESSION['potion']!==''){
echo $_SESSION['potion'];
$_SESSION['potion']="";
}
echo "<a class='btn2' href='battle.php?sd=ataka&id=$mob[id]'>Атаковать</a></div>
<div class='block2'><small>Чем чаще вы атакуете монстра, тем меньший урон вы ему наносите!</small></div>";
break;
case 'ataka':
$muron = rand(round($user['str']/6), round($user['str']/4));
$uron1 = round($muron+(($muron/100)*25));
if($user['time_udar']>=time()){
$muron = rand(round($user['str']/6), round($user['str']/4));
$uron2 = round($muron+(($muron/100)*25));
$uron1 = $uron2/10;
}else{
$muron = rand(round($user['str']/6), round($user['str']/4));
$uron1 = round($muron+(($muron/100)*25));
}
$uron=$uron1;
$tu = time()+1;
$db->query("UPDATE `users` SET `time_udar`=".$tu." WHERE `id`=".$myID."");
$mobu = rand($mob['u_min'],$mob['u_max']);
if($user['health']<='0' or $user['health']<=$mobu){
$_SESSION['rez'] = "<font color=red></center>Вы проиграли бой</center></font>";
$db->query("UPDATE `mobs` SET `user`='',`time`='0' WHERE `id`=".$id."");
header('Location: hunter.php');
exit;
}
if($mob['hp']<='0' or $mob['hp']<=$uron){
$db->query("UPDATE `mobs` SET `hp`='0' WHERE `id`=".$mob[id]."");
header('Location: battle.php?sd=win&id='.$mob['id'].'');
exit;
}
$db->query("UPDATE `users` SET `health`=`health`-".$mobu." WHERE `id`=".$myID."");
$db->query("UPDATE `mobs` SET `hp`=`hp`-".$uron." WHERE `id`=".$id."");
header('Location: battle.php?id='.$id.'');
exit;
break;
case 'win':
if($mob['hp']>'0'){
header('Location: battle.php?id='.$mob['id'].'');
exit;
}
$kamni=rand(1,1000);
if ($kamni==287){
$drid=mt_rand(1,3);
$drop = $db->query("SELECT * FROM `kamni` WHERE `id`='$drid' LIMIT 1") or die(mysql_error());
$dr = $drop->fetch_assoc();
$db->query("INSERT INTO `kamni_us` SET
`user_id` = '".$user['id']."',
`kam_str` = '".$dr['str']."',
`kam_def` = '".$dr['def']."',
`kam_hp` = '".$dr['hp']."',
`lvl` = '".$dr['lvl']."',
`tip` = '".$dr['tip']."',
`status` = 'off'");
if($dr[id]==1){$kam_name='Камень Атаки';}
if($dr[id]==2){$kam_name='Камень Защиты';}
if($dr[id]==3){$kam_name='Камень Жизни';}
$kamen="<br>".ico('icons','crystal.png')." ".$kam_name;
}
$shans_gold=rand(1,4);
if ($shans_gold==1){
$gold=rand(1,6);
$db->query("UPDATE `users` SET `gold`=`gold`+'$gold' WHERE `id`='$myID'");
$golds="<br><img src='/images/icons/gold.png'> $gold золота";
}
$silver=round(rand(($mob['silver'])/2,$mob['silver']));
if($user[vip]==1){$silver=ceil($silver*1.5);}
$exp=round(rand(($mob['exp'])/2,$mob['exp']));
if($effect_2['on'] == 1)$exp = $exp+ceil($exp*25/100);
if($user[id_clan] > 0){
$ordenexp = ceil($exp*15/100);
$db->query("UPDATE `users` SET `clan_exp` = '".($user[clan_exp]+$ordenexp)."' WHERE `id` = '".$myID."' LIMIT 1");
$db->query("UPDATE `clans` SET `exp` = `exp` + '".$ordenexp."' WHERE `id` = '".$user[id_clan]."' LIMIT 1");
}
/** ДРОП **/
/*$a = explode(",", $mob['drop']);
$a1 = count($a);
$a2 = rand(0,$a1-1);
$drid = $a[$a2];
$drop = mysql_query("SELECT * FROM `drop` WHERE `id`='$drid' LIMIT 1") or die(mysql_error());
$dr = mysql_fetch_assoc($drop);
$rnd=rand($dr['rand'],92);
if($rnd==$dr['rand']){
// ключ
if($dr['tip']=='key'){
mysql_query("UPDATE `users` SET `key`=`key`+'1' WHERE `id`='$myID'");
$_SESSION['dropkey']='yes';
$drops="<br><img src='img/key.png'> 1 $dr[name]";
}
}*/
$sob=$db->query("SELECT * FROM `sobytia_log` WHERE `id_user`=".$myID." LIMIT 1")->fetch_assoc();
if($sob['g_okra']==1 and $sob['okra']<5 and $sob['k_okra']>0)
{
$db->query("UPDATE `sobytia_log` SET `okra`=`okra`+'1' WHERE `id_user`=".$myID."");
}
$db->query("UPDATE `users` SET
`silver`=`silver`+'$silver',
`exp`=`exp`+'$exp' WHERE `id`='$myID'");
$db->query("UPDATE `mobs` SET `user`='',`hp`=`hpall`,`time`='0' WHERE `id`='$id'");
if($tren['shag'] == 3){
if($tren['camp'] < 10){
$db->query("UPDATE `trenirovka` SET `camp`=`camp`+'1' WHERE `user`='$myID'");
}}
$_SESSION['winq']='yes';
$_SESSION['rez'] = "<font color=lightgreen>Вы выиграли бой</font><br>Серебро: <img src='/images/icons/silver.png'> $silver, Опыт: <img src='/images/icons/exp.png'>$exp $drops $golds $kamen";
header('Location: hunter.php');
exit;
break;
}
require_once ('system/footer.php');
?>