game/modules_data/location/shop_.php

141 lines
4.8 KiB
PHP
Raw Normal View History

2022-06-06 21:30:34 +00:00
<?php
2023-01-28 02:24:37 +00:00
use Core\Config;
use Core\Db;
use Core\View;
2023-11-09 17:24:47 +00:00
use Enum\ShopId;
use Helper\Conversion;
use Location\Shop;
use User\Clan;
use User\ItemsModel;
2023-01-28 02:24:37 +00:00
/* @var User $u */
2023-01-28 02:24:37 +00:00
if ($u->room['file'] != 'shop_') {
return;
}
2023-01-28 02:24:37 +00:00
$shopId = null;
$status = '';
$itmAllSee = '';
$actionSale = false;
$actionGifts = false;
$buyItemId = 0;
$buyEkrItemId = 0;
$buyVoinItemId = 0;
$sellItemId = 0;
$uc = null;
$giftsvars = [];
$otdel = 1;
if ((int)$u->info['room'] === 10) {
2023-11-09 17:24:47 +00:00
$shopId = ShopId::MAIN;
}
if ((int)$u->info['room'] === 368) {
2023-11-09 17:24:47 +00:00
$shopId = ShopId::SHOP_2;
}
if ((int)$u->info['room'] === 13) {
2023-11-09 17:24:47 +00:00
$shopId = ShopId::BEREZKA;
}
2023-01-28 02:24:37 +00:00
if ($_SERVER["REQUEST_METHOD"] === "GET") { //неясно почему, $_GET вызывается буквалльно всегда, даже на пустом месте.
$actionSale = (bool)$_GET['sale'];
$actionGifts = (bool)$_GET['gifts'];
$buyItemId = intval($_GET['buy']);
$buyEkrItemId = intval($_GET['buyEkr']);
$buyVoinItemId = intval($_GET['buyVn']);
$sellItemId = intval($_GET['item']);
$otdel = $_GET['otdel'] ??= 1;
}
2023-01-28 02:24:37 +00:00
if (isset($_POST['itemgift'])) {
$present = new \DTO\Present();
$present->sender = $u->info['login'];
$present->receiver = $_POST['to_login'];
$present->textTitle = $_POST['podarok2'];
$present->text = $_POST['txt'];
if (intval($_POST['from']) === 1) {
$present->anonymousSender = true;
} elseif (intval($_POST['from'] === 2) && $u->info['clan'] > 0) {
$present->clanSender = true;
}
$sendPresent = new Present($present);
$status = $sendPresent->getStatus();
}
2023-01-28 02:24:37 +00:00
$shop = new Shop($shopId, $otdel);
$shopName = Db::getValue('select name from room where id = ?', [$u->info['room']]);
2023-01-28 02:24:37 +00:00
if ($buyItemId) {
$status = $shop->buy($buyItemId);
} elseif ($buyEkrItemId) {
$status = $shop->buyEkr($buyEkrItemId);
} elseif ($buyVoinItemId) {
$status = $shop->buyVn($buyVoinItemId);
2023-01-28 02:24:37 +00:00
}
if ($actionSale) {
$itmAll = $u->genInv(2, '`iu`.`uid`="' . $u->info['id'] . '" AND `iu`.`delete`=0 AND `iu`.`inOdet`=0 AND `iu`.`inShop`=0 AND `iu`.`data` NOT LIKE "%fromshop=2%" ORDER BY `lastUPD` DESC');
if ($itmAll[0] == 0) {
$itmAllSee = '<tr><td style="text-align: center; background-color: lightgrey;">ПУСТО</td></tr>';
2023-06-23 15:24:55 +00:00
} else {
$itmAllSee = $itmAll[2];
}
if ($sellItemId) {
$item = ItemsModel::getOwnedItemById($sellItemId, User::start()->info['id']);
$itemData = Conversion::dataStringToArray($item['data']);
$status = $item['gift'] ? 'Подарки не продаются!' : '';
$status = $itemData['nosale'] ? 'Предмет не для продажи!' : '';
if (!$status && $sellItemId) {
$sellprice = $item['1price'] - $item['1price'] * 0.1;
ItemsModel::delete($item['id']);
$u->addKr($sellprice);
$status = "Вы успешно продали предмет «{$item['name']}» за $sellprice кр.";
2023-11-09 17:24:47 +00:00
Delo::add(2, 'shopid:' . $shopId->value, $u->info['id'], "Предмет «{$item['name']}» [id:{$item['id']}] продан за $sellprice кр.", -$sellprice);
2023-01-28 02:24:37 +00:00
}
}
}
2023-01-28 02:24:37 +00:00
if ($actionGifts) {
$uc = new Clan($u->info);
$imgsrc = Config::img();
$sp = Db::getRow('select * from users_gifts where uid = ?', [$u->info['id']]);
foreach ($sp as $pl) {
$giftsvars[] = [
'img' => $imgsrc . '/i/items/' . $pl['img'],
'jsvalue' => 1000000000000 + $pl['id'],
'money' => $pl['money'],
'linkname' => $pl['name'],
];
}
$itmAll = $u->genInv(3, '`iu`.`uid`="' . $u->info['id'] . '" AND `iu`.`delete`=0 AND `iu`.`inOdet`=0 AND `iu`.`inShop`=0 AND `im`.`type` in (28,38,63,64,37) AND (`iu`.`gift` = "" OR `iu`.`gift` = 1) ORDER BY `lastUPD` DESC');
if ($itmAll[0] == 0) {
$itmAllSee = '<tr><td style="text-align: center; background-color: lightgrey;">У вас нет подходящих предметов</td></tr>';
2023-06-23 15:24:55 +00:00
} else {
$itmAllSee = $itmAll[2];
2023-01-28 02:24:37 +00:00
}
}
/** @var string $goLis инициализируется в файле из которого вызван этот. Отрисовка датчика задержки смены локации. */
/** @var string $code инициализируется в файле из которого вызван этот. Хеш-строка против кеширования. */
$renderArgs = [
'shopName' => $shopName,
'status' => $status,
'actionSale' => $actionSale,
'actionGifts' => $actionGifts,
'otdel' => $otdel,
'u' => $u,
'uc' => $uc,
'giftsvars' => $giftsvars,
'itmAllSee' => $itmAllSee,
'shop' => $shop,
'goLis' => $goLis,
'code' => $code,
2023-11-09 17:24:47 +00:00
'shopId' => $shopId->value,
'otdels' => $shop->getUsedOtdels(),
'i' => 1,
];
View::render('Locations/Shop.php', $renderArgs);