2020-07-06 22:54:50 +03:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Author: lopiu
|
|
|
|
|
* Date: 06.07.2020
|
|
|
|
|
* Time: 22:41
|
|
|
|
|
*/
|
2021-01-28 23:05:34 +02:00
|
|
|
|
|
2020-10-28 22:21:08 +02:00
|
|
|
|
namespace Battles;
|
2021-01-28 23:05:34 +02:00
|
|
|
|
|
2022-01-27 01:15:33 +02:00
|
|
|
|
use Battles\Database\Db;
|
2022-08-09 22:57:43 +03:00
|
|
|
|
use Battles\Models\Inventory;
|
2021-03-11 20:42:36 +02:00
|
|
|
|
use stdClass;
|
2021-01-25 20:01:42 +02:00
|
|
|
|
|
2020-07-06 22:54:50 +03:00
|
|
|
|
class DressedItems
|
|
|
|
|
{
|
2022-06-11 02:57:27 +03:00
|
|
|
|
private int $USERID;
|
|
|
|
|
private stdClass $dressedItem;
|
|
|
|
|
private static Db $db;
|
|
|
|
|
private object $dressed;
|
2020-07-06 22:54:50 +03:00
|
|
|
|
|
2020-07-07 12:52:54 +03:00
|
|
|
|
/**
|
|
|
|
|
* DressedItems constructor.
|
2022-06-11 02:57:27 +03:00
|
|
|
|
* @param int $user_id ID игрока.
|
2020-07-07 12:52:54 +03:00
|
|
|
|
*/
|
2021-01-28 23:05:34 +02:00
|
|
|
|
public function __construct(int $user_id)
|
2020-07-20 15:07:49 +03:00
|
|
|
|
{
|
2022-01-27 01:15:33 +02:00
|
|
|
|
self::$db = Db::getInstance();
|
2020-07-21 18:03:46 +03:00
|
|
|
|
$this->USERID = $user_id;
|
2022-06-11 02:57:27 +03:00
|
|
|
|
$this->dressed = self::$db->ofetchAll('select * from inventory where dressed_slot > 0 and owner_id = ?', $this->USERID);
|
2020-07-20 15:07:49 +03:00
|
|
|
|
}
|
2020-07-06 23:34:34 +03:00
|
|
|
|
|
2021-01-28 23:05:34 +02:00
|
|
|
|
public static function getDressedItemBySlot($itemSlot, $ownerId)
|
2021-01-25 20:01:42 +02:00
|
|
|
|
{
|
2022-01-27 01:15:33 +02:00
|
|
|
|
return self::$db->ofetch('SELECT *, COUNT(1) AS count FROM inventory WHERE owner_id = ? AND dressed_slot = ?', [$ownerId, $itemSlot]);
|
2021-01-25 20:01:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 20:42:36 +02:00
|
|
|
|
public function getItemsInSlots(): stdClass
|
2020-07-22 17:04:15 +03:00
|
|
|
|
{
|
2021-03-11 20:42:36 +02:00
|
|
|
|
$this->dressedItem = new stdClass();
|
2022-06-11 02:57:27 +03:00
|
|
|
|
foreach ($this->dressed as $item) {
|
2021-03-10 23:20:56 +02:00
|
|
|
|
$i = $item->dressed_slot;
|
|
|
|
|
$this->dressedItem->$i = $item;
|
2021-01-28 23:05:34 +02:00
|
|
|
|
}
|
|
|
|
|
return $this->dressedItem;
|
2020-07-22 17:04:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 12:45:41 +03:00
|
|
|
|
/**
|
|
|
|
|
* Снимает с предмета статус одетого на персонажа в определённом слоте персонажа.
|
|
|
|
|
* @param $slot_id - номер слота.
|
|
|
|
|
*/
|
2020-07-21 18:03:46 +03:00
|
|
|
|
public function undressItem($slot_id)
|
|
|
|
|
{
|
2020-07-22 12:45:41 +03:00
|
|
|
|
self::getItemsInSlots();
|
|
|
|
|
// Проверяем, что используется один из 12 слотов и наличие предмета в слоте.
|
2021-03-10 23:20:56 +02:00
|
|
|
|
if (in_array($slot_id, Item::ITEM_TYPES_ALLOWED_IN_SLOTS) && $this->dressedItem->$slot_id) {
|
2022-08-09 22:57:43 +03:00
|
|
|
|
Inventory::undressOne($slot_id, $this->USERID);
|
2020-07-22 17:04:15 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-11 02:57:27 +03:00
|
|
|
|
|
2021-03-11 20:58:38 +02: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);
|
|
|
|
|
}
|
2022-06-11 02:57:27 +03:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-06 22:54:50 +03:00
|
|
|
|
}
|