<?php
include 'core/sys.php';
head('Инвентарь');
reg();
if(!empty($_GET['id']) and isset($_GET['id']) and isset($_GET['sell'])){
include 'inc/invent_sell.php';
}elseif(!empty($_GET['id']) and isset($_GET['id']) and isset($_GET['use'])){
include 'inc/invent_use.php';
}elseif(!empty($_GET['id']) and isset($_GET['id']) and isset($_GET['deuse'])){
include 'inc/invent_deuse.php';
}elseif(isset($_GET['cat'])){
$cat = int($_GET['cat']);
$total = mysql_num_rows(mysql_query("SELECT `id` FROM `inventory_user` WHERE `user_id`='".$user['id']."' AND `cat_id`='".$cat."' AND `kol`>0"));
$sql = mysql_query("SELECT * FROM `inventory_user` WHERE `user_id`='".$user['id']."' AND `cat_id`='".$cat."' AND `kol`>0 ORDER BY `id` DESC LIMIT ".$page.",".$set['str']."");
if(!$sql){
	echo '<div id="error">Инвентарь пуст!</div>';
	foot();
	exit;
}
if($total==0){
	echo '<div id="error">Инвентарь пуст!</div>';
	foot();
	exit;
}
while($row = mysql_fetch_assoc($sql)){
$row_inv = mysql_fetch_assoc(mysql_query("SELECT * FROM `inventory` WHERE `id`='".$row['invent_id']."'"));
echo '<div class="row"><img src="/'.$row_inv['img'] .'" alt=""> '.$row_inv['name'].' ['.$row['kol'].'] <br>';
if($user['weapon']==$row['invent_id']){
echo 'Крепкость: '.$row['krepost'].'<br>';
}
if($row_inv['cat_id']==1){
echo '<a href="inventory.php?id='.$row['id'].'&amp;use">Использовать</a><br>';
}else{
/* статы */
if($row_inv['hp']>0){
echo 'HP: +'.$row_inv['hp'].'<br>';
}
if($row_inv['mp']>0){
echo 'MP: +'.$row_inv['mp'].'<br>';
}
if($row_inv['strength']>0){
echo 'Сила: +'.$row_inv['strength'].'<br>';
}
if($row_inv['defense']>0){
echo 'Защита: +'.$row_inv['defense'].'<br>';
}
if($row_inv['hp_recovery']>0){
echo 'Восстанавливает HP: +'.$row_inv['hp_recovery'].'<br>';
}
if($row_inv['mp_recovery']>0){
echo 'Восстанавливает MP: +'.$row_inv['mp_recovery'].'<br>';
}
if($row_inv['virus']>0){
echo 'Регенерация HP: -'.$row_inv['virus'].'<br>';
}
if($row_inv['vak']>0){
echo 'Регенерация HP: +'.$row_inv['vak'].'<br>';
}
	
	/* проверяем одето ли*/
	if($row['invent_id'] ==  $user['armor']){
	echo '<br>[<b> надето </b>]<br>';
	 echo '<a href="inventory.php?id='.$row['id'].'&amp;deuse">Снять</a><br>';
	}elseif($row['invent_id'] ==  $user['helmet']){
	echo '<br>[<b> надето </b>]<br>';
	echo '<a href="inventory.php?id='.$row['id'].'&amp;deuse">Снять</a><br>';
	}elseif($row['invent_id'] ==  $user['shoes']){
	echo '<br>[<b> надето </b>]<br>';
	echo '<a href="inventory.php?id='.$row['id'].'&amp;deuse">Снять</a><br>';
	}
	elseif($row['invent_id'] ==  $user['gloves']){
	echo '<br>[<b> надето </b>]<br>';
	echo '<a href="inventory.php?id='.$row['id'].'&amp;deuse">Снять</a><br>';
	}
	elseif($row['invent_id'] ==  $user['amulet']){
	echo '<br>[<b> надето </b>]<br>';
	echo '<a href="inventory.php?id='.$row['id'].'&amp;deuse">Снять</a><br>';
	}
	elseif($row['invent_id'] ==  $user['weapon']){
	echo '<br>[<b> надето </b>]<br>';
	echo '<a href="inventory.php?id='.$row['id'].'&amp;deuse">Снять</a><br>';
	}
	else{
	if($row_inv['virus']==0){
	 echo '<a href="inventory.php?id='.$row['id'].'&amp;use">Использовать</a><br>';
	 }
	}
 }
 echo '<a href="inventory.php?id='.$row['id'].'&amp;sell">Продать</a><br>';

echo '</div>';
}
  if($total > $set['str'])
	{
		pages($page, $total, 'inventory.php?cat='.$cat.'&amp;', $set['str']);
	}
}else{
$sql_cat = mysql_query("SELECT * FROM `inventory_cat`");
$test_inv_u = mysql_query("SELECT * FROM `inventory_user` WHERE `user_id`='".$user['id']."'");
$test_inv_2 = mysql_result(mysql_query("SELECT COUNT(id) FROM `inventory_user` WHERE `user_id`='".$user['id']."' AND `kol`>0"),0);
if(!$test_inv_u or $test_inv_2==0){
	echo '<div id="error">Инвентарь пуст!</div>';
	foot();
	exit;
}

while($row_cat = mysql_fetch_assoc($sql_cat)){
$c_inv = mysql_result(mysql_query("SELECT SUM(`kol`) FROM `inventory_user` WHERE `user_id`='".$user['id']."' AND `cat_id`='".$row_cat['id']."'"),0);
if($c_inv > 0){
echo '<div class="row"><a href="inventory.php?cat='.$row_cat['id'].'">'.$row_cat['cat_name'].'</a> ('.$c_inv.')<br></div>';
}
}
	if(!empty($_GET['monstr']) and !empty($_GET['room'])){
	$id = int($_GET['monstr']);
	$room = int($_GET['room']);
	echo '<div class="row"><a id="link_button" href="attack.php?monstr='.$id.'&amp;room='.$room.'">обратно к монстру</a></div>';
	}
}
foot();
?>