This commit is contained in:
2022-06-11 02:57:27 +03:00
parent b8f837b6cf
commit 4b65e0d372
3 changed files with 43 additions and 63 deletions
+34 -6
View File
@@ -12,18 +12,20 @@ use stdClass;
class DressedItems
{
private $USERID;
private $dressedItem;
private static $db;
private int $USERID;
private stdClass $dressedItem;
private static Db $db;
private object $dressed;
/**
* DressedItems constructor.
* @param int $user_id ID игрока.
* @param int $user_id ID игрока.
*/
public function __construct(int $user_id)
{
self::$db = Db::getInstance();
$this->USERID = $user_id;
$this->dressed = self::$db->ofetchAll('select * from inventory where dressed_slot > 0 and owner_id = ?', $this->USERID);
}
public static function getDressedItemBySlot($itemSlot, $ownerId)
@@ -33,9 +35,8 @@ class DressedItems
public function getItemsInSlots(): stdClass
{
$items = self::$db->ofetchALL('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot > 0', $this->USERID);
$this->dressedItem = new stdClass();
foreach ($items as $item) {
foreach ($this->dressed as $item) {
$i = $item->dressed_slot;
$this->dressedItem->$i = $item;
}
@@ -54,8 +55,35 @@ class DressedItems
self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$slot_id, $this->USERID]);
}
}
public static function undressAllItems($user_id)
{
return self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?', $user_id);
}
public function checkRequirements()
{
$stats = (new UserStats($this->USERID))->getFullStats();
$q = 'select count(*) from inventory where
dressed_slot > 0 and
need_strength > ? and
need_dexterity > ? and
need_intuition > ? and
need_endurance > ? and
need_intelligence > ? and
need_wisdom > ? and
owner_id = ?';
$args = [
$stats->strength,
$stats->dexterity,
$stats->intuition,
$stats->endurance,
$stats->intelligence,
$stats->wisdom,
$this->USERID
];
if (self::$db->fetchColumn($q, $args) > 0) {
self::undressAllItems($this->USERID);
}
}
}