battles/classes/DressedItems.php

148 lines
4.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Author: lopiu
* Date: 06.07.2020
* Time: 22:41
*/
class DressedItems
{
private $DB;
private $DBSUM;
private $USERID;
private $dressedItem;
/**
* DressedItems constructor.
*
* @param $user_id - ID игрока.
*/
public function __construct($user_id)
{
$this->USERID = $user_id;
}
private function getDressedItems()
{
try {
$this->DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $this->USERID);
} catch (Exception $e) {
echo '<div class="debug">Не прогрузилась таблица inventory (*) для класса DressedItems.</div>';
}
}
private function getDressedItemById($item_id)
{
return db::c()->query('SELECT * FROM inventory WHERE item_id = ?i AND dressed_slot > 0', $item_id)->fetch_assoc();
}
private function getBonusesFromDressedItems()
{
try {
$query = <<<SQL
SELECT SUM(add_strength) as sum_strength,
SUM(add_dexterity) as sum_dexterity,
SUM(add_intuition) as sum_intuition,
SUM(add_endurance) as sum_endurance,
SUM(add_intelligence) as sum_intelligence,
SUM(add_wisdom) as sum_wisdom,
SUM(add_accuracy) as sum_accuracy,
SUM(add_evasion) as sum_evasion,
SUM(add_criticals) as sum_criticals,
SUM(add_min_physical_damage) as sum_min_phys_damage,
SUM(add_max_physical_damage) as sum_max_phys_damage
FROM inventory WHERE owner_id = ?i AND dressed_slot > 0
SQL;
$this->DBSUM = db::c()->query($query, $this->USERID)->fetch_assoc();
} catch (Exception $e) {
echo '<div class="debug">Не прогрузилась таблица inventory (SUM) для класса DressedItems:' . $e . '</div>';
}
}
public function getItemsInSlots()
{
if (!$this->DB) {
self::getDressedItems();
}
while ($row = $this->DB->fetch_assoc()) {
$this->dressedItem[$row['dressed_slot']] = $row;
}
return $this->dressedItem;
}
private function getBonuses()
{
if (!$this->DBSUM) {
self::getBonusesFromDressedItems();
}
return $this->DBSUM;
}
public function getStrengthBonus()
{
return self::getBonuses()['sum_strength'];
}
public function getDexterityBonus()
{
return self::getBonuses()['sum_dexterity'];
}
public function getIntuitionBonus()
{
return self::getBonuses()['sum_intuition'];
}
public function getEnduranceBonus()
{
return self::getBonuses()['sum_endurance'];
}
public function getIntelliganceBonus()
{
return self::getBonuses()['sum_intelligence'];
}
public function getWisdomBonus()
{
return self::getBonuses()['sum_wisdom'];
}
public function getAccuracyBonus()
{
return self::getBonuses()['sum_accuracy'] ?? 0;
}
public function getEvasionBonus()
{
return self::getBonuses()['sum_evasion'] ?? 0;
}
public function getCriticalsBonus()
{
return self::getBonuses()['sum_criticals'] ?? 0;
}
public function getMinPhysDamage()
{
return self::getBonuses()['sum_min_phys_damage'];
}
public function getMaxPhysDamage()
{
return self::getBonuses()['sum_max_phys_damage'];
}
/**
* Снимает с предмета статус одетого на персонажа в определённом слоте персонажа.
* @param $slot_id - номер слота.
*
* @throws \Krugozor\Database\Mysql\Exception
*/
public function undressItem($slot_id)
{
self::getItemsInSlots();
// Проверяем, что используется один из 12 слотов и наличие предмета в слоте.
if (in_array($slot_id, Item::ITEM_TYPES_ALLOWED_IN_SLOTS) && $this->dressedItem[$slot_id]) {
db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ?i AND owner_id = ?i', $slot_id, $this->USERID);
}
}
public function slotStatus($slot_id)
{
self::getItemsInSlots();
if ($this->dressedItem[$slot_id]) {
}
}
}