shopOtdel = new ShopOtdel(); $this->otdel = $otdel; $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 where sid = ? and r = ? and kolvo > 0 order by pos', [$shopId->value, $otdel]); $this->buyer = new class { public function getId(): int { return User::start()->info['id']; } public function getCredits(): float { return User::start()->info['money']; } public function getEuroCredits(): float { return User::start()->info['money2']; } public function getVoinstvennost(): int { return (int)User::start()->rep['rep3'] - (int)User::start()->rep['rep3_buy']; } public function getNextAct() { return User::start()->info['nextAct']; // что ты такое?! } public function isAdmin(): bool { return User::start()->isAdmin(); } public function hasEnough(string $parameter, int $value): bool { return User::start()->stats[$parameter] >= $value; } public function hasExactly(string $parameter, int $value): bool { return User::start()->stats[$parameter] === $value; } public function hasEnoughCredits(int $itemprice): bool { return $this->getCredits() >= $itemprice; } public function hasEnoughEuroCredits(int $itemprice): bool { return $this->getEuroCredits() >= $itemprice; } public function hasEnoughVoinstvennost(int $itemprice): bool { return $this->getVoinstvennost() >= $itemprice; } }; if ($this->buyer->isAdmin()) { if (isset($_GET['itmup'])) { $this->itemUp(); } elseif (isset($_GET['itmdown'])) { $this->itemDown(); } } if ($_SERVER["REQUEST_METHOD"] === "GET") { if ($_GET['itmup']) { $this->itemUp(); } } } private function itemUp(): void { $this->changeItemPositionByInt(-1); } private function changeItemPositionByInt(int $modificator): void { Db::sql('update items_shop set pos = pos + ? where sid = ? and r = ? and item_id = ? and kolvo > 0', [$modificator, $this->shopId->value, $this->otdel, $this->itemId]); } private function itemDown(): void { $this->changeItemPositionByInt(1); } public function printWares(): void { 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(); $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(); } $is2 = $this->name($pl['name'], $pl['renameadd'], $pl['item_id']); if ($pl['massa'] > 0) { $is2 .= '(Масса: ' . round($pl['massa'], 2) . ')'; } $is2 .= $this->icons($itemRequirements->getAlign(), $itemData['art'], $itemData['sudba']); $is2 .= $this->price($pl['price_1'], $pl['price_2'], $pl['price_4']); if ($pl['kolvo'] < 50) { $is2 .= '     (остаток на складе: ' . $pl['kolvo'] . ')'; } $is2 .= $this->needItems($pl['tr_items']); //долговечность if ($pl['iznos'] > 0) { $pl['iznosMAXi'] = $pl['iznos']; } if ($pl['iznosMAXi'] > 0 && $pl['iznosMAXi'] < 1000) { $is2 .= 'Долговечность: 0/' . $pl['iznosMAXi'] . '
'; } if ($itemData['battleUseZd'] > 0) { $is2 .= 'Задержка использования: ' . Conversion::secondsToTimeout($itemData['battleUseZd']) . '
'; } $is2 = rtrim($is2, '
'); //Срок годности предмета if ($itemData['srok'] > 0) { $pl['srok'] = $itemData['srok']; } if ($pl['srok'] > 0) { $is2 .= '
Срок годности: ' . Conversion::secondsToTimeout($pl['srok']); } if ($pl['magic_chance'] > 0) { $is2 .= '
Вероятность срабатывания: ' . 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) { $is2 .= '
Продолжительность действия: ' . Conversion::secondsToTimeout($magicDuration); } } if ($itemRequirements->get()) { $is2 .= '
Требуется минимальное:'; $is2 .= ''; } if ($itemBonuses->get()) { $is2 .= '
Действует на:'; $is2 .= ''; } $is2 .= '
Свойства предмета:'; foreach ($itemProperties->get() as $name => $value) { $is2 .= '
' . $name . ': ' . $value; } if ($pl['2too'] === 1) { $is2 .= '
Второе оружие'; } if ($pl['2h'] === 1) { $is2 .= '
Двуручное оружие'; } if (!empty($itemData['imposed'])) { if (empty($itemData['imposed_name'])) { $itemData['imposed_name'] = 'Неизвестное зачарование'; } $itemData['imposed_name'] = str_replace('Чары ', '', $itemData['imposed_name']); $is2 .= '
Зачарование: ' . $itemData['imposed_name']; } if (!empty($itemData['free_stats']) && $itemData['free_stats'] > 0) { $is2 .= '
+' . $itemData['free_stats'] . ' дополнительных характеристик'; } //Встроенная магия if (!empty($pl['magic_inci']) || !empty($pl['magic_inc'])) { if (empty($pl['magic_inc'])) { $pl['magic_inc'] = $pl['magic_inci']; } $magic = Db::getRow('select id2, mname, minfo, img from eff_main where type1 = 12345 and id2 = ?', [$pl['magic_inc']]); if ($magic['id2']) { $is2 .= '
Встроено заклятие ' . $magic['mname'] . ' ' . $magic['minfo'] . '
'; } } $is2 .= $this->getcomplect($itemData['complect']); if ($pl['max_text'] - $pl['use_text'] > 0) { $is2 .= '
Количество символов: ' . ($pl['max_text'] - $pl['use_text']) . '
'; } $is2 .= ''; if (!empty($itemData['gravi'])) { $is2 .= '
' . $itemData['gravi'] . ''; } if (!empty($itemData['info'])) { $pl['info'] .= '
' . $itemData['info']; } if (!empty($pl['info'])) { $is2 .= '
' . $pl['info'] . '
'; } if (isset($itemData['noremont'])) { $is2 .= '
Предмет не подлежит ремонту
'; } if (isset($itemData['nosale'])) { $is2 .= '
Предмет нельзя продать
'; } if (isset($itemData['nomodif'])) { $is2 .= '
Предмет нельзя улучшать
'; } if (isset($itemData['nodelete'])) { $is2 .= '
Предмет нельзя выбросить
'; } if (isset($itemData['sleep_moroz']) && $itemData['sleep_moroz'] > 0) { $is2 .= '
Предмет не портится во время сна
'; } $is2 .= '
'; $is1 = $this->imageAndControls($pl['id'], $pl['type'], $pl['img'], $pl['name'], $pl['price_1'], $pl['price_2']); echo <<$is1
{$this->adminOptions($pl['id'], $pl['pos'])} $is2
HTML; } if (empty($this->wares)) { echo '
Прилавок магазина пуст.
'; } } private function calculateMinimalPrice($basePrice, $shopPrice, $needItems) { if ($shopPrice < 0.01 && !$needItems) { $shopPrice = $basePrice; } if ($shopPrice < 0) { $shopPrice = 0; } return $shopPrice; } private function name(string $name, ?string $defaultName, int $itemid): string { $styleSuffix = ''; if ($this->shopId === ShopId::SHOP_2) { $styleSuffix = 'WL'; } if (!empty($defaultName)) { $name .= ' (Предмет: ' . $defaultName . ')'; } if (!empty($styleSuffix)) { $name = '' . $name . '  ' . $styleSuffix . ' '; } return '' . $name . '    '; } private function icons(?int $align, ?int $artefact, ?int $destiny): string { $str = '  '; if (!empty($align)) { $str .= 'Требуется склонность'; } if (!empty($artefact)) { $str .= 'Артефакт'; } $str .= $this->destiny($destiny); return $str; } private function destiny($d): string { if (empty($d)) { return ''; } if ($d == 0) { $str = 'первым, кто наденет его'; } elseif ($d == 1) { $str = 'первым, кто возьмёт его'; } else { $str = $d; } return 'Общая судьба'; } private function price(int $credits, int $eurocredits, int $voinstvennost): string { $result = 'Цена: '; if ($this->shopId === ShopId::SHOP_2) { $result .= $this->printColoredValue($this->buyer->getVoinstvennost() >= $voinstvennost, $voinstvennost); $result .= ' Воинственности '; } elseif ($this->shopId === ShopId::BEREZKA || $this->shopId === ShopId::ARTEFACTS) { $result .= ''; $result .= $this->printColoredValue($this->buyer->getEuroCredits() >= $eurocredits, $eurocredits); $result .= ' екр. '; } else { $result .= $this->printColoredValue($this->buyer->getCredits() >= $credits, $credits); $result .= ' кр.'; } return '
' . $result . ' '; } /** * Если в первом параметре передаётся false, строка во втором параметре красится в красный цвет. * @param bool $check * @param $value * @return string */ private function printColoredValue(bool $check, $value): string { $color = $check ? 'inherit' : 'red'; return sprintf('%s', $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 .= '[' . $neededItemName . '] x' . $value . ', '; } } } return $this->printColoredValue($trn, '
Требует предмет: ' . rtrim($result, ', ') . ' ') . '
'; } 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 .= '  • ' . $row['x'] . ' предметов:
'; //действие комплекта $complectBonuses = new Bonuses(Conversion::dataStringToArray($row['data'])); foreach ($complectBonuses->get() as $name => $value) { $text .= '    '; if ($name === 'Броня') { $text .= $name . ': ' . $value; } else { $text .= $name . ': ' . ($value > 0 ? '+' . $value : $value); } $text .= '
'; } } return "
Часть комплекта: $cname
$text"; } private function imageAndControls(int $id, int $type, string $image, string $name, float $credits, float $eurocredits): string { if ($type == 71) { $result = '' . $name . '
'; } else { $result = '' . $name . '
'; } if ($this->shopId == ShopId::SHOP_2) { $js = <<Купить JS; } elseif (($this->shopId == ShopId::BEREZKA || $this->shopId == ShopId::ARTEFACTS) && $this->buyer->hasEnoughEuroCredits($eurocredits)) { $js = <<Купить JS; } elseif ($this->buyer->hasEnoughCredits($credits)) { $js = <<Купить JS; } else { return ''; } return $result . $js; } private function adminOptions(int $itemId, int $itemPosition): string { if (!$this->buyer->isAdmin()) { return ''; } $time = microtime(); return <<   $itemPosition  
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->value]); 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->value]); 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->value]); 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 = []; foreach (Db::getColumn('select r from items_shop where sid = ? group by r', [$this->shopId->value]) as $v) { $result[$v] = $this->shopOtdel->getName($v); } return $result; } public function getUserWallet(): string { $result = ''; if ($this->shopId === ShopId::MAIN) { $result = $this->buyer->getCredits() . ' кр.'; } elseif (in_array($this->shopId, [ShopId::BEREZKA, ShopId::ARTEFACTS])) { $result = $this->buyer->getEuroCredits() . ' екр.'; } elseif ($this->shopId === ShopId::SHOP_2) { $result = $this->buyer->getVoinstvennost() . ' воинственности.'; } return $result; } }