From f5b2b23582ff6e137d63c3cc326f576325f798ee Mon Sep 17 00:00:00 2001 From: lopar Date: Thu, 11 Mar 2021 19:43:20 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BF=D1=80=D0=B8=20=D0=BE=D0=B4=D0=B5=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B8=20=D0=BF=D1=80=D0=B5=D0=B4=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=BE=D0=B2.=20fix=20#8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/Battles/UserStats.php | 13 ++++ main.php | 108 +++++++++++++++++++--------------- 2 files changed, 73 insertions(+), 48 deletions(-) diff --git a/classes/Battles/UserStats.php b/classes/Battles/UserStats.php index 3c1079c..74a5055 100644 --- a/classes/Battles/UserStats.php +++ b/classes/Battles/UserStats.php @@ -217,5 +217,18 @@ class UserStats extends User return $this->legArmor; } + public function getFullStats() + { + $query = " + select + sum(greatest(strength + (ifnull((select sum(add_strength) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)), 0)) as allStrength, + sum(greatest(dexterity + (ifnull((select sum(add_dexterity) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)), 0)) as allDexterity, + sum(greatest(intuition + (ifnull((select sum(add_intuition) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)), 0)) as allIntuition, + sum(greatest(endurance + (ifnull((select sum(add_endurance) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)), 0)) as allEndurance, + sum(greatest(intelligence + (ifnull((select sum(add_intelligence) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)), 0)) as allIntelligence, + sum(greatest(wisdom + (ifnull((select sum(add_wisdom) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)), 0)) as allWisdom + from users where id = $this->id"; + return self::$db->ofetch($query); + } } \ No newline at end of file diff --git a/main.php b/main.php index 1625c5b..4d115b5 100644 --- a/main.php +++ b/main.php @@ -138,7 +138,6 @@ function del_efs($id, $type) // одеть предмет function dressitem($id) { - //bug #7 define('HELMET', 1); define('ARMOR', 2); define('LEGS', 3); @@ -153,57 +152,70 @@ function dressitem($id) 'TOO_MANY_ITEMS_IN_SLOTS' => 'Критическая ошибка: Переполнение слота!', 'UNKNOWN_ITEM_TYPE' => 'Неизвестный тип предмета!', 'ITEM_NOT_FOUND' => 'Предмет не найден!', + 'REQUIREMENTS_NOT_MET' => 'Персонаж не соответствует требованиям!', ]); + $userStats = new UserStats($_SESSION['uid']); $itemInSlot = []; - $selectedItemRow = db::c()->query('SELECT item_type FROM `inventory` WHERE item_id = ?i AND owner_id = ?i AND `dressed_slot` = 0', $id, $_SESSION['uid']); - if ($selectedItemRow->getNumRows()) { - $selectedItem = $selectedItemRow->fetch_object(); - $itemInSlotRow = db::c()->query('SELECT dressed_slot FROM inventory WHERE owner_id = ?i AND dressed_slot > 0 AND item_type = ?i', $_SESSION['uid'], $selectedItem->item_type); - $itemInSlotQuantity = $itemInSlotRow->getNumRows(); - if ($itemInSlotQuantity) { - while ($row = $itemInSlotRow->fetch_object()) { - $itemInSlot[] = $row->dressed_slot; - } - } - if (in_array($selectedItem->item_type, [HELMET, ARMOR, LEGS, BOOTS, GLOVES, WEAPON, SHIELD, BELT, AMULET])) { - //работаем с нормальными слотами - if (!$itemInSlotQuantity) { - // просто одеваем предмет - db::c()->query('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ?i', $id); - } elseif ($itemInSlotQuantity == 1) { - // снимаем предмет и одеваем вместо - db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ?i', $itemInSlot[0]); - db::c()->query('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ?i', $id); - } else { - // невозможная ситуация - два предмета в одиночном слоте. критическая ошибка, запись в лог, раздевание. - $error = DRESSITEM_ERROR['TOO_MANY_ITEMS_IN_SLOTS']; - db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?i', $_SESSION['uid']); - } - } elseif ($selectedItem->item_type == RING) { - // работаем с кольцами - if ($itemInSlotQuantity < 3) { - // Сравниваем массив колец и массив слотов для колец. - $emptyRingSlots = array_diff([9, 10, 11], $itemInSlot); - // Сортируем массив свободных слотов по возрастанию. - sort($emptyRingSlots); - // Одеваем предмет в первый свободный слот. - db::c()->query('UPDATE inventory SET dressed_slot = ?i WHERE item_id = ?i', $emptyRingSlots[0], $id); - } elseif ($itemInSlotQuantity == 3) { - db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = 11'); - db::c()->query('UPDATE inventory SET dressed_slot = 11 WHERE item_id = ?i', $id); - // снимаем предмет из слота 11 и одеваем вместо - } else { - // невозможная ситуация - больше трёх предметов на три слота. критическая ошибка, запись в лог, раздевание. - $error = DRESSITEM_ERROR['TOO_MANY_ITEMS_IN_SLOTS']; - db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?i', $_SESSION['uid']); - } - } else { - //предмет вообще не должен одеваться, ошибка - $error = DRESSITEM_ERROR['UNKNOWN_ITEM_TYPE']; - } - } else { + $selectedItemRow = db::c()->query('SELECT item_type,need_strength,need_dexterity,need_intuition,need_endurance,need_intelligence,need_wisdom FROM `inventory` WHERE item_id = ?i AND owner_id = ?i AND `dressed_slot` = 0 AND `durability` != 0', $id, $_SESSION['uid']); + + //$userStats->getStrength() + if (!$selectedItemRow->getNumRows()) { //с предметом что-то сильно не ок, ошибка. $error = DRESSITEM_ERROR['ITEM_NOT_FOUND']; + } else { + $selectedItem = $selectedItemRow->fetch_object(); + if ($selectedItem->need_strength > $userStats->getFullStats()->allStrength + || $selectedItem->need_dexterity > $userStats->getFullStats()->allDexterity + || $selectedItem->need_intuition > $userStats->getFullStats()->allIntuition + || $selectedItem->need_endurance > $userStats->getFullStats()->allEndurance + || $selectedItem->need_intelligence > $userStats->getFullStats()->allIntelligence + || $selectedItem->need_wisdom > $userStats->getFullStats()->allWisdom) { + $error = DRESSITEM_ERROR['REQUIREMENTS_NOT_MET']; + } else { + $itemInSlotRow = db::c()->query('SELECT dressed_slot FROM inventory WHERE owner_id = ?i AND dressed_slot > 0 AND item_type = ?i', $_SESSION['uid'], $selectedItem->item_type); + $itemInSlotQuantity = $itemInSlotRow->getNumRows(); + if ($itemInSlotQuantity) { + while ($row = $itemInSlotRow->fetch_object()) { + $itemInSlot[] = $row->dressed_slot; + } + } + if (in_array($selectedItem->item_type, [HELMET, ARMOR, LEGS, BOOTS, GLOVES, WEAPON, SHIELD, BELT, AMULET])) { + //работаем с нормальными слотами + if (!$itemInSlotQuantity) { + // просто одеваем предмет + db::c()->query('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ?i', $id); + } elseif ($itemInSlotQuantity == 1) { + // снимаем предмет и одеваем вместо + db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ?i', $itemInSlot[0]); + db::c()->query('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ?i', $id); + } else { + // невозможная ситуация - два предмета в одиночном слоте. критическая ошибка, запись в лог, раздевание. + $error = DRESSITEM_ERROR['TOO_MANY_ITEMS_IN_SLOTS']; + db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?i', $_SESSION['uid']); + } + } elseif ($selectedItem->item_type == RING) { + // работаем с кольцами + if ($itemInSlotQuantity < 3) { + // Сравниваем массив колец и массив слотов для колец. + $emptyRingSlots = array_diff([9, 10, 11], $itemInSlot); + // Сортируем массив свободных слотов по возрастанию. + sort($emptyRingSlots); + // Одеваем предмет в первый свободный слот. + db::c()->query('UPDATE inventory SET dressed_slot = ?i WHERE item_id = ?i', $emptyRingSlots[0], $id); + } elseif ($itemInSlotQuantity == 3) { + db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = 11'); + db::c()->query('UPDATE inventory SET dressed_slot = 11 WHERE item_id = ?i', $id); + // снимаем предмет из слота 11 и одеваем вместо + } else { + // невозможная ситуация - больше трёх предметов на три слота. критическая ошибка, запись в лог, раздевание. + $error = DRESSITEM_ERROR['TOO_MANY_ITEMS_IN_SLOTS']; + db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?i', $_SESSION['uid']); + } + } else { + //предмет вообще не должен одеваться, ошибка + $error = DRESSITEM_ERROR['UNKNOWN_ITEM_TYPE']; + } + } } if (isset($error)) {