Из shop уехали все запросы в класс. Теперь он только отображает.

This commit is contained in:
lopar
2021-08-30 01:34:50 +03:00
parent 4cf370327f
commit d2c8c8d7d5
7 changed files with 115 additions and 250 deletions
+436
View File
@@ -0,0 +1,436 @@
-- phpMyAdmin SQL Dump
-- version 5.0.1
-- https://www.phpmyadmin.net/
--
-- Хост: localhost
-- Время создания: Окт 21 2020 г., 17:33
-- Версия сервера: 10.3.17-MariaDB
-- Версия PHP: 7.2.24
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- База данных: `battles`
--
-- --------------------------------------------------------
--
-- Структура таблицы `bank`
--
CREATE TABLE `bank` (
`user_id` smallint(6) NOT NULL,
`money` smallint(5) UNSIGNED DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Дамп данных таблицы `bank`
--
INSERT INTO `bank` (`user_id`, `money`) VALUES
(2, 0);
-- --------------------------------------------------------
--
-- Структура таблицы `bank_logs`
--
CREATE TABLE `bank_logs` (
`id` int(11) NOT NULL,
`sender_id` smallint(6) DEFAULT NULL,
`receiver_id` smallint(6) DEFAULT NULL,
`amount` int(11) NOT NULL,
`type` varchar(16) NOT NULL,
`text` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Структура таблицы `chat`
--
CREATE TABLE `chat` (
`id` int(10) UNSIGNED NOT NULL,
`user_id` smallint(6) NOT NULL,
`receiver_id` smallint(6) DEFAULT NULL,
`msg` text NOT NULL,
`msgdate` timestamp NULL DEFAULT current_timestamp(),
`type` varchar(10) NOT NULL DEFAULT 'msg'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Chat messages';
--
-- Дамп данных таблицы `chat`
--
INSERT INTO `chat` (`id`, `user_id`, `receiver_id`, `msg`, `msgdate`, `type`) VALUES
(1, 2, NULL, 'dfdf', '2020-06-23 13:41:58', 'msg'),
(2, 2, NULL, 'А вот и чёртов чат. :)', '2020-06-23 13:42:15', 'msg'),
(3, 2, NULL, 'Почему этот кусок дебила работает в строчку?', '2020-06-23 13:42:38', 'msg'),
(4, 2, NULL, 'Переполнение!', '2020-07-21 07:15:57', 'msg'),
(5, 2, NULL, 'Надо переполнение!', '2020-07-21 07:16:03', 'msg'),
(6, 2, NULL, 'Точно надо переполнение!', '2020-07-21 07:16:10', 'msg'),
(7, 2, NULL, 'Ещё раз, переполенение.', '2020-07-21 07:16:19', 'msg'),
(8, 2, NULL, 'Текст-текстик!', '2020-07-21 07:16:25', 'msg'),
(9, 2, NULL, 'Ещё немного!', '2020-07-21 07:16:29', 'msg'),
(10, 2, NULL, 'Бдыщ!', '2020-07-21 07:16:35', 'msg'),
(11, 2, NULL, 'Серьёзно?', '2020-07-21 07:16:41', 'msg'),
(12, 2, NULL, 'Внезапно...', '2020-07-21 07:16:49', 'msg'),
(13, 2, NULL, 'Да вы издеваетесь...', '2020-07-21 07:17:00', 'msg'),
(14, 2, NULL, 'Скотыняка. :(', '2020-07-21 07:17:15', 'msg');
-- --------------------------------------------------------
--
-- Структура таблицы `inventory`
--
CREATE TABLE `inventory` (
`item_id` int(11) NOT NULL,
`owner_id` smallint(6) NOT NULL,
`name` varchar(255) NOT NULL DEFAULT 'Неизвестный предмет',
`item_type` smallint(6) NOT NULL DEFAULT 0,
`durability` smallint(6) NOT NULL,
`price` int(11) NOT NULL DEFAULT 0,
`need_strength` tinyint(4) NOT NULL DEFAULT 0,
`need_dexterity` tinyint(4) NOT NULL DEFAULT 0,
`need_intuition` tinyint(4) NOT NULL DEFAULT 0,
`need_endurance` tinyint(4) NOT NULL DEFAULT 0,
`need_intelligence` tinyint(4) NOT NULL DEFAULT 0,
`need_wisdom` tinyint(4) NOT NULL DEFAULT 0,
`add_strength` tinyint(4) NOT NULL DEFAULT 0,
`add_dexterity` tinyint(4) NOT NULL DEFAULT 0,
`add_intuition` tinyint(4) NOT NULL DEFAULT 0,
`add_endurance` tinyint(4) NOT NULL DEFAULT 0,
`add_intelligence` tinyint(4) NOT NULL DEFAULT 0,
`add_wisdom` tinyint(4) NOT NULL DEFAULT 0,
`add_accuracy` smallint(6) DEFAULT 0,
`add_evasion` smallint(6) DEFAULT 0,
`add_criticals` smallint(6) DEFAULT 0,
`add_min_physical_damage` smallint(5) UNSIGNED DEFAULT 0,
`add_max_physical_damage` smallint(5) UNSIGNED DEFAULT 0,
`dressed_slot` tinyint(4) NOT NULL DEFAULT 0,
`image` varchar(64) NOT NULL DEFAULT 'noitem.png',
`weight` smallint(5) UNSIGNED DEFAULT 1,
`on_sale` tinyint(4) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Инвентарь персонажей';
--
-- Дамп данных таблицы `inventory`
--
INSERT INTO `inventory` (`item_id`, `owner_id`, `name`, `item_type`, `durability`, `price`, `need_strength`, `need_dexterity`, `need_intuition`, `need_endurance`, `need_intelligence`, `need_wisdom`, `add_strength`, `add_dexterity`, `add_intuition`, `add_endurance`, `add_intelligence`, `add_wisdom`, `add_accuracy`, `add_evasion`, `add_criticals`, `add_min_physical_damage`, `add_max_physical_damage`, `dressed_slot`, `image`, `weight`, `on_sale`) VALUES
(1, 2, 'Кольчужка', 2, 10, 55, 10, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 'armor.png', 6, 0),
(2, 2, 'Нож', 6, 5, 12, 4, 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 'katana.png', 1, 0),
(3, 2, 'Ещё кольчужка', 2, 10, 50, 8, 2, 2, 8, 0, 0, -1, -1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'armor.png', 5, 0),
(4, 2, 'Колечко', 9, 4, 150, 15, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 20, 10, 0, 0, 0, 'ring1.png', 1, 0),
(5, 2, 'Перстенёк', 9, 6, 180, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 'ring2.png', 1, 0),
(6, 2, 'Перстенёк', 9, 6, 180, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 'ring2.png', 1, 0),
(7, 2, 'Кольцо общей слабости', 9, 100, 5311, 0, 0, 0, 0, 0, 0, -7, -7, -7, -7, -5, -5, -20, -20, -20, 0, 0, 0, 'ring1.png', 1, 0),
(8, 2, 'Кольцо общей слабости', 9, 100, 5311, 0, 0, 0, 0, 0, 0, -7, -7, -7, -7, -5, -5, -20, -20, -20, 0, 0, 0, 'ring1.png', 1, 0);
-- --------------------------------------------------------
--
-- Структура таблицы `online`
--
CREATE TABLE `online` (
`user_id` smallint(6) NOT NULL DEFAULT 0,
`date` int(12) UNSIGNED DEFAULT 0,
`real_time` int(11) NOT NULL,
`room` smallint(5) UNSIGNED DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Дамп данных таблицы `online`
--
INSERT INTO `online` (`user_id`, login_time, `real_time`, `room`) VALUES
(2, 1601412403, 1601651536, 1);
-- --------------------------------------------------------
--
-- Структура таблицы `users`
--
CREATE TABLE `users` (
`id` smallint(6) NOT NULL,
`login` varchar(64) NOT NULL,
`email` varchar(64) DEFAULT 'no_mail_set',
`pass` varchar(255) DEFAULT NULL,
`realname` varchar(64) DEFAULT NULL,
`borndate` varchar(24) DEFAULT '',
`info` longtext DEFAULT NULL,
`level` tinyint(4) NOT NULL DEFAULT 1,
`align` tinyint(4) DEFAULT 0,
`clan` varchar(16) DEFAULT '',
`money` int(11) DEFAULT 0,
`strength` tinyint(3) UNSIGNED NOT NULL DEFAULT 10,
`dexterity` tinyint(3) UNSIGNED NOT NULL DEFAULT 10,
`intuition` tinyint(3) UNSIGNED NOT NULL DEFAULT 10,
`endurance` tinyint(3) UNSIGNED NOT NULL DEFAULT 10,
`intelligence` tinyint(3) UNSIGNED NOT NULL DEFAULT 10,
`wisdom` tinyint(3) UNSIGNED NOT NULL DEFAULT 10,
`free_stat_points` tinyint(3) UNSIGNED DEFAULT 0,
`health` int(11) NOT NULL,
`mana` int(11) NOT NULL,
`ip` varchar(16) DEFAULT NULL,
`session_id` varchar(128) DEFAULT NULL,
`admin` tinyint(4) DEFAULT 0,
`enter_game` tinyint(1) NOT NULL DEFAULT 0,
`room` smallint(5) UNSIGNED NOT NULL DEFAULT 1,
`block` tinyint(4) NOT NULL DEFAULT 0,
`shadow` varchar(64) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Дамп данных таблицы `users`
--
INSERT INTO `users` (`id`, `login`, `email`, `pass`, `realname`, `borndate`, `info`, `level`, `align`, `clan`, `money`, `strength`, `dexterity`, `intuition`, `endurance`, `intelligence`, `wisdom`, `free_stat_points`, `health`, `mana`, `ip`, `session_id`, `admin`, `enter_game`, `room`, `block`, `shadow`) VALUES
(2, 'Father', 'father@battles.lan', '$2y$10$avSnIjtR/v1i5hJJ3dXH/e638WDbXFUtDmrSkUuyhmwsgmk7f35hq', 'Отец', '1986-10-20', 'И немного о себе..', 1, 6, '7', 0, 10, 10, 10, 10, 10, 10, 0, 17, 4, '192.168.20.15', 'lnuefs4n3air4jbpd76npq7hsl', 1, 0, 30, 0, 'father.png');
-- --------------------------------------------------------
--
-- Структура таблицы `users_effects`
--
CREATE TABLE `users_effects` (
`effect_id` int(11) NOT NULL,
`owner_id` smallint(6) NOT NULL,
`type` smallint(6) NOT NULL DEFAULT 0,
`name` varchar(64) NOT NULL DEFAULT 'Неизвестный эффект',
`remaining_time` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Структура таблицы `users_logs`
--
CREATE TABLE `users_logs` (
`id` int(11) NOT NULL,
`user_id` smallint(6) NOT NULL,
`author_id` smallint(6) NOT NULL DEFAULT 0,
`type` varchar(24) NOT NULL DEFAULT 'system',
`date` datetime DEFAULT current_timestamp(),
`text` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Дамп данных таблицы `users_logs`
--
INSERT INTO `users_logs` (`id`, `user_id`, `author_id`, `type`, `date`, `text`) VALUES
(1, 2, 0, 'system', '2020-07-05 23:03:52', 'Проверочная запись.');
-- --------------------------------------------------------
--
-- Структура таблицы `users_presents`
--
CREATE TABLE `users_presents` (
`id` int(11) NOT NULL,
`owner_id` smallint(6) NOT NULL,
`sender_id` smallint(6) NOT NULL,
`image` varchar(64) NOT NULL DEFAULT 'null.png'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Структура таблицы `users_recovery`
--
CREATE TABLE `users_recovery` (
`login` varchar(64) NOT NULL,
`hash` varchar(64) NOT NULL,
`ip` varchar(16) NOT NULL,
`date` varchar(64) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Индексы сохранённых таблиц
--
--
-- Индексы таблицы `bank`
--
ALTER TABLE `bank`
ADD UNIQUE KEY `bank_id_uindex` (`user_id`);
--
-- Индексы таблицы `bank_logs`
--
ALTER TABLE `bank_logs`
ADD PRIMARY KEY (`id`);
--
-- Индексы таблицы `chat`
--
ALTER TABLE `chat`
ADD PRIMARY KEY (`id`),
ADD KEY `chat_users_id_fk` (`user_id`);
--
-- Индексы таблицы `inventory`
--
ALTER TABLE `inventory`
ADD PRIMARY KEY (`item_id`),
ADD KEY `inventory_users_id_fk` (`owner_id`);
--
-- Индексы таблицы `online`
--
ALTER TABLE `online`
ADD UNIQUE KEY `online_user_id_uindex` (`user_id`);
--
-- Индексы таблицы `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `users_login_uindex` (`login`),
ADD UNIQUE KEY `users_email_uindex` (`email`);
--
-- Индексы таблицы `users_effects`
--
ALTER TABLE `users_effects`
ADD PRIMARY KEY (`effect_id`),
ADD KEY `users_effects_users_id_fk` (`owner_id`);
--
-- Индексы таблицы `users_logs`
--
ALTER TABLE `users_logs`
ADD PRIMARY KEY (`id`),
ADD KEY `users_logs_users_id_fk` (`user_id`);
--
-- Индексы таблицы `users_presents`
--
ALTER TABLE `users_presents`
ADD PRIMARY KEY (`id`),
ADD KEY `users_presents_users_id_fk` (`owner_id`);
--
-- Индексы таблицы `users_recovery`
--
ALTER TABLE `users_recovery`
ADD PRIMARY KEY (`login`),
ADD UNIQUE KEY `users_recovery_login_uindex` (`login`),
ADD UNIQUE KEY `users_recovery_hash_uindex` (`hash`);
--
-- AUTO_INCREMENT для сохранённых таблиц
--
--
-- AUTO_INCREMENT для таблицы `bank_logs`
--
ALTER TABLE `bank_logs`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT для таблицы `chat`
--
ALTER TABLE `chat`
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=15;
--
-- AUTO_INCREMENT для таблицы `inventory`
--
ALTER TABLE `inventory`
MODIFY `item_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
--
-- AUTO_INCREMENT для таблицы `users`
--
ALTER TABLE `users`
MODIFY `id` smallint(6) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- AUTO_INCREMENT для таблицы `users_effects`
--
ALTER TABLE `users_effects`
MODIFY `effect_id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT для таблицы `users_logs`
--
ALTER TABLE `users_logs`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT для таблицы `users_presents`
--
ALTER TABLE `users_presents`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- Ограничения внешнего ключа сохраненных таблиц
--
--
-- Ограничения внешнего ключа таблицы `bank`
--
ALTER TABLE `bank`
ADD CONSTRAINT `bank_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Ограничения внешнего ключа таблицы `chat`
--
ALTER TABLE `chat`
ADD CONSTRAINT `chat_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Ограничения внешнего ключа таблицы `inventory`
--
ALTER TABLE `inventory`
ADD CONSTRAINT `inventory_users_id_fk` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Ограничения внешнего ключа таблицы `online`
--
ALTER TABLE `online`
ADD CONSTRAINT `online_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Ограничения внешнего ключа таблицы `users_effects`
--
ALTER TABLE `users_effects`
ADD CONSTRAINT `users_effects_users_id_fk` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Ограничения внешнего ключа таблицы `users_logs`
--
ALTER TABLE `users_logs`
ADD CONSTRAINT `users_logs_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Ограничения внешнего ключа таблицы `users_presents`
--
ALTER TABLE `users_presents`
ADD CONSTRAINT `users_presents_users_id_fk` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+5 -11
View File
@@ -27,7 +27,7 @@ class InventoryItem extends Item
public function printInfo()
{
parent::printAllInfo();
echo $this->getAllInfo();
if ($this->present) {
echo "<p style='color: maroon; font-style: italic'>Это подарок от $this->present. Вы не можете передать его кому-либо ещё.</p>";
}
@@ -48,9 +48,8 @@ IMG;
}
}
public function printControls()
{
/* Тут будут кнопки под картинкой. */
public function printControls(){
// Для кнопок управления под картинкой.
}
private function dressStatsChecks(): ?string
@@ -130,14 +129,9 @@ IMG;
return $error ?? true;
}
/**
* @param $itemId
*
* @return bool
*/
public static function destroyItem($itemId): bool
public static function destroyItem($itemId)
{
return DBPDO::INIT()->execute('delete from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?', [$_SESSION['uid'], $itemId]);
DBPDO::INIT()->execute('delete from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?', [$_SESSION['uid'], $itemId]);
}
/** Надеюсь, временная заглушка, которая объединяет get_meshok() и другую выдачу одной строкой.
+36 -28
View File
@@ -102,6 +102,14 @@ class Item
$this->typename = 'Хлам';
}
$this->item_cost = $this->calculateItemCost();
}
/** Рассчёт стоимости предмета в зависимости от его характеристик.
* @return int
*/
private function calculateItemCost(): int
{
$sum_stats =
$this->add_strength +
$this->add_dexterity +
@@ -121,8 +129,7 @@ class Item
$mods_cost_modifier = 2 + floor($sum_mods / 50);
$damage_cost_modifier = 1 + floor($sum_damage / 100);
$result = intval($sum_stats * $stats_cost_modifier + $sum_mods * $mods_cost_modifier + $sum_damage * $damage_cost_modifier);
$this->item_cost = $result < 1 ? 1 : $result;
return $result < 1 ? 1 : $result;
}
protected function wrap(int $number): string
@@ -134,50 +141,51 @@ class Item
}
}
protected function printAllInfo()
public function getAllInfo(): string
{
$needsLines = [
"сила" => $this->need_strength,
"ловкость" => $this->need_dexterity,
"интуиция" => $this->need_intuition,
"выносливость" => $this->need_endurance,
"интеллект" => $this->need_intelligence,
"мудрость" => $this->need_wisdom,
'сила' => $this->need_strength,
'ловкость' => $this->need_dexterity,
'интуиция' => $this->need_intuition,
'выносливость' => $this->need_endurance,
'интеллект' => $this->need_intelligence,
'мудрость' => $this->need_wisdom,
];
$addsLines = [
"Сила" => $this->add_strength,
"Ловкость" => $this->add_dexterity,
"Интуиция" => $this->add_intuition,
"Выносливость" => $this->add_endurance,
"Интеллект" => $this->add_intelligence,
"Мудрость" => $this->add_wisdom,
"Точность" => $this->add_accuracy,
"Увёртливость" => $this->add_evasion,
"Шанс крита" => $this->add_criticals,
'Сила' => $this->add_strength,
'Ловкость' => $this->add_dexterity,
'Интуиция' => $this->add_intuition,
'Выносливость' => $this->add_endurance,
'Интеллект' => $this->add_intelligence,
'Мудрость' => $this->add_wisdom,
'Точность' => $this->add_accuracy,
'Увёртливость' => $this->add_evasion,
'Шанс крита' => $this->add_criticals,
];
echo "<b>$this->name</b> (Масса: $this->weight)";
echo "<br> Стоимость: " . $this->item_cost;
echo "<br> Долговечность: " . $this->durability;
echo "<br><em>$this->typename</em><br>";
$str = "<b>$this->name</b> (Масса: $this->weight)";
$str .= '<br> Стоимость: ' . $this->item_cost;
$str .= '<br> Долговечность: ' . $this->durability;
$str .= "<br><em>$this->typename</em><br>";
foreach ($needsLines as $stat => $value) {
if ($value > 0) {
echo "<br>Требуется $stat" . $this->wrap($value);
$str .= "<br>Требуется $stat" . $this->wrap($value);
}
}
foreach ($addsLines as $stat => $value) {
if ($value) {
echo "<br>$stat" . $this->wrap($value);
$str .= "<br>$stat" . $this->wrap($value);
}
}
if ($this->add_min_physical_damage && !$this->add_max_physical_damage) {
$damage = $this->add_min_physical_damage . " - " . $this->add_min_physical_damage;
$damage = $this->add_min_physical_damage . ' - ' . $this->add_min_physical_damage;
} elseif (!$this->add_min_physical_damage && $this->add_max_physical_damage) {
$damage = $this->add_max_physical_damage . " - " . $this->add_max_physical_damage;
$damage = $this->add_max_physical_damage . ' - ' . $this->add_max_physical_damage;
} elseif ($this->add_min_physical_damage && $this->add_max_physical_damage) {
$damage = $this->add_min_physical_damage . " - " . $this->add_max_physical_damage;
$damage = $this->add_min_physical_damage . ' - ' . $this->add_max_physical_damage;
}
if (isset($damage)) {
echo "<br>Урон: " . $damage;
$str .= '<br>Урон: ' . $damage;
}
return $str;
}
}
+25 -24
View File
@@ -49,6 +49,7 @@ SQL;
private $optype;
private ?int $shop_item_quantity;
private ?int $price;
public static string $status = '';
public function __construct($row, $operationType = null)
{
@@ -61,11 +62,12 @@ SQL;
$this->item_id = $row->item_id ?? $row->id;
}
public function printInfo()
public function printInfo(): string
{
$this->printAllInfo();
//$this->printAllInfo();
$str = $this->getAllInfo();
if ($this->optype === 'buyshop' && $this->shop_item_quantity > 0 && $this->shop_item_quantity < 20) {
echo "<div style='margin-top: 9px; font-style: italic;'>На складе осталось $this->shop_item_quantity единиц товара!</div>";
$str .= "<div style='margin-top: 9px; font-style: italic;'>На складе осталось $this->shop_item_quantity единиц товара!</div>";
}
if ($this->optype === 'sellshop') {
if ($this->getSellPriceMean() < 50) {
@@ -79,36 +81,37 @@ SQL;
} else {
$goods = 'это превосходное изделие';
}
echo "<div style='margin-top: 9px; font-style: italic;'>В среднем за $goods можно выручить <span class='success'>{$this->getSellPriceMean()}</span> кр.</div>";
$str .= "<div style='margin-top: 9px; font-style: italic;'>В среднем за $goods можно выручить <span class='success'>{$this->getSellPriceMean()}</span> кр.</div>";
}
return $str;
}
public function printImage()
public function printImage(): string
{
if (!$this->image) {
$this->image = 'noitem.png';
}
echo "<img src='/i/sh/$this->image' class='item-wrap-normal' alt=''>";
return "<img src='/i/sh/$this->image' class='item-wrap-normal' alt=''>";
}
//todo наличка после покупки отображается с задержкой.
public static function buyItem($id, User $buyer): string
public static function buyItem($id, User $buyer)
{
$db = new DBPDO();
$check = $db->ofetch("select * from trade_offers where shop_item_id = ?", $id);
if (empty($check->shop_item_quantity) || empty($check->shop_item_id)) {
return self::NO_ITEMS_IN_STOCK;
self::$status = self::NO_ITEMS_IN_STOCK;
}
// TODO БАРТЕР!
if (isset($check->barter_item_list_json)) {
echo "Работаем по бартеру!";
self::$status = "Работаем по бартеру!";
}
$db->execute(self::BUY_QUERY, [$buyer->getId(), $check->shop_item_id]);
$item = $db->ofetch("select item_id, name, price from inventory where item_id = ?", $db->lastInsertId());
if (empty($item->item_id) || empty($item->name)) {
return 'Запрос в базу не прошёл.';
self::$status = 'Запрос в базу не прошёл.';
} else {
$user = new User($_SESSION['uid']);
// Если не хватает налички, снимаем с банка с комиссией.
@@ -117,14 +120,12 @@ SQL;
$bank = new Bank($buyer->getId());
$bank->withdrawMoney($item->price);
} catch (GameException $e) {
echo 'Банковская ошибка!';
return self::NO_MONEY;
self::$status = 'Банковская ошибка! ' . self::NO_MONEY;
}
} else {
$user->setMoney($user->getMoney() - $item->price);
$user->saveMoney();
}
}
if ($check->shop_item_quantity != -1) {
@@ -133,10 +134,10 @@ SQL;
$deloText = $buyer->getLogin() . " купил товар «" . $item->name . "» id:(" . $item->item_id . ") в магазине за " . $item->price . ".";
GameLogs::addUserLog($buyer->getId(), $deloText);
return "Предмет " . $item->name . " куплен за " . $item->price . ".";
self::$status = "Предмет " . $item->name . " куплен за " . $item->price . ".";
}
public static function sellItem($id, User $seller, $bankTrade = 0): string
public static function sellItem($id, User $seller, $bankTrade = 0)
{
$db = new DBPDO();
$item = $db->ofetch('select * from inventory where item_id = ?', $id);
@@ -154,11 +155,10 @@ SQL;
$deloText = "{$seller->getLogin()} продал товар «{$sellingItemName}» id:($id) в магазине за $sellingPrice кр.";
GameLogs::addUserLog($seller->getId(), $deloText);
if ($sellingPrice == 0) {
$status = "После длительных и изнурительных торгов вы плюнули на всё и просто подарили ваш «{$sellingItemName}» торговцу.";
self::$status = "После длительных и изнурительных торгов вы плюнули на всё и просто подарили ваш «{$sellingItemName}» торговцу.";
} else {
$status = "Вы продали «{$sellingItemName}» за $sellingPrice кр.";
self::$status = "Вы продали «{$sellingItemName}» за $sellingPrice кр.";
}
return $status;
}
/** Подчсчёт средней суммы продажи.
@@ -177,18 +177,19 @@ SQL;
/**
* Для кнопок управления под картинкой предмета в зависимости от ситуации.
*/
public function printControls()
public function printControls(): string
{
if (in_array($this->optype, ['setmarket', 'unsetmarket', 'buymarket', 'sellshop', 'buyshop',])) {
$str = $this->optype == 'setmarket' ? '<input placeholder=" ' . $this->price . ' " name="cost">' : '';
$button_name = self::BUTTON[$this->optype];
echo <<<FORM
if (!in_array($this->optype, ['setmarket', 'unsetmarket', 'buymarket', 'sellshop', 'buyshop',])) {
return '';
}
$str = $this->optype == 'setmarket' ? '<input placeholder=" ' . $this->price . ' " name="cost">' : '';
$button_name = self::BUTTON[$this->optype];
return <<<FORM
<form method="post">$str
<input type="hidden" name="itemId" value="$this->item_id">
<br><input type="submit" name="$this->optype" value="$button_name">
</form>
FORM;
}
}
/**