<?php
require_once '../core/system.php';
echo only_reg();
if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `zamok` WHERE `id` = '".intval($_GET['id'])."'"),0) == true){
$zamok = mysql_fetch_assoc(mysql_query("SELECT * FROM `zamok` WHERE `id`  = '".intval($_GET['id'])."'"));
}else{
$_SESSION['err'] = "Нет такого замка!";
header('Location: index.php');
exit();
}
if($user[health] < 20){
$_SESSION['light'] = $warning_low_health;
header("Location: zamok.php?id=$zamok[id]");
exit();
}
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id`  = '".$zamok[id_user]."'"));
$gold = $ank[level]*2;
$user_uron = rand(1,$user[sila]-79);
$zamok_uron = rand(1,$zamok[param]-1000);
if ($user['health'] < $zamok_uron ) {
$castle_uron = $user['health'];
}else{
$castle_uron = $zamok_uron;
}
if ($zamok['param'] < $user_uron ) {
$player_uron = $zamok['param'];
}else{
$player_uron = $user_uron;
}
if($user[mana] > 49){
if($player_uron < $castle_uron){
mysql_query("update `user` set `mana`='".($user['mana']-50)."', `health`='".intval($user['health']-$castle_uron)."' where (`id` = '".$user['id']."')");
mysql_query("update `zamok` set `param` = '".intval($zamok['param']-$player_uron)."' where (`id` = '".$zamok['id']."')");
header("Location: zamok.php?id=$zamok[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 `gold` = '".($user['gold']+$gold)."',`mana`='".($user['mana']-50)."', `health`='".($user['health']-$castle_uron)."' where (`id` = '".$user['id']."')");
mysql_query("update `zamok` set `param` = '".($zamok['param']-$player_uron)."' where (`id` = '".$zamok['id']."')");
header("Location: zamok.php?id=$zamok[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/gold.png' alt='exp'/> ".$gold." золота";
exit();
}
}else{
$_SESSION['light'] = $warning_low_mana;
header("Location: zamok.php?id=$zamok[id]");
exit();
}
?>