battles/classes/Battles/DressedItems.php

61 lines
1.9 KiB
PHP
Raw Normal View History

2020-07-06 19:54:50 +00:00
<?php
/**
* Author: lopiu
* Date: 06.07.2020
* Time: 22:41
*/
namespace Battles;
use Battles\Database\Db;
use stdClass;
2020-07-06 19:54:50 +00:00
class DressedItems
{
private $USERID;
2020-07-06 19:54:50 +00:00
private $dressedItem;
private static $db;
2020-07-06 19:54:50 +00:00
/**
* DressedItems constructor.
* @param int $user_id ID игрока.
*/
public function __construct(int $user_id)
{
self::$db = Db::getInstance();
$this->USERID = $user_id;
}
2020-07-06 20:34:34 +00:00
public static function getDressedItemBySlot($itemSlot, $ownerId)
{
return self::$db->ofetch('SELECT *, COUNT(1) AS count FROM inventory WHERE owner_id = ? AND dressed_slot = ?', [$ownerId, $itemSlot]);
}
public function getItemsInSlots(): stdClass
2020-07-22 14:04:15 +00:00
{
$items = self::$db->ofetchALL('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot > 0', $this->USERID);
$this->dressedItem = new stdClass();
foreach ($items as $item) {
$i = $item->dressed_slot;
$this->dressedItem->$i = $item;
}
return $this->dressedItem;
2020-07-22 14:04:15 +00:00
}
/**
* Снимает с предмета статус одетого на персонажа в определённом слоте персонажа.
* @param $slot_id - номер слота.
*/
public function undressItem($slot_id)
{
self::getItemsInSlots();
// Проверяем, что используется один из 12 слотов и наличие предмета в слоте.
if (in_array($slot_id, Item::ITEM_TYPES_ALLOWED_IN_SLOTS) && $this->dressedItem->$slot_id) {
self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$slot_id, $this->USERID]);
2020-07-22 14:04:15 +00:00
}
}
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);
}
2020-07-06 19:54:50 +00:00
}