battles/ashop.php

358 lines
23 KiB
PHP
Raw Normal View History

2018-01-28 16:40:49 +00:00
<?php
session_start();
if ($_SESSION['uid'] == null) header("Location: index.php");
include "config.php";
include "functions.php";
2018-06-22 14:52:29 +00:00
if ($user['room'] != 50) {
header("Location: main.php");
die();
}
$itemWeight = db::c()->query('SELECT sum(`massa`) AS `m` FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `setsale` = 0', $user['id'])->fetch_assoc();
if ($user['battle'] != 0) {
header('location: fbattle.php');
die();
}
2018-01-28 16:40:49 +00:00
2018-06-22 16:46:48 +00:00
$bank = db::c()->query('SELECT `ekr` FROM `bank` WHERE `id`=?i', $_SESSION['uid'])->fetch_assoc();
2018-01-28 16:40:49 +00:00
2018-06-22 20:43:23 +00:00
if (isset($_GET['set']) OR isset($_POST['set'])) {
2018-06-22 19:33:11 +00:00
$set = empty($_GET['set']) ?: $_GET['set'];
$set = empty($_POST['set']) ?: $_POST['set'];
$count = isset($_POST['count']) && is_numeric($_POST['count']) ? $_POST['count'] : 0;
if ($count < 1) {
$count = 0;
2018-06-22 14:52:29 +00:00
$count_ok = 0;
} else $count_ok = 1;
2018-01-28 16:40:49 +00:00
2018-06-22 16:46:48 +00:00
$dress = db::c()->query('SELECT * FROM `ashop` WHERE `id`=?i', $set)->fetch_assoc();
2018-06-22 14:52:29 +00:00
if ($count_ok == 0) {
err('Неправильно введено количество.');
2018-06-22 14:52:29 +00:00
} elseif (($dress['massa'] * $_POST['count'] + $itemWeight['m']) > (get_meshok())) {
err('Недостаточно места в рюкзаке.');
2018-06-22 14:52:29 +00:00
} elseif ($count_ok == 1 && ($bank['ekr'] >= ($dress['ecost'] * $_POST['count'])) && ($dress['count'] >= $_POST['count'])) {
for ($k = 1; $k <= $_POST['count']; $k++) {
2018-06-22 20:43:23 +00:00
$goden = '';
2018-06-22 16:46:48 +00:00
if (isset($dress['goden'])) $goden = $dress['goden'] * 24 * 60 * 60 + time(); // Ну вот нахуя?
db::c()->query('
INSERT INTO `inventory`
(
`prototype`,`owner`,`name`,`type`,`massa`,`cost`,`img`,`maxdur`,`isrep`,`gsila`,`glovk`,`ginta`,`gintel`,
`ghp`,`gnoj`,`gtopor`,`gdubina`,`gmech`,`gfire`,`gwater`,`gair`,`gearth`,`glight`,`ggray`,`gdark`,
`needident`,`nsila`,`nlovk`,`ninta`,`nintel`,`nmudra`,`nvinos`,`nnoj`,`ntopor`,`ndubina`,`nmech`,
`nfire`,`nwater`,`nair`,`nearth`,`nlight`,`ngray`,`ndark`,`mfkrit`,`mfakrit`,`mfuvorot`,`mfauvorot`,
`bron1`,`bron2`,`bron3`,`bron4`,`maxu`,`minu`,`magic`,`nlevel`,`nalign`,`dategoden`,`goden`,`otdel`,
`artefact`, `koll`
)
VALUES (?i,?i,"?s",?i,?i,"?s","?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,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i)
', $dress['id'], $_SESSION['uid'], $dress['name'], $dress['type'], $dress['massa'], $dress['cost'], $dress['img'], $dress['maxdur'], $dress['isrep'],
$dress['gsila'], $dress['glovk'], $dress['ginta'], $dress['gintel'], $dress['ghp'], $dress['gnoj'], $dress['gtopor'], $dress['gdubina'], $dress['gmech'],
$dress['gfire'], $dress['gwater'], $dress['gair'], $dress['gearth'], $dress['glight'], $dress['ggray'], $dress['gdark'], $dress['needident'],
$dress['nsila'], $dress['nlovk'], $dress['ninta'], $dress['nintel'], $dress['nmudra'], $dress['nvinos'], $dress['nnoj'], $dress['ntopor'], $dress['ndubina'], $dress['nmech'],
$dress['nfire'], $dress['nwater'], $dress['nair'], $dress['nearth'], $dress['nlight'], $dress['ngray'], $dress['ndark'], $dress['mfkrit'], $dress['mfakrit'],
$dress['mfuvorot'], $dress['mfauvorot'], $dress['bron1'], $dress['bron3'], $dress['bron2'], $dress['bron4'], $dress['maxu'], $dress['minu'], $dress['magic'],
$dress['nlevel'], $dress['nalign'], $goden, $dress['goden'], $dress['razdel'], $dress['artefact'], $dress['koll']);
db::c()->query('UPDATE `ashop` SET `count` = `count`- ?i WHERE `id` = ?i', $_POST['count'], $set);
2018-06-22 20:43:23 +00:00
$invdb = db::c()->query('SELECT `id` FROM `inventory` WHERE `name` = "?s" ORDER BY `id` DESC LIMIT ?i', $dress['name'], $_POST['count']);
2018-06-22 16:46:48 +00:00
if ($_POST['count'] == 1) {
$dressinv = $invdb->fetch_assoc();
2018-06-22 14:52:29 +00:00
$dressid = "cap" . $dressinv['id'];
$dresscount = " ";
} else {
$dressid = "";
2018-06-22 16:46:48 +00:00
while ($dressinv = $invdb->fetch_assoc()) {
2018-06-22 14:52:29 +00:00
$dressid .= "cap" . $dressinv['id'] . ",";
}
$dresscount = "(x" . $_POST['count'] . ") ";
}
$allcost = $_POST['count'] * $dress['ecost'];
2018-06-22 16:46:48 +00:00
$deloText = $user['login'] . " купил товар: " . $dress['name'] . $dresscount . "id:(" . $dressid . ") [0/" . $dress['maxdur'] . "] за " . $allcost . " екр.";
db::c()->query('INSERT INTO `delo` (`author` ,`pers`, `text`, `type`, `date`) VALUES (?i, ?i, "?s", ?i, "?s")', 0, $user['id'], $deloText, 1, time());
2018-06-22 20:43:23 +00:00
err('Вы купили ' . $_POST['count'] . ' шт. "' . $dress['name'] . '.');
db::c()->query('UPDATE `bank` SET `ekr` = `ekr` - ?i WHERE `id` = ?i', $allcost, $_SESSION['uid']);
2018-06-22 14:52:29 +00:00
$bank['ekr'] -= $allcost;
2018-01-28 16:40:49 +00:00
}
2018-06-22 14:52:29 +00:00
} else {
err('Недостаточно денег или нет вещей в наличии.');
2018-01-28 16:40:49 +00:00
}
}
?>
<!DOCTYPE html>
2018-06-22 14:52:29 +00:00
<html>
<head>
<meta charset="utf-8">
<link href="css/main.css" rel="stylesheet"/>
2018-06-22 14:52:29 +00:00
<script language="JavaScript">
function AddCount(name, txt) {
document.all("hint3").innerHTML = '<form method=post style="margin:0; padding:0;"><table border=0 width=100% cellspacing=1 cellpadding=0 bgcolor="#CCC3AA"><tr><td align=center><B>Купить неск. штук</td><td width=20 align=right valign=top style="cursor: hand" onclick="closehint3();"><b>x</td></tr><tr><td colspan=2>' +
2018-06-22 14:52:29 +00:00
'<table border=0 width=100% cellspacing=0 cellpadding=0 bgcolor="#FFF6DD"><tr><input type="hidden" name="set" value="' + name + '"><td colspan=2 align=center><b><i>' + txt + '</td></tr><tr><td width=80% align=right>' +
'Количество (шт.) <input type="text" name="count" size=4 ></td><td width=20%>&nbsp;<input type="submit" value=" »» ">' +
'</td></tr></table></td></tr></table></form>';
document.all("hint3").style.visibility = "visible";
document.all("hint3").style.left = 100;
document.all("hint3").style.top = 100;
document.all("count").focus();
}
2018-01-28 16:40:49 +00:00
2018-06-22 14:52:29 +00:00
// Закрывает окно
function closehint3() {
document.all("hint3").style.visibility = "hidden";
}
2018-06-22 19:51:00 +00:00
function leave() {
top.frames['main'].location = 'city.php?cp'
}
2018-06-22 14:52:29 +00:00
</script>
2018-01-28 16:40:49 +00:00
</head>
<body>
<h1>Магазин Берёзка</h1>
2018-06-22 19:51:00 +00:00
<a href=# onclick=leave()> ← выйти на Центральную площадь</a>
2018-01-28 16:40:49 +00:00
<table border=0 width=100% cellspacing="0" cellpadding="4">
2018-06-22 14:52:29 +00:00
<tr>
2018-06-22 20:43:23 +00:00
<td valign=top align=left>
<!--Магазин-->
<table border=0 width=100% cellspacing="0" cellpadding="0">
<tr>
<td align=center>
<?php
if ($_REQUEST['compare'] && !$_REQUEST['common'] && !$_REQUEST['present']) {
echo "Составление подарочного букета";
} else {
switch ($_GET['otdel']) {
2018-06-22 23:00:48 +00:00
default:
2018-06-22 20:43:23 +00:00
echo "Оружие: кастеты,ножи";
$_GET['otdel'] = 1;
break;
case 1:
echo "Оружие: кастеты,ножи";
break;
case 11:
echo "Оружие: топоры";
break;
case 12:
echo "Оружие: дубины,булавы";
break;
case 13:
echo "Оружие: мечи";
break;
case 14:
echo "Оружие: луки и арбалеты";
break;
case 2:
echo "Одежда: сапоги";
break;
case 21:
echo "Одежда: перчатки";
break;
case 22:
echo "&Одежда: легкая броня";
break;
case 23:
echo "Одежда: тяжелая броня";
break;
case 24:
echo "Одежда: шлемы";
break;
case 3:
echo "Щиты";
break;
case 4:
echo "Ювелирные товары: серьги";
break;
case 41:
echo "Ювелирные товары: ожерелья";
break;
case 42:
echo "Ювелирные товары: кольца";
break;
case 5:
echo "Заклинания: нейтральные";
break;
case 51:
echo "Заклинания: боевые и защитные";
break;
case 6:
echo "Амуниция";
break;
case 7:
echo "Букеты";
break;
}
}
?>
</td>
</tr>
<tr>
<td><!--Рюкзак-->
<table border=0 width=100% cellspacing="1" cellpadding="2" bgcolor="#A5A5A5">
<?php
if ($_REQUEST['present']) {
if ($_POST['to_login'] && $_POST['flower']) {
$to = db::c()->query('SELECT `id`,`login`,`room` FROM `users` WHERE `login` = ?i', $_POST['to_login'])->fetch_assoc();
if ($_POST['to_login'] == $user['login']) {
err('Очень щедро - дарить что-то самому себе! ;)');
} elseif ($to['room'] > 500 && $to['room'] < 561) {
err('Персонаж в данный момент участвует в турнире в Башне Смерти. Попробуйте позже.');
} else {
if ($_POST['from'] == 1) {
$from = 'Аноним';
} elseif ($_POST['from'] == 2 && $user['klan']) {
$from = ' клана ' . $user['klan'];
2018-06-22 14:52:29 +00:00
} else {
2018-06-22 20:43:23 +00:00
$from = $user['login'];
}
2018-06-22 16:46:48 +00:00
2018-06-22 20:43:23 +00:00
db::c()->query('UPDATE `inventory` SET `owner` = ?i, `present` = "?s", `letter` = "?s" WHERE `present` = "?s" AND `id` = "?s" AND `owner` = ?i AND `dressed` = 0 AND `setsale` = 0', $to['id'], $from, $_POST['podarok2'], null, $_POST['flower'], $_SESSION['uid']);
$res = db::c()->query('SELECT `id`,`name`,`duration`,`maxdur` FROM `inventory` WHERE `id` = ?i', $_POST['flower'])->fetch_assoc();
$deloTextSender = "Подарен предмет \"" . $res['name'] . "\" id:(cap" . $res['id'] . ") [" . $res['duration'] . "/" . $res['maxdur'] . "] от \"" . $user['login'] . "\" к \"" . $to['login'] . "\"";
$deloTextReceiver = "Подарен предмет \"" . $res['name'] . "\" id:(cap" . $res['id'] . ") [" . $res['duration'] . "/" . $res['maxdur'] . "] от \"" . $user['login'] . "\" к \"" . $to['login'] . "\"";
db::c()->query('INSERT INTO `delo`(`author`,`pers`,`text`,`type`,`date`) VALUES (0,?i,"?s",1,?i)', $_SESSION['uid'], $deloTextSender, time());
db::c()->query('INSERT INTO `delo`(`author`,`pers`,`text`,`type`,`date`) VALUES (0,?i,"?s",1,?i)', $to['id'], $deloTextReceiver, time());
2018-06-22 16:46:48 +00:00
2018-06-22 20:43:23 +00:00
$telegraphText = "Вам пришёл подарок \"" . $res['name'] . "\" от " . $from . "!";
db::c()->query('INSERT INTO `telegraph` (owner, text) VALUES (?i,"?s")', $to['id'], $telegraphText)->fetch_assoc();
2018-06-22 16:46:48 +00:00
2018-06-22 20:43:23 +00:00
err('Подарок удачно доставлен к ' . $_POST['to_login']);
2018-06-22 14:52:29 +00:00
}
2018-06-22 20:43:23 +00:00
}
?>
<!-- Подарить подарок -->
2018-06-22 20:43:23 +00:00
<table cellspacing=0 cellpadding=0 width=100% bgcolor=#e0e0e2>
<td>
<form method="post">
<input type=hidden name=present value=1>
Вы можете сделать подарок дорогому человеку. Ваш подарок будет
отображаться в информации о персонаже.
<ol>
<li>Укажите логин персонажа, которому хотите сделать подарок<br>
<input type=text name=to_login value="" placeholder="Логин">
<li><input type=text name=podarok2 value="" maxlength=60 size=50
placeholder="Цель подарка.">
<li><textarea name=txt rows=6 cols=80
placeholder="Текст сопроводительной записки (в информации о персонаже не отображается)"></textarea>
<li>Выберите, от чьего имени подарок:<br>
<label><input type=radio name=from value=0
checked> <?= nick::id($user['id'])->full() ?>
</label><br>
<label><input type=radio name=from value=1> анонимно</label><br>
<label><input type=radio name=from value=2> от имени
клана</label><br>
<li>Нажмите кнопку <b>Подарить</b> под предметом, который хотите
преподнести в подарок:<br>
</ol>
<input type="hidden" name="flower" id="flower" value="">
<table border=0 width=100% cellspacing="1" cellpadding="2"
bgcolor="#A5A5A5">
<?
//print_r($_POST);
$data = db::c()->query('SELECT `id`,`img` FROM `inventory` WHERE `owner`= ?i
2018-06-22 16:46:48 +00:00
AND `dressed` = 0
AND (
`name` LIKE "?S" OR `name` LIKE "?S" OR `name` LIKE "?S" OR `name` LIKE "?S" OR `name` LIKE "?S" OR
`name` LIKE "?S" OR `name` LIKE "?S" OR `name` LIKE "?S"
)
AND `setsale` = 0 AND `present` = "?s"
2018-06-22 20:43:23 +00:00
ORDER BY `id` DESC', $_SESSION['uid'], '%Букет%', '%Сувенир%', '%Подарок%', '%Валентинка%', '%Открытка%', 'Ель%', '%Медаль%', '%Статуэтка%', null);
while ($row = $data->fetch_assoc()) {
if (!in_array($row['id'], array_keys($_SESSION['flowers']))) {
$row['count'] = 1;
if ($i == 0) {
$i = 1;
$color = '#C7C7C7';
} else {
$i = 0;
$color = '#D5D5D5';
}
echo "<tr bgcolor={$color}><td align=center style='width:150px'><img src=\"i/sh/{$row['img']}\" border=0>";
?>
<br><input type=submit
onClick="document.all['flower'].value="<?= $row['id']; ?>
"" value="Подарить">
</form>
</td>
2018-06-22 14:52:29 +00:00
<?
2018-06-22 20:43:23 +00:00
echo "<td valign=top>";
showitem($row);
echo "</td></tr>";
2018-06-22 14:52:29 +00:00
}
2018-06-22 20:43:23 +00:00
}
?>
</table>
<?
} else {
$data = db::c()->query('SELECT `id`,`img`,`name` FROM `ashop` WHERE `count` > 0 AND `razdel` = "?s" AND `ecost` > 0 ORDER BY `ecost` ASC', $_GET['otdel']);
while ($row = $data->fetch_assoc()) {
if ($i == 0) {
$i = 1;
$color = '#C7C7C7';
} else {
$i = 0;
$color = '#D5D5D5';
}
echo "<tr bgcolor=" . $color . "><td align=center style='width:150px'><img src=\"i/sh/{$row['img']}\" border=0>";
?>
<br/>
<a href="ashop.php?otdel=<?= $_GET['otdel'] ?>&set=<?= $row['id'] ?>&sid=">купить</A>
<img src="i/up.gif" width=11 height=11 border=0 alt="Купить несколько штук"
style="cursor:hand"
onClick="AddCount("<?= $row['id'] ?>", "<?= $row['name'] ?>")"></td>
<?
echo "<td valign=top>";
showitem($row);
echo "</td></tr>";
2018-06-22 14:52:29 +00:00
}
2018-06-22 20:43:23 +00:00
}
?>
</table>
</td>
</tr>
</table>
</td>
<td valign=top width=280>
<b>Масса всех ваших вещей: <?= $itemWeight['m'] ?>/<?= get_meshok() ?>
<br>У вас в наличии: <span style="color: #339900;"><?= $bank['ekr'] ?></span> екр.</b>
2018-06-22 20:47:02 +00:00
<hr /><a href=upgrade_items.php><font color=blue>Улучшение Артефактов</font></a>
2018-06-22 20:43:23 +00:00
<hr>
<div style="background-color: #d2d0d0;padding: 1px; text-align: center; font-weight: bold;">
Отделы магазина
</div>
<dl>
<dt><b>Оружие:</b></dt>
<dd><a href="ashop.php?otdel=1&rnd=<?= mt_rand() ?>">кастеты,ножи</a></dd>
<dd><a href="ashop.php?otdel=11&rnd=<?= mt_rand() ?>">топоры</a></dd>
<dd><a href="ashop.php?otdel=12&rnd=<?= mt_rand() ?>">дубины,булавы</a></dd>
<dd><a href="ashop.php?otdel=13&rnd=<?= mt_rand() ?>">мечи</a></dd>
<dt><b>Одежда:</b></dt>
<dd><a href="ashop.php?otdel=24&rnd=<?= mt_rand() ?>">шлемы</a></dd>
<dd><a href="ashop.php?otdel=23&rnd=<?= mt_rand() ?>">тяжелая броня</a></dd>
<dd><a href="ashop.php?otdel=22&rnd=<?= mt_rand() ?>">легкая броня</a></dd>
<dd><a href="ashop.php?otdel=3&rnd=<?= mt_rand() ?>">щиты</a></dd>
<dd><a href="ashop.php?otdel=21&rnd=<?= mt_rand() ?>">перчатки</a></dd>
<dd><a href="ashop.php?otdel=2&rnd=<?= mt_rand() ?>">сапоги</a></dd>
<dt><b>Ювелирные товары:</b></dt>
<dd><a href="ashop.php?otdel=4&rnd=<?= mt_rand() ?>">серьги</a></dd>
<dd><a href="ashop.php?otdel=41&rnd=<?= mt_rand() ?>">ожерелья</a></dd>
2018-06-22 20:47:02 +00:00
<dd><a href="ashop.php?otdel=42&rnd=<?= mt_rand() ?>">кольца</a></dd>
2018-06-22 20:43:23 +00:00
<dt><b>Магия:</b></dt>
<dd><a href="ashop.php?otdel=51&rnd=<?= mt_rand() ?>">боевые</a></dd>
<dd><a href="ashop.php?otdel=5&rnd=<?= mt_rand() ?>">разные</a></dd>
<dt><b>Разное:</b></dt>
<dd><a href="ashop.php?otdel=6&rnd=<?= mt_rand() ?>">амуниция</a></dd>
<dd><a href="ashop.php?otdel=7rnd=<?= mt_rand() ?>">букеты</a></dd>
</dl>
<div id="hint3" class="ahint"></div>
2018-06-22 14:52:29 +00:00
</td>
</tr>
2018-01-28 16:40:49 +00:00
</table>
</body>
</html>