Удалён зодиак. Фиксы перехода php7.2 -> php7.4. Покупка и продажа за банкноты (#25). Унификация вывода кнопок в магазине. Удалён старый закомментированый код. Больше констант. Плавная текучка от библиотеки db::c в сторону DBPDO. И тому подобное. Процесс идёт...
This commit is contained in:
@@ -21,6 +21,7 @@ class InventoryItem extends Item
|
||||
{
|
||||
parent::__construct($row);
|
||||
$this->owner_id = $row->owner_id;
|
||||
$this->present = $row->present;
|
||||
$this->db = DBPDO::INIT();
|
||||
}
|
||||
|
||||
@@ -28,7 +29,7 @@ class InventoryItem extends Item
|
||||
{
|
||||
parent::printAllInfo();
|
||||
if ($this->present) {
|
||||
echo "<p style='color: maroon; font-style: italic'>Это подарок от {$this->present}. Вы не можете передать его кому-либо ещё.</p>";
|
||||
echo "<p style='color: maroon; font-style: italic'>Это подарок от $this->present. Вы не можете передать его кому-либо ещё.</p>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +72,6 @@ IMG;
|
||||
*/
|
||||
public function dressItem()
|
||||
{
|
||||
$db = new DBPDO();
|
||||
$itemInSlot = [];
|
||||
if ($this->dressStatsChecks()) {
|
||||
return self::REQUIREMENTS_NOT_MET;
|
||||
@@ -79,8 +79,8 @@ IMG;
|
||||
// считаем сколько ОДЕТЫХ предметов в слоте в который мы хотим одеть предмет. 1=просто вещь 1-3=шашни с кольцами
|
||||
// Count добавленный в первый запрос возвращает одну строку в любом случае.
|
||||
// fetch возвращает одну строку в любом случае.
|
||||
$weared = $db->ofetchAll('SELECT dressed_slot FROM inventory WHERE dressed_slot != 0 AND item_type = ? AND owner_id = ?', [$this->item_type, $this->owner_id]);
|
||||
$wearedCount = $db->ofetch('select count(dressed_slot) as c from inventory where dressed_slot !=0 and item_type = ? and owner_id = ?', [$this->item_type, $this->owner_id]);
|
||||
$weared = $this->db->ofetchAll('SELECT dressed_slot FROM inventory WHERE dressed_slot != 0 AND item_type = ? AND owner_id = ?', [$this->item_type, $this->owner_id]);
|
||||
$wearedCount = $this->db->ofetch('select count(dressed_slot) as c from inventory where dressed_slot !=0 and item_type = ? and owner_id = ?', [$this->item_type, $this->owner_id]);
|
||||
// Если в слоте есть предмет(ы), забиваем их массив одетых в слот предметов.
|
||||
if ($wearedCount) {
|
||||
foreach ($weared as $item) {
|
||||
@@ -95,11 +95,11 @@ IMG;
|
||||
//работаем с нормальными слотами
|
||||
if ($wearedCount->c == 1) {
|
||||
//если слот занят, снимаем старый предмет и одеваем новый предмет
|
||||
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$itemInSlot[0], $this->owner_id]);
|
||||
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ? AND owner_id = ?', [$this->item_id, $this->owner_id]);
|
||||
$this->db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$itemInSlot[0], $this->owner_id]);
|
||||
$this->db->execute('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ? AND owner_id = ?', [$this->item_id, $this->owner_id]);
|
||||
} elseif (!$wearedCount->c) {
|
||||
//если слот пуст, одеваем новый предмет
|
||||
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ? AND owner_id = ?', [$this->item_id, $this->owner_id]);
|
||||
$this->db->execute('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ? AND owner_id = ?', [$this->item_id, $this->owner_id]);
|
||||
} else {
|
||||
/* проверка на переполнение слотов */
|
||||
$error = self::TOO_MANY_ITEMS_IN_SLOTS;
|
||||
@@ -113,11 +113,11 @@ IMG;
|
||||
// Сортируем массив свободных слотов по возрастанию.
|
||||
sort($emptyRingSlots);
|
||||
// Одеваем предмет в первый свободный слот.
|
||||
DBPDO::INIT()->execute('update inventory set dressed_slot = ? where item_id = ?', [$emptyRingSlots[0], $this->item_id]);
|
||||
$this->db->execute('update inventory set dressed_slot = ? where item_id = ?', [$emptyRingSlots[0], $this->item_id]);
|
||||
} elseif ($wearedCount->c == 3) {
|
||||
// Cнимаем предмет из последнего слота 11 и одеваем новый предмет
|
||||
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = 11');
|
||||
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = 11 WHERE item_id = ?', $this->item_id);
|
||||
$this->db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = 11');
|
||||
$this->db->execute('UPDATE inventory SET dressed_slot = 11 WHERE item_id = ?', $this->item_id);
|
||||
} else {
|
||||
/* проверка на переполнение слотов */
|
||||
$error = self::TOO_MANY_ITEMS_IN_SLOTS;
|
||||
@@ -127,7 +127,7 @@ IMG;
|
||||
$error = self::UNKNOWN_ITEM_TYPE;
|
||||
}
|
||||
|
||||
return isset($error) ? $error : true;
|
||||
return $error ?? true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +137,6 @@ IMG;
|
||||
*/
|
||||
public static function destroyItem($itemId): bool
|
||||
{
|
||||
$db = new DBPDO();
|
||||
return $db->execute('delete from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?', [$_SESSION['uid'], $itemId]);
|
||||
return DBPDO::INIT()->execute('delete from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?', [$_SESSION['uid'], $itemId]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user