<?
define('PROTECTOR', 1);

$headmod = 'scroll';//фикс. места

$textl='Инвентарь';
include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
going();
include($path.'files/core.php');
include($path.'files/head.php');
include($path.'files/zag.php');

$req = mysql_query("SELECT * FROM `res` WHERE `usr` = '$log' and `id`='$_GET[id]'");

$avto=mysql_num_rows($req);
if($avto==0){
echo'Ошибка, такого свитка нет!';
include($path.'files/down.php');
exit;
}
$mag = mysql_fetch_array($req);
if($mag[tip]!='scroll'){
echo'Ошибка, доступ закрыт!';
include($path.'files/down.php');
exit;
}
switch($mag[what]){
case 'scroll_weapon':
$req = mysql_query("SELECT * FROM `item` WHERE `usr` = '$log' and `tip`='weapon' and `image`='yes' LIMIT 1");
$avto=mysql_num_rows($req);
if($avto=='0'){
echo'Ошибка, сначала возьмите оружие!';
include($path.'files/down.php');
exit;
}
$it = mysql_fetch_array($req);

$u = explode("|",$mag[give]);
$numin=$u[0]+$udata[umin];
$numax=$u[1]+$udata[umax];
$w=explode("*",$it[name]);
if(empty($w[1])){
$nam="$w[0]*1";
}else{
$kol=$w[1]+1;
$nam="$w[0]*$kol";}

if(empty($w[1])){$stavka=100;}
if($udata[prof] == 'Кузнец'){
if($w[1]==1){$stavka=100;}
if($w[1]==2){$stavka=90;}
if($w[1]==3){$stavka=80;}
if($w[1]==4){$stavka=70;}
if($w[1]==5){$stavka=60;}
if($w[1]==6){$stavka=50;}
if($w[1]==7){$stavka=40;}
if($w[1]==8){$stavka=35;}
if($w[1]==9){$stavka=30;}
}
else{
if($w[1]==1){$stavka=100;}
if($w[1]==2){$stavka=80;}
if($w[1]==3){$stavka=70;}
if($w[1]==4){$stavka=60;}
if($w[1]==5){$stavka=50;}
if($w[1]==6){$stavka=40;}
if($w[1]==7){$stavka=35;}
if($w[1]==8){$stavka=30;}
if($w[1]==9){$stavka=25;}}
if($w[1]>=10){
echo'Вещь заточена на максимум!';
include($path.'files/down.php');
exit;}

$priz=rand(1,100);

if($priz<=$stavka){

$num=$u[0]+$it[umin];
$nux=$u[1]+$it[umax];

mysql_query("UPDATE `users` SET `umin` = '$numin',`umax` = '$numax' WHERE usr = '$log'");
mysql_query("UPDATE `item` SET
      `umin` = '$num',
      `umax` = '$nux',
      `name` = '$nam'
       WHERE `usr` = '$log' and `tip`='weapon' and `image`='yes'");
       
$msg="Оружие заточено!<br/>Новый урон: $numin/$numax<br/>";
}else{
$req = mysql_query("SELECT * FROM `item` WHERE `usr` = '$log' and `tip`='weapon' and `image`='yes'");
$it = mysql_fetch_array($req);

$numin=$udata[umin]-$it[umin];
$numax=$udata[umax]-$it[umax];

$npgolova=$udata[pgolova]-$it[pgolova];
$npbody=$udata[pbody]-$it[pbody];
$npnogi=$udata[pnogi]-$it[pnogi];

$nhp=$udata[hpall]-$it[hp];
$nmp=$udata[mpall]-$it[mp];
$nkrit=$udata[krit]-$it[krit];
$nukrit=$udata[ukrit]-$it[ukrit];

$nsila=$udata[sila]-$it[sila];
$nlovk=$udata[lovk]-$it[lovk];
$nprot=$udata[prot]-$it[prot];
$num=$udata[um]-$it[um];
$nanti=$udata[antikrit]-$it[antikrit];

mysql_query("UPDATE `users` SET
         `umin` = '$numin',
         `umax` = '$numax',
         `pgolova` = '$npgolova',
         `pbody` = '$npbody',
         `pnogi` = '$npnogi',
         `hpall` = '$nhp',
         `mpall` = '$nmp',
         `krit` = '$nkrit',
         `ukrit` = '$nukrit',
         `antikrit` = '$nanti',
         `sila` = '$nsila',
         `lovk` = '$nlovk',
         `um` = '$num',
         `prot` = '$nprot'
          WHERE usr = '$log'");

mysql_query("DELETE FROM `item` WHERE `usr` = '$log' and `tip`='weapon' and `image`='yes'");

$msg="Оружие не выдержало очередного заряда магии из свитка!<br/><b>Оружие $it[name] сломано!</b><br/>";
}
//////////////
if($mag[kol]==1){
mysql_query("DELETE FROM `res` WHERE `usr` = '$log' and `id`='$_GET[id]'");
}else{
$mag[kol]--;
mysql_query("UPDATE res SET kol = '$mag[kol]' WHERE `usr` = '$log' and `id`='$_GET[id]'");
}
break;
/////////////////////
case 'scroll_armor':
if(empty($_GET[tip])){
echo'<b>Заколдовать:</b><br/>';
echo"<a href=\"scroll.php?tip=golova&amp;id=$_GET[id]\">Шлем</a><br/>";
echo"<a href=\"scroll.php?tip=body&amp;id=$_GET[id]\">Доспехи</a><br/>";
echo"<a href=\"scroll.php?tip=shit&amp;id=$_GET[id]\">Щит</a><br/>";
echo"<a href=\"scroll.php?tip=plash&amp;id=$_GET[id]\">Плащ</a><br/>";
echo"<a href=\"scroll.php?tip=poyas&amp;id=$_GET[id]\">Пояс</a><br/>";
echo"<a href=\"scroll.php?tip=ruki&amp;id=$_GET[id]\">Рукавицы</a><br/>";
echo"<a href=\"scroll.php?tip=nogi&amp;id=$_GET[id]\">Сапоги</a><br/>";
echo"<a href=\"scroll.php?tip=amulet&id=$_GET[id]\">Амулет</a><br/>";
echo"<a href=\"scroll.php?tip=kolco&id=$_GET[id]\">Кольцо</a><br/>";
echo"<br/>";
}elseif(isset($_GET[tip]) and empty($_GET[what])){
echo"<a href=\"scroll.php?tip=$_GET[tip]&amp;what=pgolova&amp;id=$_GET[id]\">Защиту головы</a><br/>";
echo"<a href=\"scroll.php?tip=$_GET[tip]&amp;what=pbody&amp;id=$_GET[id]\">Защиту тела</a><br/>";
echo"<a href=\"scroll.php?tip=$_GET[tip]&amp;what=pnogi&amp;id=$_GET[id]\">Защиту ног</a><br/>";
}else{
if($_GET[tip]!=golova and $_GET[tip]!=kolco and $_GET[tip]!=amulet and $_GET[tip]!=body and $_GET[tip]!=nogi and $_GET[tip]!=shit and $_GET[tip]!=plash and $_GET[tip]!=ruki and $_GET[tip]!=poyas){
echo'Ошибка, доступ закрыт!';
include($path.'files/down.php');
exit;
}
if($_GET[what]!=pgolova and $_GET[what]!=pbody and $_GET[what]!=pnogi){
echo'Ошибка, доступ закрыт!';
include($path.'files/down.php');
exit;
}
$req = mysql_query("SELECT * FROM `item` WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `image`='yes' LIMIT 2");
$avto=mysql_num_rows($req);
if($avto=='0'){
echo'Ошибка, сначала наденьте вещь!';
include($path.'files/down.php');
exit;
}
$it = mysql_fetch_array($req);

$nprotect=$mag[give]+$udata[$_GET[what]];

$w=explode("*",$it[name]);
if(empty($w[1])){
$nam="$w[0]*1";
}else{
$kol=$w[1]+1;
$nam="$w[0]*$kol";}

if(empty($w[1])){$stavka=100;}
if($udata[prof] == 'Кузнец'){
if($w[1]==1){$stavka=100;}
if($w[1]==2){$stavka=90;}
if($w[1]==3){$stavka=80;}
if($w[1]==4){$stavka=70;}
if($w[1]==5){$stavka=60;}
if($w[1]==6){$stavka=50;}
if($w[1]==7){$stavka=40;}
if($w[1]==8){$stavka=35;}
if($w[1]==9){$stavka=30;}
}
else{
if($w[1]==1){$stavka=100;}
if($w[1]==2){$stavka=80;}
if($w[1]==3){$stavka=70;}
if($w[1]==4){$stavka=60;}
if($w[1]==5){$stavka=50;}
if($w[1]==6){$stavka=40;}
if($w[1]==7){$stavka=35;}
if($w[1]==8){$stavka=30;}
if($w[1]==9){$stavka=25;}}
if($w[1]>=10){
echo'Вещь заточена на максимум!';
include($path.'files/down.php');
exit;}

$priz=rand(1,100);

if($priz<=$stavka){

$num=$mag[give]+$it[$_GET[what]];
//
$req = mysql_query("SELECT * FROM `item` WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `image`='yes' LIMIT 2");
$aro = mysql_fetch_array($req);
//
mysql_query("UPDATE `users` SET `$_GET[what]` = '$nprotect' WHERE usr = '$log'");
mysql_query("UPDATE `item` SET
      `$_GET[what]` = '$num',
      `name` = '$nam'
       WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `image`='yes' and `id` = '$aro[id]'");
       
$msg="Защита увеличена!<br/>Новая защита: $nprotect<br/>";
}else{
$req = mysql_query("SELECT * FROM `item` WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `image`='yes'");
$it = mysql_fetch_array($req);

$numin=$udata[umin]-$it[umin];
$numax=$udata[umax]-$it[umax];
$npgolova=$udata[pgolova]-$it[pgolova];
$npbody=$udata[pbody]-$it[pbody];
$npnogi=$udata[pnogi]-$it[pnogi];
$nhp=$udata[hpall]-$it[hp];
$nmp=$udata[mpall]-$it[mp];
$nkrit=$udata[krit]-$it[krit];
$nukrit=$udata[ukrit]-$it[ukrit];

$nsila=$udata[sila]-$it[sila];
$nlovk=$udata[lovk]-$it[lovk];
$nprot=$udata[prot]-$it[prot];
$num=$udata[um]-$it[um];
$nanti=$udata[antikrit]-$it[antikrit];

mysql_query("UPDATE `users` SET
         `umin` = '$numin',
         `umax` = '$numax',
         `pgolova` = '$npgolova',
         `pbody` = '$npbody',
         `pnogi` = '$npnogi',
         `hpall` = '$nhp',
         `mpall` = '$nmp',
         `krit` = '$nkrit',
         `ukrit` = '$nukrit',
         `antikrit` = '$nanti',
         `sila` = '$nsila',
         `lovk` = '$nlovk',
         `um` = '$num',
         `prot` = '$nprot'
          WHERE usr = '$log'");
//
$req = mysql_query("SELECT * FROM `item` WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `image`='yes' LIMIT 2");
$aro = mysql_fetch_array($req);
//
mysql_query("DELETE FROM `item` WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `image`='yes' and `id` = '$aro[id]'");

$msg="Вещь не выдержала очередного заряда магии из свитка!<br/><b>Вещь $it[name] сломана!</b><br/>";
}
//////////////
if($mag[kol]==1){
mysql_query("DELETE FROM `res` WHERE `usr` = '$log' and `id`='$_GET[id]'");
}else{
$mag[kol]--;
mysql_query("UPDATE res SET kol = '$mag[kol]' WHERE `usr` = '$log' and `id`='$_GET[id]'");
}
///////////////
}
break;
}
///////
echo"$msg";
echo"<a href=\"inventar.php?\">Назад</a>";
include($path.'files/down.php');
?>