diff --git a/classes/Battles/Bank.php b/classes/Battles/Bank.php index c01504f..8c672f8 100644 --- a/classes/Battles/Bank.php +++ b/classes/Battles/Bank.php @@ -7,17 +7,16 @@ namespace Battles; -use Config; use Exceptions\GameException; use Battles\Database\DBPDO; use Throwable; class Bank { - public $user_id; - private $money; + public int $user_id = 0; + private int $money = 0; private $user; - private static $db; + private static DBPDO $db; const ERROR_NO_MONEY_IN_WALLET = "Ошибка! Нет денег в кошельке!"; const ERROR_NO_BANK_ACCOUNT = "Ошибка! Счёта не существует!"; @@ -174,11 +173,11 @@ class Bank self::setBankMoney($this->money, $this->user_id); $this->bankLogs(0, $this->money, "withdrawMoney"); // Отдаём сумму в кошелёк получателя - $this->user->money += $amount; - self::setWalletMoney($this->user->money, $this->user_id); + $this->user['money'] += $amount; + self::setWalletMoney($this->user['money'], $this->user_id); // Возвращаем изменившиеся значения return [ - 'walletMoney' => $this->user->money, + 'walletMoney' => $this->user['money'], 'bankMoney' => $this->money ]; } @@ -223,7 +222,7 @@ class Bank } - public function getMoney() + public function getMoney(): int { return $this->money; } diff --git a/classes/Battles/GameLogs.php b/classes/Battles/GameLogs.php index 68d61cd..329b52c 100644 --- a/classes/Battles/GameLogs.php +++ b/classes/Battles/GameLogs.php @@ -3,7 +3,6 @@ namespace Battles; -use Config; use SQLite3; use SQLite3Result; diff --git a/classes/Battles/InventoryItem.php b/classes/Battles/InventoryItem.php index 0cd1c14..e62f1a0 100644 --- a/classes/Battles/InventoryItem.php +++ b/classes/Battles/InventoryItem.php @@ -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 "
Это подарок от {$this->present}. Вы не можете передать его кому-либо ещё.
"; + echo "Это подарок от $this->present. Вы не можете передать его кому-либо ещё.
"; } } @@ -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]); } } \ No newline at end of file diff --git a/classes/Battles/Item.php b/classes/Battles/Item.php index c2105e4..d59a859 100644 --- a/classes/Battles/Item.php +++ b/classes/Battles/Item.php @@ -6,7 +6,6 @@ class Item protected $name; protected $item_type; protected $durability; - protected $price; protected $need_strength; protected $need_dexterity; protected $need_intuition; @@ -102,8 +101,6 @@ class Item } } - - protected function wrap(int $number):string { if ($number > 0) { @@ -134,10 +131,9 @@ class Item "Увёртливость" => $this->add_evasion, "Шанс крита" => $this->add_criticals, ]; - echo "" . $this->name . " (Масса: " . $this->weight . ")"; + echo "$this->name (Масса: $this->weight)"; echo "%s