2019-01-11 16:02:57 +00:00
|
|
|
|
<?php
|
2021-08-22 18:51:00 +00:00
|
|
|
|
|
2020-10-28 20:21:08 +00:00
|
|
|
|
namespace Battles;
|
2021-08-30 16:30:56 +00:00
|
|
|
|
use Battles\Database\DBPDO;
|
|
|
|
|
|
2021-03-10 21:43:48 +00:00
|
|
|
|
class Item
|
2019-01-11 16:02:57 +00:00
|
|
|
|
{
|
2021-08-22 18:51:00 +00:00
|
|
|
|
protected int $item_id;
|
|
|
|
|
protected string $name = '';
|
|
|
|
|
protected int $item_type = self::ITEM_TYPE_TRASH;
|
|
|
|
|
protected int $durability = 0;
|
|
|
|
|
protected int $need_strength = 0;
|
|
|
|
|
protected int $need_dexterity = 0;
|
|
|
|
|
protected int $need_intuition = 0;
|
|
|
|
|
protected int $need_endurance = 0;
|
|
|
|
|
protected int $need_intelligence = 0;
|
|
|
|
|
protected int $need_wisdom = 0;
|
|
|
|
|
protected int $add_strength = 0;
|
|
|
|
|
protected int $add_dexterity = 0;
|
|
|
|
|
protected int $add_intuition = 0;
|
|
|
|
|
protected int $add_endurance = 0;
|
|
|
|
|
protected int $add_intelligence = 0;
|
|
|
|
|
protected int $add_wisdom = 0;
|
|
|
|
|
protected int $add_accuracy = 0;
|
|
|
|
|
protected int $add_evasion = 0;
|
|
|
|
|
protected int $add_criticals = 0;
|
|
|
|
|
protected int $add_min_physical_damage = 0;
|
|
|
|
|
protected int $add_max_physical_damage = 0;
|
|
|
|
|
protected int $weight = 0;
|
|
|
|
|
protected string $image = '';
|
|
|
|
|
protected int $item_cost = 0;
|
|
|
|
|
public const ITEM_TYPES_ALLOWED_IN_SLOTS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
2020-07-22 14:04:15 +00:00
|
|
|
|
public const ITEM_TYPE_HELMET = 1;
|
|
|
|
|
public const ITEM_TYPE_ARMOR = 2;
|
2021-01-25 18:02:23 +00:00
|
|
|
|
public const ITEM_TYPE_LEGS = 3;
|
|
|
|
|
public const ITEM_TYPE_BOOTS = 4;
|
|
|
|
|
public const ITEM_TYPE_GLOVES = 5;
|
|
|
|
|
public const ITEM_TYPE_WEAPON = 6;
|
|
|
|
|
public const ITEM_TYPE_SHIELD = 7;
|
|
|
|
|
public const ITEM_TYPE_BELT = 8;
|
2020-07-22 14:04:15 +00:00
|
|
|
|
public const ITEM_TYPE_RING = 9;
|
2021-01-25 18:02:23 +00:00
|
|
|
|
public const ITEM_TYPE_AMULET = 10;
|
|
|
|
|
public const ITEM_TYPE_CONSUMABLE = 20;
|
2021-01-28 21:05:34 +00:00
|
|
|
|
public const ITEM_TYPE_OTHER = 50;
|
|
|
|
|
public const ITEM_TYPE_TRASH = 100;
|
2021-08-22 18:51:00 +00:00
|
|
|
|
private string $typename;
|
2019-01-14 21:54:20 +00:00
|
|
|
|
|
2019-01-11 16:26:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* Item constructor.
|
2019-02-15 11:38:30 +00:00
|
|
|
|
*
|
2019-01-11 16:26:33 +00:00
|
|
|
|
* @param $row
|
|
|
|
|
*/
|
2019-01-11 16:02:57 +00:00
|
|
|
|
public function __construct($row)
|
|
|
|
|
{
|
2021-03-10 21:20:56 +00:00
|
|
|
|
if (is_array($row)) {
|
|
|
|
|
foreach ($this as $key => $value) {
|
|
|
|
|
if (isset($row[$key])) {
|
|
|
|
|
$this->$key = $row[$key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} elseif (is_object($row)) {
|
|
|
|
|
foreach ($this as $name => $value) {
|
|
|
|
|
if (isset($row->$name)) {
|
|
|
|
|
$this->$name = $row->$name;
|
|
|
|
|
}
|
2019-01-14 21:31:59 +00:00
|
|
|
|
}
|
2019-01-14 13:46:20 +00:00
|
|
|
|
}
|
2019-01-14 14:18:04 +00:00
|
|
|
|
|
2020-07-21 15:03:46 +00:00
|
|
|
|
switch ($this->item_type) {
|
2020-07-22 14:04:15 +00:00
|
|
|
|
case self::ITEM_TYPE_HELMET:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Шлем';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2020-07-22 14:04:15 +00:00
|
|
|
|
case self::ITEM_TYPE_ARMOR:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Броня';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2020-07-22 14:04:15 +00:00
|
|
|
|
case self::ITEM_TYPE_LEGS:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Поножи';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2020-07-22 14:04:15 +00:00
|
|
|
|
case self::ITEM_TYPE_BOOTS:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Сапоги';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2020-07-22 14:04:15 +00:00
|
|
|
|
case self::ITEM_TYPE_GLOVES:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Перчатки';
|
|
|
|
|
break;
|
2020-07-22 14:04:15 +00:00
|
|
|
|
case self::ITEM_TYPE_WEAPON:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Оружие';
|
|
|
|
|
break;
|
2020-07-22 14:04:15 +00:00
|
|
|
|
case self::ITEM_TYPE_SHIELD:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Щит';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2020-07-22 14:04:15 +00:00
|
|
|
|
case self::ITEM_TYPE_BELT:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Пояс';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2020-08-29 12:42:08 +00:00
|
|
|
|
case self::ITEM_TYPE_RING:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Кольцо';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2020-08-29 12:42:08 +00:00
|
|
|
|
case self::ITEM_TYPE_AMULET:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Амулет';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2020-08-29 12:42:08 +00:00
|
|
|
|
case self::ITEM_TYPE_CONSUMABLE:
|
|
|
|
|
$this->typename = 'Расходуемый предмет';
|
|
|
|
|
break;
|
2019-01-12 21:35:48 +00:00
|
|
|
|
default:
|
|
|
|
|
$this->typename = 'Хлам';
|
2019-01-11 22:50:10 +00:00
|
|
|
|
}
|
2021-08-22 18:56:40 +00:00
|
|
|
|
|
2021-08-29 22:34:50 +00:00
|
|
|
|
$this->item_cost = $this->calculateItemCost();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Рассчёт стоимости предмета в зависимости от его характеристик.
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
2021-08-30 16:30:56 +00:00
|
|
|
|
protected function calculateItemCost(): int
|
2021-08-29 22:34:50 +00:00
|
|
|
|
{
|
2021-08-22 18:56:40 +00:00
|
|
|
|
$sum_stats =
|
|
|
|
|
$this->add_strength +
|
|
|
|
|
$this->add_dexterity +
|
|
|
|
|
$this->add_intuition +
|
|
|
|
|
$this->add_endurance +
|
|
|
|
|
$this->add_intelligence +
|
|
|
|
|
$this->add_wisdom;
|
|
|
|
|
$sum_mods =
|
|
|
|
|
$this->add_accuracy +
|
|
|
|
|
$this->add_evasion +
|
|
|
|
|
$this->add_criticals;
|
|
|
|
|
$sum_damage =
|
|
|
|
|
$this->add_min_physical_damage +
|
|
|
|
|
$this->add_max_physical_damage;
|
|
|
|
|
// За каждые N параметров повышаем множитель на 1 чтобы цена пропрорционально росла.
|
|
|
|
|
$stats_cost_modifier = 5 + floor($sum_stats / 10);
|
|
|
|
|
$mods_cost_modifier = 2 + floor($sum_mods / 50);
|
|
|
|
|
$damage_cost_modifier = 1 + floor($sum_damage / 100);
|
|
|
|
|
$result = intval($sum_stats * $stats_cost_modifier + $sum_mods * $mods_cost_modifier + $sum_damage * $damage_cost_modifier);
|
2021-08-29 22:34:50 +00:00
|
|
|
|
return $result < 1 ? 1 : $result;
|
2019-01-11 16:02:57 +00:00
|
|
|
|
}
|
2019-01-11 19:39:37 +00:00
|
|
|
|
|
2021-08-22 18:51:00 +00:00
|
|
|
|
protected function wrap(int $number): string
|
2019-01-11 20:05:09 +00:00
|
|
|
|
{
|
2020-07-21 15:03:46 +00:00
|
|
|
|
if ($number > 0) {
|
|
|
|
|
return ": <b>" . $number . "</b>";
|
|
|
|
|
} else {
|
|
|
|
|
return ": <b style='color: maroon;'>" . $number . "</b>";
|
|
|
|
|
}
|
2019-01-11 20:05:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 22:34:50 +00:00
|
|
|
|
public function getAllInfo(): string
|
2019-01-11 20:05:09 +00:00
|
|
|
|
{
|
2021-01-28 23:58:07 +00:00
|
|
|
|
$needsLines = [
|
2021-08-29 22:34:50 +00:00
|
|
|
|
'сила' => $this->need_strength,
|
|
|
|
|
'ловкость' => $this->need_dexterity,
|
|
|
|
|
'интуиция' => $this->need_intuition,
|
|
|
|
|
'выносливость' => $this->need_endurance,
|
|
|
|
|
'интеллект' => $this->need_intelligence,
|
|
|
|
|
'мудрость' => $this->need_wisdom,
|
2021-01-28 23:58:07 +00:00
|
|
|
|
];
|
|
|
|
|
$addsLines = [
|
2021-08-29 22:34:50 +00:00
|
|
|
|
'Сила' => $this->add_strength,
|
|
|
|
|
'Ловкость' => $this->add_dexterity,
|
|
|
|
|
'Интуиция' => $this->add_intuition,
|
|
|
|
|
'Выносливость' => $this->add_endurance,
|
|
|
|
|
'Интеллект' => $this->add_intelligence,
|
|
|
|
|
'Мудрость' => $this->add_wisdom,
|
|
|
|
|
'Точность' => $this->add_accuracy,
|
|
|
|
|
'Увёртливость' => $this->add_evasion,
|
|
|
|
|
'Шанс крита' => $this->add_criticals,
|
2021-01-28 21:05:34 +00:00
|
|
|
|
];
|
2021-08-29 22:34:50 +00:00
|
|
|
|
$str = "<b>$this->name</b> (Масса: $this->weight)";
|
|
|
|
|
$str .= '<br> Стоимость: ' . $this->item_cost;
|
|
|
|
|
$str .= '<br> Долговечность: ' . $this->durability;
|
|
|
|
|
$str .= "<br><em>$this->typename</em><br>";
|
2021-01-28 23:58:07 +00:00
|
|
|
|
foreach ($needsLines as $stat => $value) {
|
|
|
|
|
if ($value > 0) {
|
2021-08-29 22:34:50 +00:00
|
|
|
|
$str .= "<br>Требуется $stat" . $this->wrap($value);
|
2021-01-28 23:58:07 +00:00
|
|
|
|
}
|
2020-07-21 15:03:46 +00:00
|
|
|
|
}
|
2021-01-28 23:58:07 +00:00
|
|
|
|
foreach ($addsLines as $stat => $value) {
|
|
|
|
|
if ($value) {
|
2021-08-29 22:34:50 +00:00
|
|
|
|
$str .= "<br>$stat" . $this->wrap($value);
|
2021-01-28 23:58:07 +00:00
|
|
|
|
}
|
2020-07-21 15:03:46 +00:00
|
|
|
|
}
|
|
|
|
|
if ($this->add_min_physical_damage && !$this->add_max_physical_damage) {
|
2021-08-29 22:34:50 +00:00
|
|
|
|
$damage = $this->add_min_physical_damage . ' - ' . $this->add_min_physical_damage;
|
2020-07-21 15:03:46 +00:00
|
|
|
|
} elseif (!$this->add_min_physical_damage && $this->add_max_physical_damage) {
|
2021-08-29 22:34:50 +00:00
|
|
|
|
$damage = $this->add_max_physical_damage . ' - ' . $this->add_max_physical_damage;
|
2020-07-21 15:03:46 +00:00
|
|
|
|
} elseif ($this->add_min_physical_damage && $this->add_max_physical_damage) {
|
2021-08-29 22:34:50 +00:00
|
|
|
|
$damage = $this->add_min_physical_damage . ' - ' . $this->add_max_physical_damage;
|
2020-07-21 15:03:46 +00:00
|
|
|
|
}
|
2020-07-22 09:50:14 +00:00
|
|
|
|
if (isset($damage)) {
|
2021-08-29 22:34:50 +00:00
|
|
|
|
$str .= '<br>Урон: ' . $damage;
|
2019-01-14 13:46:20 +00:00
|
|
|
|
}
|
2021-08-29 22:34:50 +00:00
|
|
|
|
return $str;
|
2019-01-14 13:46:20 +00:00
|
|
|
|
}
|
2021-08-30 16:30:56 +00:00
|
|
|
|
|
|
|
|
|
public static function getItemById($item_id): Item
|
|
|
|
|
{
|
|
|
|
|
return new Item(DBPDO::$db->ofetch('select * from items where id = ?', $item_id));
|
|
|
|
|
}
|
2019-01-11 16:02:57 +00:00
|
|
|
|
}
|