battles/shop.php
Igor Barkov [iwork] 378633b720 buy item fix
2019-01-14 19:19:11 +02:00

337 lines
15 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
ob_start();
session_start();
if ($_SESSION['uid'] == null) header("Location: index.php");
require_once("functions.php");
if ($user['room'] != 22) {
header("Location: main.php");
die();
}
if ($user['battle'] != 0) {
header('location: fbattle.php');
die();
}
$sellItemId = filter_input(INPUT_GET, 'sellitem');
$saleItems = false;
if ($sellItemId && is_numeric($sellItemId)) {
$dress = db::c()->query('SELECT `id`, `name`, `cost`, `type`, `duration`, `maxdur`, `goden`, `dategoden`, `koll` FROM `inventory` WHERE `dressed` = 0 AND `id` = ?i AND `owner` = ?i', $sellItemId, $user['id'])->fetch_assoc();
$price = $dress['cost'] * 1;
$kols = '';
if ($dress['koll']) {
$price *= $dress['koll'];
$kols = '(x' . $dress['koll'] . ')';
}
destructitem($dress['id']);
if ($dress['type'] == 12) {
$allcost = round($price * (1 - $dress['duration'] / $dress['maxdur']), 2);
} else {
$allcost = round($price - $dress['duration'] * ($dress['cost'] / ($dress['maxdur'] * 10)), 2);
}
if ($dress['goden'] != 0) {
$goden_max = $dress['goden'] * 24 * 60;
$goden_left = ($dress['dategoden'] - time()) / 60;
$per = $goden_left / $goden_max;
$allcost = round(($allcost * $per), 2);
}
$user['money'] += $allcost;
$deloText = "\"" . $user['login'] . "\" продал в магазин товар : \"" . $dress['name'] . "\" $kols id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] за " . $allcost . " кр. ";
db::c()->query('UPDATE `users` SET `money` = ?i WHERE `id` = ?i', $user['money'], $user['id']);
db::c()->query('INSERT INTO `delo` (`pers`, `text`, `type`, `date`) VALUES (?i, "?s", 1, ?i)', $user['id'], $deloText, time());
echo "<b style='color: red;'>Вы продали \"{$dress['name']}\" $kols за " . $allcost . " кр.</b>";
}
if (!empty($_GET['buy'])) {
$dress = db::c()->query('SELECT * FROM `shop` WHERE `id`=?i', $_GET['buy'])->fetch_assoc();
if (($dress['massa'] + $itemWeight['m']) > (get_meshok())) {
err('Недостаточно места в рюкзаке.');
} elseif ($user['money'] >= $dress['cost'] AND ($dress['count'] > 0 OR $dress['count'] == -1)) {
$newItem = [
'prototype' => $dress['id'],
'owner' => $user['id'],
'name' => $dress['name'], //s
'type' => $dress['type'],
'massa' => $dress['massa'],
'cost' => $dress['cost'],
'img' => $dress['img'], //s
'maxdur' => $dress['maxdur'],
'isrep' => $dress['isrep'],
'gsila' => $dress['gsila'],
'glovk' => $dress['glovk'],
'ginta' => $dress['ginta'],
'gintel' => $dress['gintel'],
'ghp' => $dress['ghp'],
'gnoj' => $dress['gnoj'],
'gtopor' => $dress['gtopor'],
'gdubina' => $dress['gdubina'],
'gmech' => $dress['gmech'],
'gfire' => $dress['gfire'],
'gwater' => $dress['gwater'],
'gair' => $dress['gair'],
'gearth' => $dress['gearth'],
'glight' => $dress['glight'],
'ggray' => $dress['ggray'],
'gdark' => $dress['gdark'],
'needident' => $dress['needident'],
'nsila' => $dress['nsila'],
'nlovk' => $dress['nlovk'],
'ninta' => $dress['ninta'],
'nintel' => $dress['nintel'],
'nmudra' => $dress['nmudra'],
'nvinos' => $dress['nvinos'],
'nnoj' => $dress['nnoj'],
'ntopor' => $dress['ntopor'],
'ndubina' => $dress['ndubina'],
'nmech' => $dress['nmech'],
'bron1' => $dress['bron1'],
'bron2' => $dress['bron2'],
'bron3' => $dress['bron3'],
'bron4' => $dress['bron4'],
'minu' => $dress['minu'],
'maxu' => $dress['maxu'],
'magic' => $dress['magic'],
'nlevel' => $dress['nlevel'],
'nalign' => $dress['nalign'],
'dategoden' => $dress['dategoden'],
'goden' => $dress['goden'],
'otdel' => $dress['otdel'],//s
'gmp' => $dress['gmp'],
'gmeshok' => $dress['gmeshok'],
'encicl' => $dress['encicl'],//s
'artefact' => $dress['artefact'],
'koll' => $dress['koll']
];
db::c()->query('INSERT INTO `inventory` SET ?A[?i,?i,"?s",?i,?i,?i,"?s",?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,"?s",?i,?i,"?s",?i,?i]', $newItem);
if ($dress['count'] != -1) db::c()->query('UPDATE `shop` SET `count` = `count` - ?i WHERE `id` = ?i', $count, $set);
echo "<b style='color: red'>Вы купили {$count} шт. \"{$dress['name']}\".</b>";
$user['money'] -= $count * $dress['cost'];
db::c()->query('UPDATE `users` set `money` = ?i WHERE `id` = ?i', $user['money'], $user['id']);
$invdb = db::c()->query('SELECT `id` FROM `inventory` WHERE `name` = "?s" ORDER BY `id` DESC LIMIT ?i', $dress['name'], $count);
$dressinv = $invdb->fetch_assoc();
$dressid = "cap" . $dressinv['id'];
$deloText = "\"" . $user['login'] . "\" купил товар : \"" . $dress['name'] . " id:(" . $dressid . ") [0/" . $dress['maxdur'] . "] за " . $dress['cost'] . " кр.";
db::c()->query('INSERT INTO `delo` (`pers`, `text`, `type`, `date`) VALUES (?i, "?s", 1, ?i', $user['id'], $deloText, time());
} else {
echo "<b style='color: red;'>Недостаточно денег или нет вещей в наличии.</b>";
}
}
$itemWeight = db::c()->query('SELECT sum(`massa`) AS `m` FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `setsale` = 0', $user['id'])->fetch_assoc();
$shopCategoryType = empty($_POST['sale']) ?: $_POST['sale'];
$shopCategoryTypeNumber = empty($_GET['otdel']) ?: $_GET['otdel'];
switch ($shopCategoryTypeNumber) {
default:
$shopCategoryType = "Предметы в инвентаре";
$saleItems = true;
break;
case 1:
$shopCategoryType = "Кастеты и ножи";
break;
case 11:
$shopCategoryType = "Топоры";
break;
case 12:
$shopCategoryType = "Дубины и булавы";
break;
case 13:
$shopCategoryType = "Мечи";
break;
case 2:
$shopCategoryType = "Сапоги";
break;
case 21:
$shopCategoryType = "Перчатки";
break;
case 22:
$shopCategoryType = "Легкая броня";
break;
case 23:
$shopCategoryType = "Тяжелая броня";
break;
case 24:
$shopCategoryType = "Шлемы";
break;
case 3:
$shopCategoryType = "Щиты";
break;
case 4:
$shopCategoryType = "Серьги";
break;
case 41:
$shopCategoryType = "Ожерелья";
break;
case 42:
$shopCategoryType = "Кольца";
break;
case 5:
$shopCategoryType = "Заклинания: нейтральные";
break;
case 51:
$shopCategoryType = "Заклинания: боевые и защитные";
break;
case 6:
$shopCategoryType = "Амуниция";
break;
case 52:
$shopCategoryType = "Руны";
break;
}
$shopItems = db::c()->query('SELECT `shop`.*,
`magic`.`name` AS `magic_name`,
`magic`.`chanse` AS `magic_chanse`,
`magic`.`time` AS `magic_time`,
`magic`.`file` AS `magic_file`,
`magic`.`targeted` AS `magic_targeted`,
`magic`.`needcharge` AS `magic_needcharge`,
`magic`.`img` AS `magic_img`
FROM `shop` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `count` > 0 AND `cost` > 0 AND `razdel` = ?i ORDER by `nlevel` ASC, `id` ASC', $shopCategoryTypeNumber);
$iteminfo =[];
while ($row = $shopItems->fetch_assoc()) {
$iteminfo[] = new ShopItem($row);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="css/main.css" rel="stylesheet"/>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.simplemodal.js"></script>
<script src="js/jquery.ui.js?100"></script>
<script src="js/mi.js"></script>
<link rel="stylesheet" href="css/bkstyle.css?101"/>
<link rel="stylesheet" href="css/mi.css"/>
<style>
.row {
font-family: Tahoma, sans-serif;
font-size: 13px;
}
</style>
<script>
function leave() {
top.frames['main'].location = 'city.php?cp'
}
</script>
</head>
<body>
<h1>Государственный магазин</h1>
<a href=# onclick=leave()> ← выйти на Центральную площадь</a>
<TABLE width=100% cellspacing="0" cellpadding="4">
<TR>
<TD valign=top align=left>
<!--Магазин-->
<TABLE border=0 width=100% cellspacing="0" cellpadding="0" bgcolor="#A5A5A5">
<TR>
<TD align=center>
<h3><?= $shopCategoryType ?></h3>
<?php if ($saleItems): ?>
Вы можете продать ваши предметы за 10% от стоимости.
<?php endif; ?>
</TD>
</TR>
<TR>
<TD>
<TABLE class="zebra" WIDTH=100% CELLSPACING="1" CELLPADDING="2" BGCOLOR="#A5A5A5">
<?php
if ($saleItems == true) {
// Выбираем всё потому что эту выборку потом использует showitem();
$data = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `setsale` = 0 AND `cost` > 0 AND `present` = "?s" AND `tradesale` = 0 AND `podzem` = 0 ORDER BY `update` DESC', $user['id'], null);
while ($row = $data->fetch_assoc()) {
$row['count'] = 1;
$price = $row['cost'] * 0.1;
if ($row['koll']) {
$price *= $row['koll'];
}
if ($row['type'] == 12) {
$allcost = round($price * (1 - $row['duration'] / $row['maxdur']), 2);
} else {
$allcost = round($price - $row['duration'] * ($row['cost'] / ($row['maxdur'] * 10)), 2);
}
if ($row['goden'] != 0) {
$goden_max = $row['goden'] * 24 * 60;
$goden_left = ($row['dategoden'] - time()) / 60;
$per = $goden_left / $goden_max;
$allcost = round(($allcost * $per), 2);
}
?>
<tr>
<td align=center style='width: 150px;'>
<img src="i/sh/<?= $row['img'] ?>" border=0>
<br><a href="shop.php?sellitem=<?= $row['id'] ?>&sid=&sale=1">продать
за <?= $allcost ?></a>
</td>
<td valign=top class="row">
<?php showitem($row); ?>
</td>
</tr>
<?php
}
} else {
foreach ($iteminfo as $ii) {
echo "<tr><td style='width: 150px; text-align: center;'>";
$ii->printImage();
$ii->printControls();
echo "</td>";
echo "<td style='vertical-align: top;'>";
$ii->printInfo();
echo "</td></tr>";
}
}
?>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
<TD valign=top width=280>
<B>Масса всех ваших вещей: <?= getItemsMassaInfo() ?>
<BR>У вас в наличии: <span style="color: darkgreen;"><?= $user['money'] ?></span> кр.</B>
<hr>
<a href="shop.php?otdel=sale&rnd=<?= mt_rand() ?>">Продать вещи</a>
<dl>
<dt><b>Оружие:</b></dt>
<dd><a href="shop.php?otdel=1&rnd=<?= mt_rand() ?>">кастеты,ножи</a></dd>
<dd><a href="shop.php?otdel=11&rnd=<?= mt_rand() ?>">топоры</a></dd>
<dd><a href="shop.php?otdel=12&rnd=<?= mt_rand() ?>">дубины,булавы</a></dd>
<dd><a href="shop.php?otdel=13&rnd=<?= mt_rand() ?>">мечи</a></dd>
<dt><b>Одежда:</b></dt>
<dd><a href="shop.php?otdel=24&rnd=<?= mt_rand() ?>">шлемы</a></dd>
<dd><a href="shop.php?otdel=23&rnd=<?= mt_rand() ?>">тяжелая броня</a></dd>
<dd><a href="shop.php?otdel=22&rnd=<?= mt_rand() ?>">легкая броня</a></dd>
<dd><a href="shop.php?otdel=3&rnd=<?= mt_rand() ?>">щиты</a></dd>
<dd><a href="shop.php?otdel=21&rnd=<?= mt_rand() ?>">перчатки</a></dd>
<dd><a href="shop.php?otdel=2&rnd=<?= mt_rand() ?>">сапоги</a></dd>
<dt><b>Ювелирные товары:</b></dt>
<dd><a href="shop.php?otdel=4&rnd=<?= mt_rand() ?>">серьги</a></dd>
<dd><a href="shop.php?otdel=41&rnd=<?= mt_rand() ?>">ожерелья</a></dd>
<dd><a href="shop.php?otdel=42&rnd=<?= mt_rand() ?>">кольца</a></dd>
<dt><b>Магия:</b></dt>
<dd><a href="shop.php?otdel=51&rnd=<?= mt_rand() ?>">боевые</a></dd>
<dd><a href="shop.php?otdel=5&rnd=<?= mt_rand() ?>">разные</a></dd>
<dt><b>Разное:</b></dt>
<dd><a href="shop.php?otdel=6&rnd=<?= mt_rand() ?>">амуниция</a></dd>
<dd><a href="shop.php?otdel=52&rnd=<?= mt_rand() ?>">руны</a></dd>
</dl>
<div id="hint3" class="ahint"></div>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>