From 12feda506a9106d1888cc28e88a43b803ba782b1 Mon Sep 17 00:00:00 2001 From: "Igor Barkov (iwork)" Date: Tue, 21 Jul 2020 18:03:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20Item=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=20=D0=BD=D0=BE=D0=B2=D1=83=D1=8E=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=B7=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/DressedItems.php | 50 +++---- classes/InventoryItem.php | 21 ++- classes/Item.php | 284 +++++++++++++++----------------------- classes/ShopItem.php | 4 +- main.php | 8 +- 5 files changed, 151 insertions(+), 216 deletions(-) diff --git a/classes/DressedItems.php b/classes/DressedItems.php index 66bc041..8edb106 100644 --- a/classes/DressedItems.php +++ b/classes/DressedItems.php @@ -7,9 +7,9 @@ class DressedItems { - private static $DB; - private static $DBSUM; - private static $USERID; + private $DB; + private $DBSUM; + private $USERID; private $dressedItem; /** @@ -19,14 +19,13 @@ class DressedItems */ public function __construct($user_id) { - //$this->USERID = $user_id; - self::$USERID = $user_id; + $this->USERID = $user_id; } - private static function getDressedItems() + private function getDressedItems() { try { - self::$DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', self::$USERID); + $this->DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $this->USERID); } catch (Exception $e) { echo '
Не прогрузилась таблица inventory (*) для класса DressedItems.
'; } @@ -50,7 +49,7 @@ SELECT SUM(add_strength) as sum_strength, SUM(weight) as sum_weight FROM inventory WHERE owner_id = ?i AND dressed_slot > 0 SQL; - self::$DBSUM = db::c()->query($query, self::$USERID)->fetch_assoc(); + $this->DBSUM = db::c()->query($query, $this->USERID)->fetch_assoc(); } catch (Exception $e) { echo '
Не прогрузилась таблица inventory (SUM) для класса DressedItems:' . $e . '
'; } @@ -58,66 +57,69 @@ SQL; public function getItemsInSlots() { - if (!self::$DB) { - //$this->getDressedItems(); + if (!$this->DB) { self::getDressedItems(); } - while ($row = self::$DB->fetch_assoc()) { + while ($row = $this->DB->fetch_assoc()) { $dressed_item[$row['dressed_slot']] = $row; $this->dressedItem[$row['dressed_slot']] = $row; } return $this->dressedItem; } - protected function getBonuses() + private function getBonuses() { - if (!self::$DBSUM) { + if (!$this->DBSUM) { self::getBonusesFromDressedItems(); } - return self::$DBSUM; + return $this->DBSUM; } public function getStrengthBonus() { - - //return $this->getBonuses()['sum_strength']; return self::getBonuses()['sum_strength']; } public function getDexterityBonus() { - return $this->getBonuses()['sum_dexterity']; + return self::getBonuses()['sum_dexterity']; } public function getIntuitionBonus() { - return $this->getBonuses()['sum_intuition']; + return self::getBonuses()['sum_intuition']; } public function getEnduranceBonus() { - return $this->getBonuses()['sum_endurance']; + return self::getBonuses()['sum_endurance']; } public function getIntelliganceBonus() { - return $this->getBonuses()['sum_intelligence']; + return self::getBonuses()['sum_intelligence']; } public function getWisdomBonus() { - return $this->getBonuses()['sum_wisdom']; + return self::getBonuses()['sum_wisdom']; } public function getAccuracyBonus() { - return $this->getBonuses()['sum_accuracy']; + return self::getBonuses()['sum_accuracy']; } public function getEvasionBonus() { - return $this->getBonuses()['sum_evasion']; + return self::getBonuses()['sum_evasion']; } public function getCriticalsBonus() { - return $this->getBonuses()['sum_criticals']; + return self::getBonuses()['sum_criticals']; } public function getItemsWeight() { return self::getBonuses()['sum_weight']; } + public function undressItem($slot_id) + { + if (!$slot_id || $this->dressedItem[$slot_id]) { + db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ?i AND owner_id = ?i', $slot_id, $this->USERID); + } + } } \ No newline at end of file diff --git a/classes/InventoryItem.php b/classes/InventoryItem.php index a3958e9..80f80da 100644 --- a/classes/InventoryItem.php +++ b/classes/InventoryItem.php @@ -8,28 +8,25 @@ class InventoryItem extends Item { parent::__construct($row); $this->present = $row['present']; - - if ($this->artefact) $this->name = <<{$this->name} -NAME; } public function printInfo() { - parent::printBaseInfo(); - parent::printRequirements(); - parent::printBonuses(); - if ($this->present) echo "

Это подарок от {$this->present}. Вы не можете передать его кому-либо ещё.

"; + parent::printAllInfo(); + if ($this->present) { + echo "

Это подарок от {$this->present}. Вы не можете передать его кому-либо ещё.

"; + } } public function printImage() { - if (!in_array($this->type,[12,50,200])) { - echo "id} title='Надеть'>"; + if (!in_array($this->item_type, [12, 50, 200])) { + echo "item_id} title='Надеть'>"; parent::printImage(); echo ""; + } else { + parent::printImage(); } - else parent::printImage(); } /** @@ -45,6 +42,6 @@ BTN; public function getId() { - return $this->id; + return $this->item_id; } } \ No newline at end of file diff --git a/classes/Item.php b/classes/Item.php index 751900c..6508cdd 100644 --- a/classes/Item.php +++ b/classes/Item.php @@ -2,91 +2,30 @@ abstract class Item { - public $id; + public $item_id; public $name; - public $nalign; - public $massa; - public $maxdur; - public $img; - - public $cost; - public $artefact; - - public $type; - - public $nlevel; - public $nsila; - public $nlovk; - public $ninta; - public $nvinos; - public $nintel; - public $nmudra; - public $nnoj; - public $ntopor; - public $ndubina; - public $nmech; - public $nfire; - public $nwater; - public $nair; - public $nearth; - public $nlight; - public $ngray; - public $ndark; - - public $minu; - public $maxu; - - public $gsila; - public $glovk; - public $ginta; - public $gintel; - public $gnoj; - public $gtopor; - public $gdubina; - public $gmech; - public $gfire; - public $gwater; - public $gair; - public $gearth; - public $glight; - public $ggray; - public $gdark; - public $ghp; - - public $bron1; - public $bron2; - public $bron3; - public $bron4; - - public $mfkrit; - public $mfakrit; - public $mfuvorot; - public $mfauvorot; - - public $dategoden; - public $goden; - public $needident; - public $magic; - public $magic_name; - public $magic_img; - public $isrep; - public $gmp; - - public $encicl; - - public $koll; - public $prof; - public $prof1; - - public $count; - public $razdel; - public $ecost; - public $zeton; - public $onlyone; - public $shshop; - public $otdel; - public $setsale; - + public $item_type; + public $durability; + public $price; + public $need_strength; + public $need_dexterity; + public $need_intuition; + public $need_endurance; + public $need_intelligence; + public $need_wisdom; + public $add_strength; + public $add_dexterity; + public $add_intuition; + public $add_endurance; + public $add_intelligence; + public $add_wisdom; + public $add_accuracy; + public $add_evasion; + public $add_criticals; + public $add_min_physical_damage; + public $add_max_physical_damage; + public $weight; + public $image; /** * Item constructor. @@ -101,46 +40,38 @@ abstract class Item } } - switch ($this->type) { + switch ($this->item_type) { case 1: - $this->typename = 'Серьги'; - break; - case 2: - $this->typename = 'Ожерелье'; - break; - case 3: - $this->typename = 'Оружие'; - break; - case 4: - $this->typename = 'Броня'; - break; - case 5: - $this->typename = 'Кольцо'; - break; - - case 8: $this->typename = 'Шлем'; break; - case 9: + case 2: + $this->typename = 'Броня'; + break; + case 3: + $this->typename = 'Поножи'; + break; + case 4: + $this->typename = 'Сапоги'; + break; + case 5: $this->typename = 'Перчатки'; break; - case 10: + case 6: + $this->typename = 'Оружие'; + break; + case 7: $this->typename = 'Щит'; break; + case 8: + $this->typename = 'Пояс'; + break; + case 9: + case 10: case 11: - $this->typename = 'Обувь'; + $this->typename = 'Кольцо'; break; case 12: - $this->typename = 'Магический свиток'; - break; - case 22: - $this->typename = 'Рубашка'; - break; - case 50: - $this->typename = 'Волшебное зелье'; - break; - case 200: - $this->typename = 'Сувенир'; + $this->typename = 'Амулет'; break; default: $this->typename = 'Хлам'; @@ -152,73 +83,80 @@ abstract class Item public function printImage() { echo << + IMG; } protected function wrap($number) { - if ($number > 0) return ": " . $number . ""; - else return ": " . $number . ""; + if ($number > 0) { + return ": " . $number . ""; + } else { + return ": " . $number . ""; + } } - protected function printBaseInfo() + protected function printAllInfo() { - echo "" . $this->name . " (Масса: " . $this->massa . ")"; - if ($this->nalign) echo " nalign}.gif title='Этот предмет могут использовать только игроки с определённой склонностью.'> "; - if ($this->maxdur > 0) echo "
Долговечность: {$this->maxdur}"; - if ($this->maxdur == -1) echo "
Долговечность: неразрушимо"; - echo "
{$this->typename}"; - } - - protected function printRequirements() - { - if ($this->nlevel > 0) echo "
Требуется уровень" . $this->wrap($this->nlevel); - if ($this->nnoj > 0) echo "
Требуется владение колющим оружиием" . $this->wrap($this->nnoj); - if ($this->ndubina > 0) echo "
Требуется владение дробящим оружием" . $this->wrap($this->ndubina); - if ($this->ntopor > 0) echo "
Требуется владение рубящим оружием" . $this->wrap($this->ntopor); - if ($this->nmech > 0) echo "
Требуется владение режущим оружием" . $this->wrap($this->nmech); - if ($this->nsila > 0) echo "
Требуется сила" . $this->wrap($this->nsila); - if ($this->nlovk > 0) echo "
Требуется ловкость" . $this->wrap($this->nlovk); - if ($this->ninta > 0) echo "
Требуется интуиция" . $this->wrap($this->ninta); - if ($this->nvinos > 0) echo "
Требуется выносливость" . $this->wrap($this->nvinos); - if ($this->nintel > 0) echo "
Требуется интеллект" . $this->wrap($this->nintel); - } - - protected function printBonuses() - { - if ($this->gsila) echo "
Сила" . $this->wrap($this->gsila); - if ($this->glovk) echo "
Ловкость" . $this->wrap($this->glovk); - if ($this->ginta) echo "
Интуиция" . $this->wrap($this->ginta); - if ($this->gintel) echo "
Интеллект" . $this->wrap($this->gintel); - if ($this->minu AND $this->maxu) echo "
Урон: {$this->minu} - {$this->maxu}"; - if ($this->ghp) echo "
Здоровье" . $this->wrap($this->ghp); - if ($this->gnoj) echo "
Владение колющим оружиием" . $this->wrap($this->gnoj); - if ($this->gdubina) echo "
Владение дробящим оружием" . $this->wrap($this->gdubina); - if ($this->gtopor) echo "
Владение рубящим оружием" . $this->wrap($this->gtopor); - if ($this->gmech) echo "
Владение режущим оружием" . $this->wrap($this->gmech); - if ($this->gfire) echo "
Владение магией огня" . $this->wrap($this->gfire); - if ($this->gwater) echo "
Владение магией воды" . $this->wrap($this->gwater); - if ($this->gair) echo "
Владение магией воздуха" . $this->wrap($this->gair); - if ($this->gearth) echo "
Владение магией земли" . $this->wrap($this->gearth); - if ($this->glight) echo "
Владение магией света" . $this->wrap($this->glight); - if ($this->ggray) echo "
Владение магией серости" . $this->wrap($this->ggray); - if ($this->gdark) echo "
Владение магией тьмы" . $this->wrap($this->gdark); - if ($this->mfkrit) echo "
Шанс крита" . $this->wrap($this->mfkrit); - if ($this->mfakrit) echo "
Шанс антикрита" . $this->wrap($this->mfakrit); - if ($this->mfuvorot) echo "
Шанс уворота" . $this->wrap($this->mfuvorot); - if ($this->mfauvorot) echo "
Шанс антиуворота" . $this->wrap($this->mfauvorot); - if ($this->bron1) echo "
Броня головы" . $this->wrap($this->bron1); - if ($this->bron2) echo "
Броня корпуса" . $this->wrap($this->bron2); - if ($this->bron3) echo "
Броня пояса" . $this->wrap($this->bron3); - if ($this->bron4) echo "
Броня ног" . $this->wrap($this->bron4); - if ($this->magic AND $this->type != 12) { - echo "
Магические свойства:"; - if ($this->magic_name) echo "
{$this->magic_name}"; - else echo "
Неопознанная магия"; - if ($this->magic_img AND $this->type != 50) echo << -IMG; + echo "" . $this->name . " (Масса: " . $this->weight . ")"; + if ($this->durability) { + echo "
Долговечность:" . $this->durability; + } + echo "
{$this->typename}
"; + if ($this->need_strength > 0) { + echo "
Требуется сила" . $this->wrap($this->need_strength); + } + if ($this->need_dexterity > 0) { + echo "
Требуется ловкость" . $this->wrap($this->need_dexterity); + } + if ($this->need_intuition > 0) { + echo "
Требуется интуиция" . $this->wrap($this->need_intuition); + } + if ($this->need_endurance > 0) { + echo "
Требуется выносливость" . $this->wrap($this->need_endurance); + } + if ($this->need_intelligence > 0) { + echo "
Требуется интеллект" . $this->wrap($this->need_intelligence); + } + if ($this->need_wisdom > 0) { + echo "
Требуется мудрость" . $this->wrap($this->need_wisdom); + } + if ($this->add_strength > 0) { + echo "
Сила" . $this->wrap($this->add_strength); + } + if ($this->add_dexterity) { + echo "
Ловкость" . $this->wrap($this->add_dexterity); + } + if ($this->add_intuition) { + echo "
Интуиция" . $this->wrap($this->add_intuition); + } + if ($this->add_endurance) { + echo "
Выносливость" . $this->wrap($this->add_endurance); + } + if ($this->add_intelligence) { + echo "
Интеллект" . $this->wrap($this->add_intelligence); + } + if ($this->add_wisdom) { + echo "
Мудрость" . $this->wrap($this->add_wisdom); + } + if ($this->add_accuracy) { + echo "
Точность" . $this->wrap($this->add_accuracy); + } + if ($this->add_evasion) { + echo "
Увёртливость" . $this->wrap($this->add_evasion); + } + if ($this->add_criticals) { + echo "
Шанс крита" . $this->wrap($this->add_criticals); + } + if ($this->add_min_physical_damage && !$this->add_max_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; + } elseif ($this->add_min_physical_damage && $this->add_max_physical_damage) { + $damage = $this->add_min_physical_damage . " - " . $this->add_max_physical_damage; + } + if ($damage) { + echo "Урон: " . $damage; } } } \ No newline at end of file diff --git a/classes/ShopItem.php b/classes/ShopItem.php index 70a3278..8606278 100644 --- a/classes/ShopItem.php +++ b/classes/ShopItem.php @@ -4,9 +4,7 @@ class ShopItem extends Item { public function printInfo() { - parent::printBaseInfo(); - parent::printRequirements(); - parent::printBonuses(); + parent::printAllInfo(); } public function buyItem($owner) diff --git a/main.php b/main.php index 4ebac61..47557af 100644 --- a/main.php +++ b/main.php @@ -563,7 +563,7 @@ if (input::post('setshadow')) { die(); } -if (input::get('edit')) { +if (isset($_GET['edit'])) { if (input::get('ups')) { addOnePoint(input::get('ups'), 'stat'); @@ -573,9 +573,9 @@ if (input::get('edit')) { addOnePoint(input::get('upm'), 'mastery'); } - if (input::get('drop')) { - dropitem(input::get('drop')); - updstats(); + if (isset($_GET['drop'])) { + $items = new DressedItems($_SESSION['uid']); + $items->undressItem($_GET['drop']); } if (input::get('dress')) {