<?php
require_once ('../system/func.php');
auth();


if(isset($_GET['pit_kup']))
{
$id = abs(intval($_GET['pit_kup']));
if($id)$pit = mysql_fetch_assoc(mysql_query("SELECT * FROM `pits` WHERE `id` = '".$id."'"));
if(!$pit){
$_SESSION['msg'] == 'Такой питомец не существует';
header('Location: /rinok?act=pit');
exit();
}
$k_pit = mysql_result(mysql_query("SELECT COUNT(*) FROM `pit_users` WHERE `id_user` = '$myID'"),0);
if($k_pit == 1)
{
if($user['gold'] < ceil($pit['cena']*50/100))
{
$_SESSION['msg'] = "Не хватает <img src='/images/icons/gold.png' width='15px' alt='*' /> ".(ceil($pit['cena']*50/100)-$user['gold'])." золота";
header('Location: ?');
exit();
}
mysql_query("update `pit_users` set 
`name` = '".$pit['name']."', 
`item` = '".$pit['item']."'
where (`id_user` = '".$myID."')");
mysql_query("update `users` set 
`gold` = '".($user['gold']-ceil($pit['cena']*50/100))."' where (`id` = '".$myID."')");
$_SESSION['msg'] = "Питомец успешно куплен";
header('Location: ?');
exit();
}
else
{
if($user['gold'] < $pit['cena'])
{
$_SESSION['msg'] = "Не хватает <img src='/images/icons/gold.png' width='15px' alt='*' /> ".($pit['cena']-$user['gold'])." золота";
header('Location: ?');
exit();
}
else
{
mysql_query("update `users` set 
`gold` = '".($user['gold']-$pit['cena'])."', 
`str` = '".($user['str']+$pit['str'])."', 
`def` = '".($user['def']+$pit['def'])."', 
`max_health` = '".($user['max_health']+$pit['health'])."'
where (`id` = '".$myID."')");
mysql_query("INSERT INTO `pit_users` SET 
`id_user` = '$myID', 
`name` = '$pit[name]', 
`str` = '$pit[str]', 
`def` = '$pit[def]', 
`health` = '$pit[health]', 
`item` = '$pit[item]'");
$_SESSION['msg'] = 'Питомец куплен';
header('Location: ?');
exit();
}
}
}
if(isset($_GET['pit']))
{
$id = abs(intval($_GET['pit']));
if($id)$pit = mysql_fetch_assoc(mysql_query("SELECT * FROM `pits` WHERE `id` = '".$id."'"));
if(!$pit){
$_SESSION['msg'] == 'Такой питомец не существует';
header('Location: ?');
exit();
}
$k_pit = mysql_result(mysql_query("SELECT COUNT(*) FROM `pit_users` WHERE `id_user` = '$myID'"),0);
$title = $pit['name'];
require_once ('system/header.php');
echo "<div class='block'>";
echo "<div class='oh'><img src='/images/pits/$pit[item].png' style='margin-right:3px;margin-top:-2px;'></div>".ico('icons','pit.png')." $pit[name]<br>Питомец увеличет ваши параметры";
echo "<div style='clear:both;'></div>";
echo "</div>";
echo "<div class='block center'>";
echo ico('icons','str.png')." $pit[str] ";
echo ico('icons','def.png')." $pit[def] ";
echo ico('icons','health.png')." $pit[health]<br>";
if($k_pit == 0)echo "<a href='/rinok?pit_kup=$pit[id]' class='btn2'>Купить за ".ico('icons','gold.png')." $pit[cena] золота</a>";
else echo "<a href='/rinok?pit_kup=$pit[id]' class='btn2'>Заменить ".ico('icons','gold.png')." за ".ceil($pit['cena']*50/100)." золота</a>";
echo "</div>";
echo "<a href='?act=pit' class='link'>".ico('icons','arrow.png')." Вернуться назад</a>";
require_once ('system/footer.php');
break;
}
if(isset($_GET['komplekt'])){
$id = abs(intval($_GET['komplekt']));
if($id)$komplekt = mysql_fetch_assoc(mysql_query("SELECT * FROM `komplekt` WHERE `id` = '".$id."'"));
if(!$komplekt){
$_SESSION['msg'] == 'Такой комплект не существует';
header('Location: /rinok?act=shop');
exit();
}
$title = $komplekt['name'];
require_once ('../system/header.php');
$cena = 0;
for($item = 1; $item < 9; $item++){
$q = mysql_fetch_array(mysql_query("SELECT * FROM `item` WHERE `id_komplekt` = '$id' ORDER BY `id` ASC"));
$cena += $q[cena];
}
## Акция ##
if($auction == 1 and $auction_name == 'shop' and $user['auction'] >= $auction_summa)$cena -= ceil($cena*$auction_skidka/100);
###########
if(isset($_GET[pay])){
if($user[gold] < $cena){
$_SESSION[msg] = "Не хватает ".ico('icons','gold.png')." ".($cena-$user[gold])." золота";
header("Location: ?komplekt=$id");
exit();
}
if(mysql_result(mysql_query('SELECT COUNT(*) FROM `inv` WHERE `odeta` = "0" AND `id_user` = "'.$myID.'"'),0) + 8 > 20) {
$_SESSION[msg] = 'В сумке не хватает места';
header("Location: ?komplekt=$id");
exit();
}
for($items = 1; $items < 9; $items++){
if($items == 1)$tip = 'golova';
if($items == 2)$tip = 'plechi';
if($items == 3)$tip = 'tors';
if($items == 4)$tip = 'perchatki';
if($items == 5)$tip = 'lev';
if($items == 6)$tip = 'prav';
if($items == 7)$tip = 'nogi';
if($items == 8)$tip = 'obuv';
$random = rand(19999,99999);
$item = mysql_fetch_array(mysql_query("SELECT * FROM `item` WHERE `id_komplekt` = '$komplekt[id]' AND `tip` = '$tip'"));
mysql_query("INSERT INTO `inv` SET 
`id` = '$random',
`id_user` = '$myID', 
`name` = '$item[name]', 
`str` = '$item[str]', 
`def` = '$item[def]', 
`health` = '$item[health]', 
`tip` = '$item[tip]', 
`skill` = '$item[skill]', 
`odeta` = 'net' , 
`item` = '$item[item]'");
}
mysql_query("update `users` set `gold` = '".($user[gold]-$cena)."' where (`id` = '".$myID."')");
$_SESSION[msg] = "$komplekt[name] успешно куплен";
header('Location: /inv');
exit();
}
if($user['skill'] >= $komplekt['skill'])
{
echo "<a href='?komplekt=$id&pay' class='btn'><img src='/style/style/shield.png'> 
<span class='money'>Купить комплект за</span> <img src='/style/style/gold.png'> $cena</a>";
}
echo "<div class='content'><img src='/shopimage/$komplekt[id].png'></div>";

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `item` WHERE `id_komplekt` = '$id'"),0);
$q = mysql_query("SELECT * FROM `item` WHERE `id_komplekt` = '$id' ORDER BY `id` ASC");
if($k_post == 0)
{echo "<div class='blt minor'>В комплекте нет вещей</div>";
}

while($post = mysql_fetch_assoc($q))
{
echo "<a href='/itemshop/$post[id]' class='btn' title='".$post[name]."'>".ico("snop","$post[skill].png")."
<span class='item-".skill($post[skill])."'>$post[name]</span></a>";
}


echo "<a href='?act=skill_$komplekt[skill]' class= 'btn'><img src='/style/style/feather.png'> Назад</a>";
require_once ('../system/footer.php');
break;
}

switch($_GET['act'])
{
case 'koldun':
$title = 'Таверна';
require_once ('system/header.php');
echo '<img src="images/other/koldun.png" class="example_beauty" style="width:100%;border-radius:0px">';
echo "<div class='content'>Здравствуй $myLogin <br/> я могу восстановить тебе 100% <img src='/style/style/health.png' width='12px' 'alt='*' /> <img src='/style/style/regen.png' width='12px' 'alt='*' /></div>";
echo "<a class='btn' href='?koldun&url=/rinok?act=koldun'>Восстановить за <img src='/style/style/gold.png' width='12px' 'alt='*' /> <span class='money'>15</span></a>";
break;

case 'shop':
$title = 'Магазин снаряжения';
require_once ('../system/header.php');
echo '<div class="content"><h3>Магазин снаряжения</h3></div>';
echo "<a class='btn' ".($user['skill'] >= 100 ? "href='?act=skill_100'" : "").">".ico('snop','100.png')."  <span class='item-5'>Божественные вещи</span></a>";
echo "<a class='btn' ".($user['skill'] >= 48 ? "href='?act=skill_48'" : "").">".ico('snop','48.png')."<span class='item-4'>Легендарные вещи</span></a>";
echo "<a class='btn' ".($user['skill'] >= 26 ? "href='?act=skill_26'" : "").">".ico('snop','26.png')." <span class='item-3'>Эпические вещи</span></a>";
echo "<a class='btn' ".($user['skill'] >= 10 ? "href='?act=skill_10'" : "").">".ico('snop','10.png')." <span class='item-2'>Редкие вещи</span></a>";
echo "<a class='btn' ".($user['skill'] >= 1 ? "href='?act=skill_1'" : "").">".ico('snop','1.png')." <span class='item-1'>Простые вещи</span></a>";

if($user['skill'] == 0)
{
echo "<a class='btn' href='/train'>".ico('icons','train.png')."Тренировка</a>";
}


break;
case 'skill_1':
$title = 'Простые вещи';
require_once ('../system/header.php');
if($user['skill'] < 1)
{ 
$_SESSION['msg'] = "У вас не достаточно мастерства"; 
exit(header('Location: ?act=shop')); 
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `komplekt` WHERE `skill` = '1'"),0);
$q = mysql_query("SELECT * FROM `komplekt` WHERE `skill` = '1' ORDER BY `id` ASC");
if($k_post == 0)
{
echo "<div class='blt minor'>Торговая лавка пуста</div>";
}
while($post = mysql_fetch_assoc($q))
{
echo "<a href='?komplekt=$post[id]' class='btn' title='".$post[name]."'>".ico("snop","$post[skill].png")." $post[name]</a>";
echo "<div class='content'><img src='/shopimage/$post[id].png'></div>";
}



echo "<a href='?act=shop' class= 'btn'><img src='/style/style/feather.png'> Назад</a>";
break;
case 'skill_10':
$title = '../Редкие вещи';
require_once ('system/header.php');
if($user['skill'] < 10) { 
$_SESSION['msg'] = "<font color=''>У вас не достаточно мастерства...</font>"; 
exit(header('Location: ?act=shop')); 
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `komplekt` WHERE `skill` = '1'"),0);
$q = mysql_query("SELECT * FROM `komplekt` WHERE `skill` = '10' ORDER BY `id` ASC");
if($k_post == 0)echo "<div class='block'>Торговая лавка пуста</div>";
echo "<div class='block2'>";
while($post = mysql_fetch_assoc($q)) {
echo "<li><a href='?komplekt=$post[id]'>".ico("snop","$post[skill].png")."$post[name]</a></li><li class='original center'><a><img src='/shopimage/[id].png'></a></li>";
}
echo "</div>";
echo "<a href='?act=shop' class= ".$user[oformlenie]." data-ajax>".ico('icons','arrow.png')." Вернуться назад</a>";
break;
case 'skill_26':
$title = 'Эпические вещи';
require_once ('../system/header.php');
if($user['skill'] < 26) { 
$_SESSION['msg'] = "<font color=''>У вас не достаточно мастерства...</font>"; 
exit(header('Location: ?act=shop')); 
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `komplekt` WHERE `skill` = '26'"),0);
$q = mysql_query("SELECT * FROM `komplekt` WHERE `skill` = '26' ORDER BY `id` ASC");
if($k_post == 0)echo "<div class='block'>Торговая лавка пуста</div>";
echo "<div class='block2'>";
while($post = mysql_fetch_assoc($q)) {
echo "<li><a href='?komplekt=$post[id]'>".ico("snop","$post[skill].png")."$post[name]</a></li><li class='original center'><a><img src='/shopimage/$post[id].png'></a></li>";
}
echo "</div>";
echo "<a href='?act=shop' class= ".$user[oformlenie]." data-ajax>".ico('icons','arrow.png')." Вернуться назад</a>";
break;
case 'skill_48':
$title = 'Легендарные вещи';
require_once ('../system/header.php');
if($user['skill'] < 48) { 
$_SESSION['msg'] = "<font color=''>У вас не достаточно мастерства...</font>"; 
exit(header('Location: ?act=shop')); 
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `komplekt` WHERE `skill` = '48'"),0);
$q = mysql_query("SELECT * FROM `komplekt` WHERE `skill` = '48' ORDER BY `id` ASC");
if($k_post == 0)echo "<div class='block'>Торговая лавка пуста</div>";
echo "<div class='block2'>";
while($post = mysql_fetch_assoc($q)) {
echo "<li><a href='?komplekt=$post[id]'>".ico("snop","$post[skill].png")."$post[name]</a></li><li class='original center'><a><img src='/shopimage/$post[id].png'></a></li>";
}
echo "</div>";
echo "<a href='?act=shop'class= ".$user[oformlenie]." data-ajax >".ico('icons','arrow.png')." Вернуться назад</a>";
break;
case 'skill_100':
$title = 'Божественные вещи';
require_once ('../system/header.php');
if($user['skill'] < 100) { 
$_SESSION['msg'] = "<font color=''>У вас не достаточно мастерства...</font>"; 
exit(header('Location: ?act=shop')); 
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `komplekt` WHERE `skill` = '100'"),0);
$q = mysql_query("SELECT * FROM `komplekt` WHERE `skill` = '100' ORDER BY `id` ASC");
if($k_post == 0)echo "<div class='block'>Торговая лавка пуста</div>";
echo "<div class='block2'>";
while($post = mysql_fetch_assoc($q)) {
echo "<li><a href='?komplekt=$post[id]'>".ico("snop","$post[skill].png")."$post[name]</a></li><li class='original center'><a><img src='/shopimage/$post[id].png'></a></li>";
}
echo "</div>";
echo "<a href='?act=shop' class= ".$user[oformlenie]." data-ajax>".ico('icons','arrow.png')." Вернуться назад</a>";
break;
case 'pit':
$title = 'Магазин питомцев';
require_once ('../system/header.php');
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `pits`"),0);
$q = mysql_query("SELECT * FROM `pits` ORDER BY `id` ASC");
echo "<div class='block2'>";
if($k_post == 0)echo "<h1>Торговая лавка пуста</h1>";
while($post = mysql_fetch_assoc($q)) {
echo "<li><a href='?pit=$post[id]'>". ico('icons','pit.png')."$post[name]</a></li>";
}
echo "</div>";
echo "<a href='?' class= ".$user[oformlenie]." data-ajax>".ico('icons','arrow.png')." Вернуться назад</a>";
break;
default:
$title = 'Рынок';
require_once ('../system/header.php');
?>
<div class="mess_blue">Рынок</div>
<div class="taverna_logo"></div>
<a class="btn" href="/taverna" title="Таверна"><div class="icn tavern"></div>Таверна</a>
<a class="btn" href="/merchant" title="Лавочник"><div class="icn band2"></div>Старый лавочник</a>
<a class="btn"href="/effects" title="Городской бонус"><div class="icn bonus"></div>Городской бонус</a>
<a class="btn"  href="/smitch" title="Кузнец"><div class="icn band"></div>Кузнец</a>
<a class="btn" href="?act=shop" title="Магазин снаряжения"><div class="icn shop"></div>Магазин снаряжения</a>
<a class="btn" href="?act=pit" title="Питомник"><div class="icn dungeon"></div>Питомник</a>
<?
}
require_once ('../system/footer.php');
?>