2023-07-07 15:36:23 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Location;
|
|
|
|
|
|
|
|
|
|
use Core\Config;
|
|
|
|
|
use Core\Db;
|
2023-07-28 21:18:04 +00:00
|
|
|
|
use Delo;
|
2023-08-14 15:15:05 +00:00
|
|
|
|
use Helper\Conversion;
|
2023-07-28 21:18:04 +00:00
|
|
|
|
use Item\Data\Bonuses;
|
|
|
|
|
use Item\Data\Properties;
|
|
|
|
|
use Item\Data\Requirements;
|
|
|
|
|
use Item\DataModel;
|
2023-07-07 15:36:23 +00:00
|
|
|
|
use User;
|
|
|
|
|
|
|
|
|
|
class Shop
|
|
|
|
|
{
|
|
|
|
|
private const ITEM_GENERATION_CURRENT = 2;
|
|
|
|
|
public const MAIN = 1;
|
|
|
|
|
public const BEREZKA = 2;
|
2023-07-19 15:23:44 +00:00
|
|
|
|
public const CRYSTALS = 1050;
|
|
|
|
|
public const REFERALS = 27;
|
|
|
|
|
public const TEMPLE = 14;
|
|
|
|
|
public const IZLOM = 10;
|
|
|
|
|
public const LABORATORY = 45;
|
|
|
|
|
public const ARTEFACTS = 777; //магазин самоцветов
|
|
|
|
|
public const KNIGHTS_MAIN = 400; //магазин рефералов
|
|
|
|
|
public const DUNGEON_BEZDNA = 801; // храм?!
|
|
|
|
|
public const DUNGEON_PTP = 802; // излом?!
|
|
|
|
|
public const DUNGEON_CATACOMBS = 803; //лаборатория?!?!
|
|
|
|
|
public const DUNGEON_MISTY = 804;
|
|
|
|
|
//public const BOOKS = 7;
|
|
|
|
|
public const MUSHROOMS = 17; // общий рыцарский
|
|
|
|
|
public const RULF_HRUNT = 33; // бездна
|
|
|
|
|
public const LUKA = 5; // пещера тысячи проклятий
|
|
|
|
|
public const ANVIL = 700; // катакомбы
|
|
|
|
|
public const NEWBIE = 106; // пещера мглы
|
|
|
|
|
//public const FLOWER = 6;
|
|
|
|
|
public const SHOP_2 = 609; // магазин грибоеда??
|
|
|
|
|
public const SHOP_KAT = 44; // магазин рульфа хрунта, а ты что такое?
|
|
|
|
|
public const SHOP_PRIZ = 404; // каморка Луки
|
|
|
|
|
//public const BLOOD_ALTAR = 11; //алтарь крови
|
|
|
|
|
public const TAVERN = 9; // наковальня
|
|
|
|
|
public const ANIMALS = 8; // магазин новичка
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public const OTDEL_NAME = [
|
|
|
|
|
1 => 'Кастеты,ножи',
|
|
|
|
|
2 => 'Топоры',
|
|
|
|
|
3 => 'Дубины,булавы',
|
|
|
|
|
4 => 'Мечи',
|
|
|
|
|
5 => 'Магические посохи',
|
|
|
|
|
6 => 'Сапоги',
|
|
|
|
|
7 => 'Перчатки',
|
|
|
|
|
8 => 'Рубахи',
|
|
|
|
|
9 => 'Легкая броня',
|
|
|
|
|
10 => 'Тяжелая броня',
|
|
|
|
|
11 => 'Шлемы',
|
|
|
|
|
12 => 'Наручи',
|
|
|
|
|
13 => 'Пояса',
|
|
|
|
|
14 => 'Поножи',
|
|
|
|
|
15 => 'Щиты',
|
|
|
|
|
16 => 'Серьги',
|
|
|
|
|
17 => 'Ожерелья',
|
|
|
|
|
18 => 'Кольца',
|
|
|
|
|
19 => 'Заклинания: нейтральные',
|
|
|
|
|
20 => 'Заклинания: боевые и защитные',
|
|
|
|
|
21 => 'Заклинания: карманные',
|
|
|
|
|
22 => 'Заклинания: исцеляющие',
|
|
|
|
|
23 => 'Заклинания: манящие',
|
|
|
|
|
24 => 'Заклинания: стратегические',
|
|
|
|
|
25 => 'Заклинания: тактические',
|
|
|
|
|
26 => 'Заклинания: сервисные',
|
|
|
|
|
27 => 'Амуниция',
|
|
|
|
|
28 => 'Эликсиры',
|
|
|
|
|
29 => 'Еда',
|
|
|
|
|
30 => 'Подарки',
|
|
|
|
|
31 => 'Подарки: недобрые',
|
|
|
|
|
32 => 'Подарки: упаковка',
|
|
|
|
|
33 => 'Подарки: открытки',
|
|
|
|
|
34 => 'Подарки: фейерверки',
|
|
|
|
|
35 => 'Усиление оружия: Заточки',
|
|
|
|
|
36 => 'Плащи и Накидки:',
|
|
|
|
|
37 => 'Готовые Комплекты:',
|
|
|
|
|
];
|
|
|
|
|
public const OTDEL_GROUP_NAME = [
|
|
|
|
|
1 => 'Оружие',
|
|
|
|
|
6 => 'Одежда',
|
|
|
|
|
15 => 'Щиты',
|
|
|
|
|
16 => 'Ювелирные товары',
|
|
|
|
|
19 => 'Заклинания',
|
|
|
|
|
27 => 'Амуниция',
|
|
|
|
|
28 => 'Эликсиры',
|
|
|
|
|
30 => 'Подарки',
|
|
|
|
|
35 => 'Прочее',
|
|
|
|
|
];
|
|
|
|
|
private int $shopId;
|
|
|
|
|
private array $wares;
|
|
|
|
|
private int $otdel;
|
2023-07-19 15:23:44 +00:00
|
|
|
|
private int $itemId;
|
|
|
|
|
private $buyer;
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function __construct(int $shopId, int $otdel = 1)
|
2023-07-07 15:36:23 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$this->otdel = $otdel;
|
2023-07-07 15:36:23 +00:00
|
|
|
|
$this->itemId = intval($_GET['itmid']);
|
|
|
|
|
$this->shopId = $shopId;
|
|
|
|
|
$this->wares = Db::getRows('select * from
|
|
|
|
|
items_shop
|
|
|
|
|
left join items_main on items_shop.item_id = items_main.id
|
2023-07-28 21:18:04 +00:00
|
|
|
|
where sid = ? and r = ? and kolvo > 0 order by pos', [$shopId, $otdel]);
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
|
|
|
|
$this->buyer = new class {
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function getId(): int
|
2023-07-07 15:36:23 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
return User::start()->info['id'];
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function getCredits(): float
|
2023-07-07 15:36:23 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
return User::start()->info['money'];
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function getEuroCredits(): float
|
2023-07-07 15:36:23 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
return User::start()->info['money2'];
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function getVoinstvennost(): int
|
2023-07-07 15:36:23 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
return (int)User::start()->rep['rep3'] - (int)User::start()->rep['rep3_buy'];
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function getNextAct()
|
2023-07-07 15:36:23 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
return User::start()->info['nextAct']; // что ты такое?!
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function isAdmin(): bool
|
2023-07-07 15:36:23 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
return User::start()->isAdmin();
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function hasEnough(string $parameter, int $value): bool
|
2023-07-07 15:36:23 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
return User::start()->stats[$parameter] >= $value;
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function hasExactly(string $parameter, int $value): bool
|
2023-07-07 15:36:23 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
return User::start()->stats[$parameter] === $value;
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function hasEnoughCredits(int $itemprice): bool
|
2023-07-07 15:36:23 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
return $this->getCredits() >= $itemprice;
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function hasEnoughEuroCredits(int $itemprice): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->getEuroCredits() >= $itemprice;
|
|
|
|
|
}
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function hasEnoughVoinstvennost(int $itemprice): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->getVoinstvennost() >= $itemprice;
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-07-07 15:36:23 +00:00
|
|
|
|
if ($this->buyer->isAdmin()) {
|
|
|
|
|
if (isset($_GET['itmup'])) {
|
|
|
|
|
$this->itemUp();
|
|
|
|
|
} elseif (isset($_GET['itmdown'])) {
|
|
|
|
|
$this->itemDown();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] === "GET") {
|
|
|
|
|
if ($_GET['itmup']) {
|
|
|
|
|
$this->itemUp();
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
private function itemUp()
|
|
|
|
|
{
|
|
|
|
|
$this->changeItemPositionByInt(-1);
|
|
|
|
|
}
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
private function changeItemPositionByInt(int $modificator)
|
|
|
|
|
{
|
|
|
|
|
Db::sql('update items_shop set pos = pos + ? where sid = ? and r = ? and item_id = ? and kolvo > 0',
|
|
|
|
|
[$modificator, $this->shopId, $this->otdel, $this->itemId]);
|
|
|
|
|
}
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
private function itemDown()
|
|
|
|
|
{
|
|
|
|
|
$this->changeItemPositionByInt(1);
|
|
|
|
|
}
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
public function printWares()
|
|
|
|
|
{
|
|
|
|
|
foreach ($this->wares as $pl) {
|
|
|
|
|
$data = new DataModel($pl['item_id']);
|
|
|
|
|
$itemRequirements = new Requirements($data->getRequirements());
|
|
|
|
|
$itemBonuses = new Bonuses($data->getBonuses());
|
|
|
|
|
$itemProperties = new Properties($data->getProperties());
|
|
|
|
|
$itemData = $data->getAll();
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$pl['price_1'] = $this->calculateMinimalPrice($pl['price1'], $pl['price_1'], $pl['tr_items']);
|
|
|
|
|
$pl['price_2'] = $this->calculateMinimalPrice($pl['price2'], $pl['price_2'], $pl['tr_items']);
|
|
|
|
|
|
|
|
|
|
if (($pl['type'] >= 18 && $pl['type'] <= 24) || $pl['type'] == 26 || $pl['type'] == 27) {
|
|
|
|
|
$itemBonuses->addZonb();
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$is2 = $this->name($pl['name'], $pl['renameadd'], $pl['item_id']);
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
|
|
|
|
if ($pl['massa'] > 0) {
|
|
|
|
|
$is2 .= '(Масса: ' . round($pl['massa'], 2) . ')';
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$is2 .= $this->icons($itemRequirements->getAlign(), $itemData['art'], $itemData['sudba']);
|
|
|
|
|
$is2 .= $this->price($pl['price_1'], $pl['price_2'], $pl['price_4']);
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if ($pl['kolvo'] < 50) {
|
|
|
|
|
$is2 .= ' <small style="color: crimson;">(остаток на складе: <strong>' . $pl['kolvo'] . '</strong>)</small>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$is2 .= $this->needItems($pl['tr_items']);
|
|
|
|
|
|
|
|
|
|
//долговечность
|
|
|
|
|
if ($pl['iznos'] > 0) {
|
|
|
|
|
$pl['iznosMAXi'] = $pl['iznos'];
|
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if ($pl['iznosMAXi'] > 0 && $pl['iznosMAXi'] !== 999999999) {
|
|
|
|
|
$is2 .= 'Долговечность: 0/' . $pl['iznosMAXi'] . '<br>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($itemData['battleUseZd'] > 0) {
|
2023-08-14 15:15:05 +00:00
|
|
|
|
$is2 .= 'Задержка использования: ' . Conversion::secondsToTimeout($itemData['battleUseZd']) . '<br>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$is2 = rtrim($is2, '<br>');
|
|
|
|
|
|
|
|
|
|
//Срок годности предмета
|
|
|
|
|
if ($itemData['srok'] > 0) {
|
|
|
|
|
$pl['srok'] = $itemData['srok'];
|
|
|
|
|
}
|
|
|
|
|
if ($pl['srok'] > 0) {
|
2023-08-14 15:15:05 +00:00
|
|
|
|
$is2 .= '<br>Срок годности: ' . Conversion::secondsToTimeout($pl['srok']);
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
if ($pl['magic_chance'] > 0) {
|
|
|
|
|
$is2 .= '<br>Вероятность срабатывания: ' . min([$pl['magic_chance'], 100]) . '%';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Продолжительность действия магии:
|
|
|
|
|
if ((int)$pl['magic_inci'] > 0) {
|
|
|
|
|
$magicDuration = Db::getValue('select actiontime from eff_main where id2 = ?', [(int)$pl['magic_inci']]);
|
|
|
|
|
|
|
|
|
|
if ($magicDuration > 0) {
|
2023-08-14 15:15:05 +00:00
|
|
|
|
$is2 .= '<br>Продолжительность действия: ' . Conversion::secondsToTimeout($magicDuration);
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if ($itemRequirements->get()) {
|
|
|
|
|
$is2 .= '<br><strong>Требуется минимальное:</strong>';
|
|
|
|
|
$is2 .= '<ul style="margin: 0; padding: 0 30px;">';
|
|
|
|
|
foreach ($itemRequirements->get() as $dataName => $dataInfo) {
|
|
|
|
|
if ($dataName === 'align' || $dataName === 'sex') {
|
|
|
|
|
$is2 .= $this->buyer->hasExactly($dataName, intval($dataInfo['value'])) ? '<li>' : '<li style="color: crimson; list-style-type: \'× \';">';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
} else {
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$is2 .= $this->buyer->hasEnough($dataName, intval($dataInfo['value'])) ? '<li>' : '<li style="color: crimson; list-style-type: \'× \';">';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$is2 .= $dataInfo['name'] . ': ' . $dataInfo['value'];
|
|
|
|
|
$is2 .= '</li>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$is2 .= '</ul>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if ($itemBonuses->get()) {
|
|
|
|
|
$is2 .= '<br><strong>Действует на:</strong>';
|
|
|
|
|
$is2 .= '<ul style="margin: 0; padding: 0 30px;">';
|
|
|
|
|
foreach ($itemBonuses->get() as $name => $value) {
|
|
|
|
|
if ($name === 'Броня') {
|
|
|
|
|
$is2 .= '<li>' . $name . ': ' . $value . '</li>';
|
|
|
|
|
continue;
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$color = $value > 0 ? 'darkgreen' : 'darkred';
|
|
|
|
|
$is2 .= '<li style="color: ' . $color . '">' . $name . ': ' . ($value > 0 ? '+' . $value : $value) . '</li>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$is2 .= '</ul>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
|
|
|
|
|
$is2 .= '<br><strong>Свойства предмета:</strong>';
|
|
|
|
|
foreach ($itemProperties->get() as $name => $value) {
|
|
|
|
|
$is2 .= '<br>' . $name . ': ' . $value;
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
|
|
|
|
|
if ($pl['2too'] === 1) {
|
|
|
|
|
$is2 .= '<br>Второе оружие';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if ($pl['2h'] === 1) {
|
|
|
|
|
$is2 .= '<br>Двуручное оружие';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if (!empty($itemData['imposed'])) {
|
|
|
|
|
if (empty($itemData['imposed_name'])) {
|
|
|
|
|
$itemData['imposed_name'] = 'Неизвестное зачарование';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
$itemData['imposed_name'] = str_replace('Чары ', '', $itemData['imposed_name']);
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$is2 .= '<br><span style="color: maroon;">Зачарование:</span> ' . $itemData['imposed_name'];
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if (!empty($itemData['free_stats']) && $itemData['free_stats'] > 0) {
|
|
|
|
|
$is2 .= '<br> +' . $itemData['free_stats'] . ' дополнительных характеристик';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Встроенная магия
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if (!empty($pl['magic_inci']) || !empty($pl['magic_inc'])) {
|
|
|
|
|
if (empty($pl['magic_inc'])) {
|
2023-07-07 15:36:23 +00:00
|
|
|
|
$pl['magic_inc'] = $pl['magic_inci'];
|
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$magic = Db::getRow('select id2, mname, minfo, img from eff_main where type1 = 12345 and id2 = ?', [$pl['magic_inc']]);
|
|
|
|
|
if ($magic['id2']) {
|
|
|
|
|
$is2 .= '<br><div>Встроено заклятие <img alt="' . $magic['mname'] . '" src="' . Config::img() . '/i/eff/' . $magic['img'] . '"> ' . $magic['minfo'] . '</div>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$is2 .= $this->getcomplect($itemData['complect']);
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
|
|
|
|
if ($pl['max_text'] - $pl['use_text'] > 0) {
|
|
|
|
|
$is2 .= '<div>Количество символов: ' . ($pl['max_text'] - $pl['use_text']) . '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$is2 .= '<small>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if (!empty($itemData['gravi'])) {
|
|
|
|
|
$is2 .= '<br><span style="font-size: x-large; font-family: consolas, monospace; background-color: darkseagreen; color: ghostwhite; padding: 0 5px;">' . $itemData['gravi'] . '</span>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if (!empty($itemData['info'])) {
|
|
|
|
|
$pl['info'] .= '<br>' . $itemData['info'];
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
if (!empty($pl['info'])) {
|
|
|
|
|
$is2 .= '<div style="border: 2px dashed whitesmoke; background-color: silver;">' . $pl['info'] . '</div>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($itemData['noremont'])) {
|
|
|
|
|
$is2 .= '<div style="color:brown;">Предмет не подлежит ремонту</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($itemData['nosale'])) {
|
|
|
|
|
$is2 .= '<div style="color:brown;">Предмет нельзя продать</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($itemData['nomodif'])) {
|
|
|
|
|
$is2 .= '<div style="color:brown;">Предмет нельзя улучшать</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($itemData['nodelete'])) {
|
|
|
|
|
$is2 .= '<div style="color:brown;">Предмет нельзя выбросить</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($itemData['sleep_moroz']) && $itemData['sleep_moroz'] > 0) {
|
|
|
|
|
$is2 .= '<div style="color:brown;">Предмет не портится во время сна</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$is2 .= '</small>';
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$is1 = $this->imageAndControls($pl['id'], $pl['type'], $pl['img'], $pl['name'], $pl['price_1'], $pl['price_2']);
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
echo <<<HTML
|
|
|
|
|
<div style="padding: 7px; text-align: center; vertical-align: middle;" class="left">$is1</div>
|
|
|
|
|
<div style="padding: 7px;" class="right">{$this->adminOptions($pl['id'], $pl['pos'])} $is2</div>
|
|
|
|
|
HTML;
|
2023-07-07 15:36:23 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->wares)) {
|
2023-07-28 21:18:04 +00:00
|
|
|
|
echo '<div style="grid-column: 1 / 3; padding: 7px; margin: auto">Прилавок магазина пуст.</div>';
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-19 15:23:44 +00:00
|
|
|
|
|
|
|
|
|
private function calculateMinimalPrice($basePrice, $shopPrice, $needItems)
|
|
|
|
|
{
|
|
|
|
|
if ($shopPrice < 0.01 && !$needItems) {
|
|
|
|
|
$shopPrice = $basePrice;
|
|
|
|
|
}
|
|
|
|
|
if ($shopPrice < 0) {
|
|
|
|
|
$shopPrice = 0;
|
|
|
|
|
}
|
|
|
|
|
return $shopPrice;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
private function name(string $name, ?string $defaultName, int $itemid): string
|
2023-07-19 15:23:44 +00:00
|
|
|
|
{
|
2023-07-28 21:18:04 +00:00
|
|
|
|
$styleSuffix = '';
|
|
|
|
|
if ($this->shopId == self::SHOP_2) {
|
|
|
|
|
$styleSuffix = 'WL';
|
|
|
|
|
}
|
|
|
|
|
if (!empty($defaultName)) {
|
|
|
|
|
$name .= ' (Предмет: ' . $defaultName . ')';
|
|
|
|
|
}
|
|
|
|
|
if (!empty($styleSuffix)) {
|
|
|
|
|
$name = '<span class="icos_' . $styleSuffix . '">' . $name . ' <small> ' . $styleSuffix . ' </small></span>';
|
2023-07-19 15:23:44 +00:00
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
return '<a id="sit_' . $itemid . '" href="/item/' . $itemid . '" target="_blank">' . $name . '</a> ';
|
|
|
|
|
}
|
2023-07-19 15:23:44 +00:00
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
private function icons(?int $align, ?int $artefact, ?int $destiny): string
|
|
|
|
|
{
|
|
|
|
|
$str = ' ';
|
|
|
|
|
if (!empty($align)) {
|
|
|
|
|
$str .= '<img src="' . Config::img() . '/i/align/align' . $align . '.gif" alt="Требуется склонность">';
|
|
|
|
|
}
|
|
|
|
|
if (!empty($artefact)) {
|
|
|
|
|
$str .= '<img src="' . Config::img() . '/i/artefact.gif" alt="Артефакт">';
|
|
|
|
|
}
|
|
|
|
|
$str .= $this->destiny($destiny);
|
|
|
|
|
return $str;
|
2023-07-19 15:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function destiny($d): string
|
|
|
|
|
{
|
|
|
|
|
if (empty($d)) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
if ($d == 0) {
|
|
|
|
|
$str = 'первым, кто наденет его';
|
|
|
|
|
} elseif ($d == 1) {
|
|
|
|
|
$str = 'первым, кто возьмёт его';
|
|
|
|
|
} else {
|
|
|
|
|
$str = $d;
|
|
|
|
|
}
|
|
|
|
|
return '<img
|
|
|
|
|
title="Этот предмет будет связан общей судьбой с ' . $str . '. Никто другой не сможет его использовать."
|
|
|
|
|
src="' . Config::img() . '/i/destiny0.gif"
|
|
|
|
|
alt="Общая судьба">';
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 21:18:04 +00:00
|
|
|
|
private function price(int $credits, int $eurocredits, int $voinstvennost): string
|
|
|
|
|
{
|
|
|
|
|
$result = 'Цена: ';
|
|
|
|
|
if ($this->shopId === self::SHOP_2) {
|
|
|
|
|
$result .= $this->printColoredValue($this->buyer->getVoinstvennost() >= $voinstvennost, $voinstvennost);
|
|
|
|
|
$result .= ' Воинственности ';
|
|
|
|
|
} elseif ($this->shopId === self::BEREZKA || $this->shopId === self::ARTEFACTS) {
|
|
|
|
|
$result .= '<span style="color: cornflowerblue;">';
|
|
|
|
|
$result .= $this->printColoredValue($this->buyer->getEuroCredits() >= $eurocredits, $eurocredits);
|
|
|
|
|
$result .= ' екр.</span> ';
|
|
|
|
|
} else {
|
|
|
|
|
$result .= $this->printColoredValue($this->buyer->getCredits() >= $credits, $credits);
|
|
|
|
|
$result .= ' кр.';
|
|
|
|
|
}
|
|
|
|
|
return '<br><strong>' . $result . '</strong> ';
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-19 15:23:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* Если в первом параметре передаётся false, строка во втором параметре красится в красный цвет.
|
|
|
|
|
* @param bool $check
|
|
|
|
|
* @param $value
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function printColoredValue(bool $check, $value): string
|
|
|
|
|
{
|
|
|
|
|
$color = $check ? 'inherit' : 'red';
|
|
|
|
|
return sprintf('<span style="color:%s;">%s</span>', $color, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function needItems(string $items): string
|
|
|
|
|
{
|
|
|
|
|
if (!$items || Config::get('noitembuy')) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$result = '';
|
|
|
|
|
$trn = true;
|
|
|
|
|
|
|
|
|
|
$itemsArray = explode(',', $items);
|
|
|
|
|
foreach ($itemsArray as $keyvalue) {
|
|
|
|
|
[$key, $value] = explode('=', $keyvalue);
|
|
|
|
|
if (!empty($key) && !empty($value)) {
|
|
|
|
|
$neededItemName = Db::getValue('select name from items_main where id = ?', [$key]);
|
|
|
|
|
if ($neededItemName) {
|
|
|
|
|
$neededItemsInInventoryCount = Db::getValue(
|
|
|
|
|
'select count(*) from items_users where item_id = ? and inShop = 0 and inOdet = 0 and `delete` in (0,1000) and uid = ?',
|
|
|
|
|
[$key, $this->buyer->getId()]);
|
|
|
|
|
if ($neededItemsInInventoryCount < (int)$value) {
|
|
|
|
|
$trn = false;
|
|
|
|
|
}
|
|
|
|
|
$result .= '[<strong>' . $neededItemName . '</strong>] x' . $value . ', ';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->printColoredValue($trn, '<br>Требует предмет: ' . rtrim($result, ', ') . ' ') . '<br>';
|
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
|
|
|
|
|
private function getcomplect(?int $complect): string
|
|
|
|
|
{
|
|
|
|
|
if (!isset($complect)) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$cname = 'Неизвестный Комплект';
|
|
|
|
|
$text = '';
|
|
|
|
|
$stmt = Db::getRows('select * from complects where com = ? order by x', [$complect]);
|
|
|
|
|
foreach ($stmt as $row) {
|
|
|
|
|
$cname = $row['name'];
|
|
|
|
|
$text .= ' • <span style="color: green;">' . $row['x'] . ' предметов</span>:<br>';
|
|
|
|
|
//действие комплекта
|
2023-08-14 15:15:05 +00:00
|
|
|
|
$complectBonuses = new Bonuses(Conversion::dataStringToArray($row['data']));
|
2023-07-28 21:18:04 +00:00
|
|
|
|
foreach ($complectBonuses->get() as $name => $value) {
|
|
|
|
|
$text .= ' <span style="color: darkgreen;">';
|
|
|
|
|
if ($name === 'Броня') {
|
|
|
|
|
$text .= $name . ': ' . $value;
|
|
|
|
|
} else {
|
|
|
|
|
$text .= $name . ': ' . ($value > 0 ? '+' . $value : $value);
|
|
|
|
|
}
|
|
|
|
|
$text .= '</span><br>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "<br>Часть комплекта: <strong>$cname</strong><br><small>$text</small>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function imageAndControls(int $id, int $type, string $image, string $name, float $credits, float $eurocredits): string
|
|
|
|
|
{
|
|
|
|
|
if ($type == 71) {
|
|
|
|
|
$result = '<img src="' . Config::img() . '/i/items/' . $image . '" width="80" alt="' . $name . '"><br>';
|
|
|
|
|
} else {
|
|
|
|
|
$result = '<img src="' . Config::img() . '/i/items/' . $image . '" alt="' . $name . '"><br>';
|
|
|
|
|
}
|
|
|
|
|
if ($this->shopId == self::SHOP_2) {
|
|
|
|
|
$result .= '<a href="javascript:void(' . $id . ');" onClick="top.buyShopNow(' . $id . ',\'?' . 'otdel=' . $this->otdel . '&buyVn=' . $id . '&sd4=' . $this->buyer->getNextAct() . '\',\'' . $name . '\',\'??\',\' ??.\');">купить</a>';
|
|
|
|
|
} elseif (($this->shopId == self::BEREZKA || $this->shopId == self::ARTEFACTS) && $this->buyer->hasEnoughEuroCredits($eurocredits)) {
|
|
|
|
|
$result .= '<a href="javascript:void(' . $id . ');" onClick="top.buyShopNow(' . $id . ',\'?' . 'otdel=' . $this->otdel . '&buyEkr=' . $id . '&sd4=' . $this->buyer->getNextAct() . '\',\'' . $name . '\',\'' . $eurocredits . '\',\' екр.\');">купить</a>';
|
|
|
|
|
} elseif ($this->buyer->hasEnoughCredits($credits)) {
|
|
|
|
|
$result .= '<a href="javascript:void(' . $id . ');" onClick="top.buyShopNow(' . $id . ',\'?' . 'otdel=' . $this->otdel . '&buy=' . $id . '&sd4=' . $this->buyer->getNextAct() . '\',\'' . $name . '\',\'' . $credits . '\',\' кр.\');">купить</a>';
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function adminOptions(int $itemId, int $itemPosition): string
|
|
|
|
|
{
|
|
|
|
|
if (!$this->buyer->isAdmin()) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$time = microtime();
|
|
|
|
|
return <<<HTML
|
|
|
|
|
<div style="float:right">
|
|
|
|
|
<a href="?otdel=$this->otdel&itmid=$itemId&itmup=1#itmdown$itemId">↿</a>
|
|
|
|
|
$itemPosition
|
|
|
|
|
<a href="?otdel=$this->otdel&itmid=$itemId&itmdown=1#itmdown$itemId">⇂</a>
|
|
|
|
|
<button onclick="window.open('/item_edit_data.php?edit_item_data=$itemId','winEdi1','width=850,height=400,top=400,left=500,resizable=no,scrollbars=yes,status=no')">
|
|
|
|
|
Редактировать предмет
|
|
|
|
|
</button>
|
|
|
|
|
<button onclick="location.href='/main.php?timeWorld=$time&otdel=$this->otdel#itmShop$itemId'">Обновить</button>
|
|
|
|
|
</div><br>
|
|
|
|
|
HTML;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buy(int $itemid): string
|
|
|
|
|
{
|
|
|
|
|
$sql = 'select sid, items_shop.price_1, name from items_shop left join items_main on item_id = id where item_id = ? and sid = ?';
|
|
|
|
|
$item = Db::getRow($sql, [$itemid, $this->shopId]);
|
|
|
|
|
if (!$this->buyer->hasEnoughCredits($item['price_1'])) {
|
|
|
|
|
return 'Покупка не удалась.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$newId = User\ItemsModel::addItem($itemid, $this->buyer->getId());
|
|
|
|
|
Db::sql('update items_users set `1price` = ? where id = ?', [$item['price_1'], $newId]);
|
|
|
|
|
User::start()->info['money'] -= $item['price_1'];
|
|
|
|
|
User::start()->addKr(-$item['price_1']);
|
|
|
|
|
Delo::add(1, "shopid:{$item['sid']}", $this->buyer->getId(), "Покупка «{$item['name']}» по цене {$item['price_1']}.", $item['price_1']);
|
|
|
|
|
return "Вы купили «{$item['name']}» по цене {$item['price_1']}.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buyEkr(int $itemid): string
|
|
|
|
|
{
|
|
|
|
|
$sql = 'select sid, items_shop.price_2, name from items_shop left join items_main on item_id = id where item_id = ? and sid = ?';
|
|
|
|
|
$item = Db::getRow($sql, [$itemid, $this->shopId]);
|
|
|
|
|
if (!$this->buyer->hasEnoughEuroCredits($item['price_2'])) {
|
|
|
|
|
return 'Покупка не удалась.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$newId = User\ItemsModel::addItem($itemid, $this->buyer->getId());
|
|
|
|
|
Db::sql('update items_users set `2price` = ? where id = ?', [$item['price_2'], $newId]);
|
|
|
|
|
User::start()->info['money2'] -= $item['price_2'];
|
|
|
|
|
User::start()->addEkr(-$item['price_2']);
|
|
|
|
|
Delo::add(1, "shopid:{$item['sid']}", $this->buyer->getId(), "Покупка «{$item['name']}» по цене {$item['price_2']}.", $item['price_2']);
|
|
|
|
|
return "Вы купили «{$item['name']}» по цене {$item['price_2']}.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buyVn(int $itemid): string
|
|
|
|
|
{
|
|
|
|
|
$sql = 'select sid, items_shop.price_4, name from items_shop left join items_main on item_id = id where item_id = ? and sid = ?';
|
|
|
|
|
$item = Db::getRow($sql, [$itemid, $this->shopId]);
|
|
|
|
|
if (!$this->buyer->hasEnoughVoinstvennost($item['price_4'])) {
|
|
|
|
|
return 'Покупка не удалась.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$newId = User\ItemsModel::addItem($itemid, $this->buyer->getId());
|
|
|
|
|
Db::sql('update items_users set `4price` = ? where id = ?', [$item['price_4'], $newId]);
|
|
|
|
|
User::start()->rep['rep3'] -= $item['price_4'];
|
|
|
|
|
User::start()->addVoinstvennost(-$item['price_4']);
|
|
|
|
|
Delo::add(1, "shopid:{$item['sid']}", $this->buyer->getId(), "Покупка «{$item['name']}» по цене {$item['price_4']}.", $item['price_4']);
|
|
|
|
|
return "Вы купили «{$item['name']}» по цене {$item['price_4']}.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getUsedOtdels(): array
|
|
|
|
|
{
|
|
|
|
|
$result = [];
|
|
|
|
|
$o = Db::getColumn('select r from items_shop where sid = ? group by r', [$this->shopId]);
|
|
|
|
|
foreach ($o as $v) {
|
|
|
|
|
$result[$v] = self::OTDEL_NAME[$v];
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getUserWallet(): string
|
|
|
|
|
{
|
|
|
|
|
$result = '';
|
|
|
|
|
if ($this->shopId === self::MAIN) {
|
|
|
|
|
$result = $this->buyer->getCredits() . ' кр.';
|
|
|
|
|
} elseif (in_array($this->shopId, [self::BEREZKA, self::ARTEFACTS])) {
|
|
|
|
|
$result = $this->buyer->getEuroCredits() . ' екр.';
|
|
|
|
|
} elseif ($this->shopId === self::SHOP_2) {
|
|
|
|
|
$result = $this->buyer->getVoinstvennost() . ' воинственности.';
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2023-07-07 15:36:23 +00:00
|
|
|
|
}
|