2020-07-06 19:54:50 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Author: lopiu
|
|
|
|
|
* Date: 06.07.2020
|
|
|
|
|
* Time: 22:41
|
|
|
|
|
*/
|
2021-01-28 21:05:34 +00:00
|
|
|
|
|
2020-10-28 20:21:08 +00:00
|
|
|
|
namespace Battles;
|
2021-01-28 21:05:34 +00:00
|
|
|
|
|
2022-01-26 23:15:33 +00:00
|
|
|
|
use Battles\Database\Db;
|
2022-08-09 19:57:43 +00:00
|
|
|
|
use Battles\Models\Inventory;
|
2021-03-11 18:42:36 +00:00
|
|
|
|
use stdClass;
|
2021-01-25 18:01:42 +00:00
|
|
|
|
|
2020-07-06 19:54:50 +00:00
|
|
|
|
class DressedItems
|
|
|
|
|
{
|
2022-12-16 23:20:43 +00:00
|
|
|
|
private int $userId;
|
2022-06-10 23:57:27 +00:00
|
|
|
|
private stdClass $dressedItem;
|
|
|
|
|
private static Db $db;
|
|
|
|
|
private object $dressed;
|
2020-07-06 19:54:50 +00:00
|
|
|
|
|
2020-07-07 09:52:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* DressedItems constructor.
|
2022-12-16 23:20:43 +00:00
|
|
|
|
* @param int $userId ID игрока.
|
2020-07-07 09:52:54 +00:00
|
|
|
|
*/
|
2022-12-16 23:20:43 +00:00
|
|
|
|
public function __construct(int $userId)
|
2020-07-20 12:07:49 +00:00
|
|
|
|
{
|
2022-01-26 23:15:33 +00:00
|
|
|
|
self::$db = Db::getInstance();
|
2022-12-16 23:20:43 +00:00
|
|
|
|
$this->userId = $userId;
|
|
|
|
|
$this->dressed = self::$db->ofetchAll('select * from inventory where dressed_slot > 0 and owner_id = ?', $this->userId);
|
2020-07-20 12:07:49 +00:00
|
|
|
|
}
|
2020-07-06 20:34:34 +00:00
|
|
|
|
|
2021-01-28 21:05:34 +00:00
|
|
|
|
public static function getDressedItemBySlot($itemSlot, $ownerId)
|
2021-01-25 18:01:42 +00:00
|
|
|
|
{
|
2022-01-26 23:15:33 +00:00
|
|
|
|
return self::$db->ofetch('SELECT *, COUNT(1) AS count FROM inventory WHERE owner_id = ? AND dressed_slot = ?', [$ownerId, $itemSlot]);
|
2021-01-25 18:01:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 18:42:36 +00:00
|
|
|
|
public function getItemsInSlots(): stdClass
|
2020-07-22 14:04:15 +00:00
|
|
|
|
{
|
2021-03-11 18:42:36 +00:00
|
|
|
|
$this->dressedItem = new stdClass();
|
2022-06-10 23:57:27 +00:00
|
|
|
|
foreach ($this->dressed as $item) {
|
2021-03-10 21:20:56 +00:00
|
|
|
|
$i = $item->dressed_slot;
|
|
|
|
|
$this->dressedItem->$i = $item;
|
2021-01-28 21:05:34 +00:00
|
|
|
|
}
|
|
|
|
|
return $this->dressedItem;
|
2020-07-22 14:04:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 09:45:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* Снимает с предмета статус одетого на персонажа в определённом слоте персонажа.
|
2022-12-16 23:20:43 +00:00
|
|
|
|
* @param $slotId - номер слота.
|
2020-07-22 09:45:41 +00:00
|
|
|
|
*/
|
2022-12-16 23:20:43 +00:00
|
|
|
|
public function undressItem($slotId)
|
2020-07-21 15:03:46 +00:00
|
|
|
|
{
|
2020-07-22 09:45:41 +00:00
|
|
|
|
self::getItemsInSlots();
|
|
|
|
|
// Проверяем, что используется один из 12 слотов и наличие предмета в слоте.
|
2022-12-16 23:20:43 +00:00
|
|
|
|
if (in_array($slotId, Item::TYPES_ALLOWED_IN_SLOTS) && $this->dressedItem->$slotId) {
|
|
|
|
|
Inventory::undressOne($slotId, $this->userId);
|
2020-07-22 14:04:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-10 23:57:27 +00:00
|
|
|
|
|
2022-12-16 23:20:43 +00:00
|
|
|
|
public static function undressAllItems($userId)
|
2021-03-11 18:58:38 +00:00
|
|
|
|
{
|
2022-12-16 23:20:43 +00:00
|
|
|
|
return self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?', $userId);
|
2021-03-11 18:58:38 +00:00
|
|
|
|
}
|
2022-06-10 23:57:27 +00:00
|
|
|
|
|
|
|
|
|
public function checkRequirements()
|
|
|
|
|
{
|
2022-12-16 23:20:43 +00:00
|
|
|
|
$stats = (new UserStats($this->userId))->getFullStats();
|
|
|
|
|
$q = 'select count(*) from inventory where
|
|
|
|
|
dressed_slot > 0 and
|
2022-06-10 23:57:27 +00:00
|
|
|
|
need_strength > ? and
|
2022-12-16 23:20:43 +00:00
|
|
|
|
need_dexterity > ? and
|
|
|
|
|
need_intuition > ? and
|
|
|
|
|
need_endurance > ? and
|
2022-06-10 23:57:27 +00:00
|
|
|
|
need_intelligence > ? and
|
2022-12-16 23:20:43 +00:00
|
|
|
|
need_wisdom > ? and
|
2022-06-10 23:57:27 +00:00
|
|
|
|
owner_id = ?';
|
|
|
|
|
$args = [
|
|
|
|
|
$stats->strength,
|
|
|
|
|
$stats->dexterity,
|
|
|
|
|
$stats->intuition,
|
|
|
|
|
$stats->endurance,
|
|
|
|
|
$stats->intelligence,
|
|
|
|
|
$stats->wisdom,
|
2022-12-16 23:20:43 +00:00
|
|
|
|
$this->userId
|
2022-06-10 23:57:27 +00:00
|
|
|
|
];
|
|
|
|
|
if (self::$db->fetchColumn($q, $args) > 0) {
|
2022-12-16 23:20:43 +00:00
|
|
|
|
self::undressAllItems($this->userId);
|
2022-06-10 23:57:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-16 23:20:43 +00:00
|
|
|
|
}
|