'Кастеты,ножи',
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;
private int $itemId;
private $buyer;
public function __construct(int $shopId, int $otdel = 1)
{
$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, $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()
{
$this->changeItemPositionByInt(-1);
}
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]);
}
private function itemDown()
{
$this->changeItemPositionByInt(1);
}
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();
$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'] !== 999999999) {
$is2 .= 'Долговечность: 0/' . $pl['iznosMAXi'] . '
';
}
if ($itemData['battleUseZd'] > 0) {
$is2 .= 'Задержка использования: ' . ConversionHelper::secondsToTimeout($itemData['battleUseZd']) . '
';
}
$is2 = rtrim($is2, '
');
//Срок годности предмета
if ($itemData['srok'] > 0) {
$pl['srok'] = $itemData['srok'];
}
if ($pl['srok'] > 0) {
$is2 .= '
Срок годности: ' . ConversionHelper::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 .= '
Продолжительность действия: ' . ConversionHelper::secondsToTimeout($magicDuration);
}
}
if ($itemRequirements->get()) {
$is2 .= '
Требуется минимальное:';
$is2 .= '
';
}
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 === self::SHOP_2) {
$result .= $this->printColoredValue($this->buyer->getVoinstvennost() >= $voinstvennost, $voinstvennost);
$result .= ' Воинственности ';
} elseif ($this->shopId === self::BEREZKA || $this->shopId === self::ARTEFACTS) {
$result .= '';
$result .= $this->printColoredValue($this->buyer->getEuroCredits() >= $eurocredits, $eurocredits);
$result .= ' екр. ';
} else {
$result .= $this->printColoredValue($this->buyer->getCredits() >= $credits, $credits);
$result .= ' кр.';
}
return '