<?
include_once '../core/system.php';
echo only_reg();
if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `bashni` WHERE `id` = '".intval($_GET['id'])."'"),0) == true){
$bashnay = mysql_fetch_assoc(mysql_query("SELECT * FROM `bashni` WHERE `id`  = '".intval($_GET['id'])."'"));
}else{
$_SESSION['err'] = "Нет такой башни!";
header('Location: index.php');
exit();
}
if($user[health] < 20){
$_SESSION['light'] = "<span class='dred'>Для нападения нужно <img src='/images/icon/health.png' alt=''/> 20 Здоровья</span><br/>Здоровье восстанавливается со временем или за золото<br><div class='separ'></div><a class='btn' href='/moduls/ckoldun.php?act=ok'><span class='end'><span class='label'>Восстановить <img src='/images/icon/health.png' alt=''/> 100% здоровья</span></span></a><br><span class='grey'>Цена: <img src='/images/icon/gold.png' alt=''/> 10 золота</span>";
header("Location: bashnya.php?id=$bashnay[id]");
exit();
}
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id`  = '".$bashnay[id_user]."'"));
$exp = $ank[level]*2;
$user_uron = rand(1,$user[sila]-79);
$bashnay_uron = rand(1,$bashnay[sila]-80);
if($user[mana] > 49){
if($user_uron < $bashnay_uron){
mysql_query("update `user` set `mana`='".($user['mana']-50)."', `health`='".($user['health']-$bashnay_uron)."' where (`id` = '".$user['id']."')");
mysql_query("update `bashni` set `health` = '".($bashnay['health']-$user_uron)."' where (`id` = '".$bashnay['id']."')");
header("Location: bashnya.php?id=$bashnay[id]");
$_SESSION['light'] = "<h2 class='dred' style='font-weight:bold;'><img src='/images/icon/2hit.png' alt=''/> Поражение <img src='/images/icon/2hit.png' alt=''/></h2>";
exit();
}else{
mysql_query("update `user` set `exp` = '".($user['exp']+$exp)."',`mana`='".($user['mana']-50)."', `health`='".($user['health']-$bashnay_uron)."' where (`id` = '".$user['id']."')");
mysql_query("update `bashni` set `health` = '".($bashnay['health']-$user_uron)."' where (`id` = '".$bashnay['id']."')");
header("Location: bashnya.php?id=$bashnay[id]");
$_SESSION['light'] = "<h2 class='dgreen' style='font-weight:bold;'><img src='/images/icon/2hit.png' alt=''/> Победа <img src='/images/icon/2hit.png' alt=''/></h2><div class='separ'></div><img src='/images/icon/exp.png' alt='exp'/> ".$exp." опыта";
exit();
}
}else{
$_SESSION['light'] = "<span class='dred'>Для нападения нужно <img src='/images/icon/mana.png' alt=''/> 50 маны</span><br/>Мана восстанавливается со временем или за золото<br><div class='separ'></div><a class='btn' href='/moduls/ckoldun.php?act=ok'><span class='end'><span class='label'>Восстановить <img src='/images/icon/mana.png' alt=''/> 100% маны</span></span></a><br><span class='grey'>Цена: <img src='/images/icon/gold.png' alt=''/> 10 золота</span>";
header("Location: bashnya.php?id=$bashnay[id]");
exit();
}
?>