This commit is contained in:
2023-11-09 19:24:47 +02:00
parent 1645f58a63
commit fc17eada24
19 changed files with 1255 additions and 953 deletions
+44 -106
View File
@@ -5,107 +5,34 @@ namespace Location;
use Core\Config;
use Core\Db;
use Delo;
use Enum\ShopId;
use Helper\Conversion;
use Item\Data\Bonuses;
use Item\Data\Properties;
use Item\Data\Requirements;
use Item\DataModel;
use Model\Constant\ShopOtdel;
use User;
class Shop
{
private const ITEM_GENERATION_CURRENT = 2;
public const MAIN = 1;
public const BEREZKA = 2;
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; // магазин новичка
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;
public ShopOtdel $shopOtdel;
private ShopId $shopId;
private array $wares;
private int $otdel;
private int $itemId;
private $buyer;
public function __construct(int $shopId, int $otdel = 1)
public function __construct(ShopId $shopId, int $otdel = 1)
{
$this->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, $otdel]);
where sid = ? and r = ? and kolvo > 0 order by pos', [$shopId->value, $otdel]);
$this->buyer = new class {
public function getId(): int
@@ -178,23 +105,23 @@ class Shop
}
}
private function itemUp()
private function itemUp(): void
{
$this->changeItemPositionByInt(-1);
}
private function changeItemPositionByInt(int $modificator)
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, $this->otdel, $this->itemId]);
[$modificator, $this->shopId->value, $this->otdel, $this->itemId]);
}
private function itemDown()
private function itemDown(): void
{
$this->changeItemPositionByInt(1);
}
public function printWares()
public function printWares(): void
{
foreach ($this->wares as $pl) {
$data = new DataModel($pl['item_id']);
@@ -229,7 +156,7 @@ class Shop
if ($pl['iznos'] > 0) {
$pl['iznosMAXi'] = $pl['iznos'];
}
if ($pl['iznosMAXi'] > 0 && $pl['iznosMAXi'] !== 999999999) {
if ($pl['iznosMAXi'] > 0 && $pl['iznosMAXi'] < 1000) {
$is2 .= 'Долговечность: 0/' . $pl['iznosMAXi'] . '<br>';
}
@@ -264,11 +191,14 @@ class Shop
$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: \'× \';">';
$value = $dataName === 'align' ? intval($dataInfo['sysvalue']) : intval($dataInfo['value']);
$is2 .= $this->buyer->hasExactly($dataName, $value) ? '<li>' : '<li style="color: crimson; list-style-type: \'× \';">';
} else {
$is2 .= $this->buyer->hasEnough($dataName, intval($dataInfo['value'])) ? '<li>' : '<li style="color: crimson; list-style-type: \'× \';">';
}
$is2 .= $dataInfo['name'] . ': ' . $dataInfo['value'];
$name = empty($dataInfo['name']) ? $dataName : $dataInfo['name'];
$is2 .= $name . ': ' . $dataInfo['value'];
//$is2 .= $dataName . ': ' . $dataInfo;
$is2 .= '</li>';
}
$is2 .= '</ul>';
@@ -391,7 +321,7 @@ HTML;
private function name(string $name, ?string $defaultName, int $itemid): string
{
$styleSuffix = '';
if ($this->shopId == self::SHOP_2) {
if ($this->shopId === ShopId::SHOP_2) {
$styleSuffix = 'WL';
}
if (!empty($defaultName)) {
@@ -437,10 +367,10 @@ HTML;
private function price(int $credits, int $eurocredits, int $voinstvennost): string
{
$result = 'Цена: ';
if ($this->shopId === self::SHOP_2) {
if ($this->shopId === ShopId::SHOP_2) {
$result .= $this->printColoredValue($this->buyer->getVoinstvennost() >= $voinstvennost, $voinstvennost);
$result .= ' Воинственности ';
} elseif ($this->shopId === self::BEREZKA || $this->shopId === self::ARTEFACTS) {
} elseif ($this->shopId === ShopId::BEREZKA || $this->shopId === ShopId::ARTEFACTS) {
$result .= '<span style="color: cornflowerblue;">';
$result .= $this->printColoredValue($this->buyer->getEuroCredits() >= $eurocredits, $eurocredits);
$result .= ' екр.</span> ';
@@ -524,14 +454,23 @@ HTML;
} 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>';
if ($this->shopId == ShopId::SHOP_2) {
$js = <<<JS
<button onClick="top.buyShopNow($id,'?otdel=$this->otdel&buyVn=$id&sd4={$this->buyer->getNextAct()}','$name')">Купить</button>
JS;
} elseif (($this->shopId == ShopId::BEREZKA || $this->shopId == ShopId::ARTEFACTS) && $this->buyer->hasEnoughEuroCredits($eurocredits)) {
$js = <<<JS
<button onClick="top.buyShopNow($id,'?otdel=$this->otdel&buyEkr=$id&sd4={$this->buyer->getNextAct()}','$name',$eurocredits,'екр.')">Купить</button>
JS;
} 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>';
$js = <<<JS
<button onClick="top.buyShopNow($id,'?otdel=$this->otdel&buy=$id&sd4={$this->buyer->getNextAct()}','$name',$credits,'кр.')">Купить</button>
JS;
} else {
return '';
}
return $result;
return $result . $js;
}
private function adminOptions(int $itemId, int $itemPosition): string
@@ -556,7 +495,7 @@ 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]);
$item = Db::getRow($sql, [$itemid, $this->shopId->value]);
if (!$this->buyer->hasEnoughCredits($item['price_1'])) {
return 'Покупка не удалась.';
}
@@ -572,7 +511,7 @@ HTML;
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]);
$item = Db::getRow($sql, [$itemid, $this->shopId->value]);
if (!$this->buyer->hasEnoughEuroCredits($item['price_2'])) {
return 'Покупка не удалась.';
}
@@ -588,7 +527,7 @@ HTML;
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]);
$item = Db::getRow($sql, [$itemid, $this->shopId->value]);
if (!$this->buyer->hasEnoughVoinstvennost($item['price_4'])) {
return 'Покупка не удалась.';
}
@@ -604,9 +543,8 @@ HTML;
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];
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;
}
@@ -614,11 +552,11 @@ HTML;
public function getUserWallet(): string
{
$result = '';
if ($this->shopId === self::MAIN) {
if ($this->shopId === ShopId::MAIN) {
$result = $this->buyer->getCredits() . ' кр.';
} elseif (in_array($this->shopId, [self::BEREZKA, self::ARTEFACTS])) {
} elseif (in_array($this->shopId, [ShopId::BEREZKA, ShopId::ARTEFACTS])) {
$result = $this->buyer->getEuroCredits() . ' екр.';
} elseif ($this->shopId === self::SHOP_2) {
} elseif ($this->shopId === ShopId::SHOP_2) {
$result = $this->buyer->getVoinstvennost() . ' воинственности.';
}
return $result;