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
|
|
|
|
|
|
|
|
|
use Battles\Database\DBPDO;
|
2021-01-25 18:01:42 +00:00
|
|
|
|
|
2020-07-06 19:54:50 +00:00
|
|
|
|
class DressedItems
|
|
|
|
|
{
|
2020-07-21 15:03:46 +00:00
|
|
|
|
private $USERID;
|
2020-07-06 19:54:50 +00:00
|
|
|
|
private $dressedItem;
|
2021-01-28 21:05:34 +00:00
|
|
|
|
private static $db;
|
2020-07-06 19:54:50 +00:00
|
|
|
|
|
2020-07-07 09:52:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* DressedItems constructor.
|
2021-01-28 21:05:34 +00:00
|
|
|
|
* @param int $user_id ID игрока.
|
2020-07-07 09:52:54 +00:00
|
|
|
|
*/
|
2021-01-28 21:05:34 +00:00
|
|
|
|
public function __construct(int $user_id)
|
2020-07-20 12:07:49 +00:00
|
|
|
|
{
|
2021-01-28 21:05:34 +00:00
|
|
|
|
self::$db = DBPDO::INIT();
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->USERID = $user_id;
|
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
|
|
|
|
{
|
2021-03-10 21:20:56 +00:00
|
|
|
|
return self::$db->fetch('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-10 21:20:56 +00:00
|
|
|
|
public function getItemsInSlots(): \stdClass
|
2020-07-22 14:04:15 +00:00
|
|
|
|
{
|
2021-01-31 23:48:53 +00:00
|
|
|
|
$items = self::$db->ofetchALL('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot > 0', $this->USERID);
|
2021-03-10 21:20:56 +00:00
|
|
|
|
$this->dressedItem = new \stdClass();
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
$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
|
|
|
|
}
|
|
|
|
|
|
2021-01-28 21:05:34 +00:00
|
|
|
|
private function getBonuses(): array
|
2020-07-07 09:50:45 +00:00
|
|
|
|
{
|
2021-01-28 21:05:34 +00:00
|
|
|
|
$query = <<<SQL
|
2020-07-07 13:01:46 +00:00
|
|
|
|
SELECT SUM(add_strength) as sum_strength,
|
2020-07-20 13:51:23 +00:00
|
|
|
|
SUM(add_dexterity) as sum_dexterity,
|
2020-07-07 13:01:46 +00:00
|
|
|
|
SUM(add_intuition) as sum_intuition,
|
|
|
|
|
SUM(add_endurance) as sum_endurance,
|
|
|
|
|
SUM(add_intelligence) as sum_intelligence,
|
2020-07-20 10:22:29 +00:00
|
|
|
|
SUM(add_wisdom) as sum_wisdom,
|
|
|
|
|
SUM(add_accuracy) as sum_accuracy,
|
2020-07-20 13:27:32 +00:00
|
|
|
|
SUM(add_evasion) as sum_evasion,
|
|
|
|
|
SUM(add_criticals) as sum_criticals,
|
2020-07-20 13:44:31 +00:00
|
|
|
|
SUM(add_min_physical_damage) as sum_min_phys_damage,
|
2020-07-22 14:04:15 +00:00
|
|
|
|
SUM(add_max_physical_damage) as sum_max_phys_damage
|
2021-01-28 21:05:34 +00:00
|
|
|
|
FROM inventory WHERE owner_id = ? AND dressed_slot > 0
|
2020-07-07 13:01:46 +00:00
|
|
|
|
SQL;
|
2021-01-28 21:05:34 +00:00
|
|
|
|
return self::$db->fetch($query, $this->USERID);
|
2020-07-06 19:54:50 +00:00
|
|
|
|
}
|
2020-07-07 09:50:45 +00:00
|
|
|
|
|
2021-01-28 23:58:07 +00:00
|
|
|
|
public function getAccuracyBonus(): ?int
|
2020-07-20 12:07:49 +00:00
|
|
|
|
{
|
2020-08-29 12:15:31 +00:00
|
|
|
|
return self::getBonuses()['sum_accuracy'] ?? 0;
|
2020-07-20 12:07:49 +00:00
|
|
|
|
}
|
2021-01-28 21:05:34 +00:00
|
|
|
|
|
2021-01-28 23:58:07 +00:00
|
|
|
|
public function getEvasionBonus(): ?int
|
2020-07-20 12:07:49 +00:00
|
|
|
|
{
|
2020-08-29 12:15:31 +00:00
|
|
|
|
return self::getBonuses()['sum_evasion'] ?? 0;
|
2020-07-20 12:07:49 +00:00
|
|
|
|
}
|
2021-01-28 21:05:34 +00:00
|
|
|
|
|
2021-01-28 23:58:07 +00:00
|
|
|
|
public function getCriticalsBonus(): ?int
|
2020-07-20 12:07:49 +00:00
|
|
|
|
{
|
2020-08-29 12:15:31 +00:00
|
|
|
|
return self::getBonuses()['sum_criticals'] ?? 0;
|
|
|
|
|
}
|
2021-01-28 21:05:34 +00:00
|
|
|
|
|
2021-01-28 23:58:07 +00:00
|
|
|
|
public function getMinPhysDamage(): ?int
|
2020-08-29 12:15:31 +00:00
|
|
|
|
{
|
|
|
|
|
return self::getBonuses()['sum_min_phys_damage'];
|
|
|
|
|
}
|
2021-01-28 21:05:34 +00:00
|
|
|
|
|
2021-01-28 23:58:07 +00:00
|
|
|
|
public function getMaxPhysDamage(): ?int
|
2020-08-29 12:15:31 +00:00
|
|
|
|
{
|
|
|
|
|
return self::getBonuses()['sum_max_phys_damage'];
|
2020-07-20 12:07:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 09:45:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* Снимает с предмета статус одетого на персонажа в определённом слоте персонажа.
|
|
|
|
|
* @param $slot_id - номер слота.
|
|
|
|
|
*/
|
2020-07-21 15:03:46 +00:00
|
|
|
|
public function undressItem($slot_id)
|
|
|
|
|
{
|
2020-07-22 09:45:41 +00:00
|
|
|
|
self::getItemsInSlots();
|
|
|
|
|
// Проверяем, что используется один из 12 слотов и наличие предмета в слоте.
|
2021-03-10 21:20:56 +00:00
|
|
|
|
if (in_array($slot_id, Item::ITEM_TYPES_ALLOWED_IN_SLOTS) && $this->dressedItem->$slot_id) {
|
2021-01-28 21:05:34 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-06 19:54:50 +00:00
|
|
|
|
}
|