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;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
|
2022-01-26 23:15:33 +00:00
|
|
|
|
use Battles\Database\Db;
|
2021-08-30 16:30:56 +00:00
|
|
|
|
|
2021-03-10 21:43:48 +00:00
|
|
|
|
class Item
|
2019-01-11 16:02:57 +00:00
|
|
|
|
{
|
2022-12-16 23:20:43 +00:00
|
|
|
|
protected int $id;
|
2021-08-22 18:51:00 +00:00
|
|
|
|
protected string $name = '';
|
2022-12-16 23:20:43 +00:00
|
|
|
|
protected int $type = self::TYPE_TRASH;
|
2021-08-22 18:51:00 +00:00
|
|
|
|
protected int $durability = 0;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
protected int $needStrength = 0;
|
|
|
|
|
protected int $needDexterity = 0;
|
|
|
|
|
protected int $needIntuition = 0;
|
|
|
|
|
protected int $needEndurance = 0;
|
|
|
|
|
protected int $needIntelligence = 0;
|
|
|
|
|
protected int $needWisdom = 0;
|
|
|
|
|
protected int $addStrength = 0;
|
|
|
|
|
protected int $addDexterity = 0;
|
|
|
|
|
protected int $addIntuition = 0;
|
|
|
|
|
protected int $addEndurance = 0;
|
|
|
|
|
protected int $addIntelligence = 0;
|
|
|
|
|
protected int $addWisdom = 0;
|
|
|
|
|
protected int $addAccuracy = 0;
|
|
|
|
|
protected int $addEvasion = 0;
|
|
|
|
|
protected int $addCriticals = 0;
|
|
|
|
|
protected int $addMinPhysicalDamage = 0;
|
|
|
|
|
protected int $addMaxPhysicalDamage = 0;
|
2021-08-22 18:51:00 +00:00
|
|
|
|
protected int $weight = 0;
|
|
|
|
|
protected string $image = '';
|
2022-12-16 23:20:43 +00:00
|
|
|
|
protected int $cost = 0;
|
|
|
|
|
public const TYPES_ALLOWED_IN_SLOTS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
|
|
|
public const TYPE_HELMET = 1;
|
|
|
|
|
public const TYPE_ARMOR = 2;
|
|
|
|
|
public const TYPE_LEGS = 3;
|
|
|
|
|
public const TYPE_BOOTS = 4;
|
|
|
|
|
public const TYPE_GLOVES = 5;
|
|
|
|
|
public const TYPE_WEAPON = 6;
|
|
|
|
|
public const TYPE_SHIELD = 7;
|
|
|
|
|
public const TYPE_BELT = 8;
|
|
|
|
|
public const TYPE_RING = 9;
|
|
|
|
|
public const TYPE_AMULET = 10;
|
|
|
|
|
public const TYPE_CONSUMABLE = 20;
|
|
|
|
|
public const TYPE_OTHER = 50;
|
|
|
|
|
public const 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
|
|
|
|
|
2022-12-16 23:20:43 +00:00
|
|
|
|
switch ($this->type) {
|
|
|
|
|
case self::TYPE_HELMET:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Шлем';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
case self::TYPE_ARMOR:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Броня';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
case self::TYPE_LEGS:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Поножи';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
case self::TYPE_BOOTS:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Сапоги';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
case self::TYPE_GLOVES:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Перчатки';
|
|
|
|
|
break;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
case self::TYPE_WEAPON:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Оружие';
|
|
|
|
|
break;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
case self::TYPE_SHIELD:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Щит';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
case self::TYPE_BELT:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Пояс';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
case self::TYPE_RING:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Кольцо';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
case self::TYPE_AMULET:
|
2020-07-21 15:03:46 +00:00
|
|
|
|
$this->typename = 'Амулет';
|
2019-01-12 21:35:48 +00:00
|
|
|
|
break;
|
2022-12-16 23:20:43 +00:00
|
|
|
|
case self::TYPE_CONSUMABLE:
|
2020-08-29 12:42:08 +00:00
|
|
|
|
$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
|
|
|
|
|
2022-12-16 23:20:43 +00:00
|
|
|
|
$this->cost = $this->calculateItemCost();
|
2021-08-29 22:34:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Рассчёт стоимости предмета в зависимости от его характеристик.
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
2021-08-30 16:30:56 +00:00
|
|
|
|
protected function calculateItemCost(): int
|
2021-08-29 22:34:50 +00:00
|
|
|
|
{
|
2022-12-16 23:20:43 +00:00
|
|
|
|
$sumStats =
|
|
|
|
|
$this->addStrength +
|
|
|
|
|
$this->addDexterity +
|
|
|
|
|
$this->addIntuition +
|
|
|
|
|
$this->addEndurance +
|
|
|
|
|
$this->addIntelligence +
|
|
|
|
|
$this->addWisdom;
|
|
|
|
|
$sumMods =
|
|
|
|
|
$this->addAccuracy +
|
|
|
|
|
$this->addEvasion +
|
|
|
|
|
$this->addCriticals;
|
|
|
|
|
$sumDamage =
|
|
|
|
|
$this->addMinPhysicalDamage +
|
|
|
|
|
$this->addMaxPhysicalDamage;
|
2021-08-22 18:56:40 +00:00
|
|
|
|
// За каждые N параметров повышаем множитель на 1 чтобы цена пропрорционально росла.
|
2022-12-16 23:20:43 +00:00
|
|
|
|
$statsCostModifier = 5 + floor($sumStats / 10);
|
|
|
|
|
$modsCostModifier = 2 + floor($sumMods / 50);
|
|
|
|
|
$damageCostModifier = 1 + floor($sumDamage / 100);
|
|
|
|
|
$result = intval($sumStats * $statsCostModifier + $sumMods * $modsCostModifier + $sumDamage * $damageCostModifier);
|
|
|
|
|
return max($result, 1);
|
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 = [
|
2022-12-16 23:20:43 +00:00
|
|
|
|
'сила' => $this->needStrength,
|
|
|
|
|
'ловкость' => $this->needDexterity,
|
|
|
|
|
'интуиция' => $this->needIntuition,
|
|
|
|
|
'выносливость' => $this->needEndurance,
|
|
|
|
|
'интеллект' => $this->needIntelligence,
|
|
|
|
|
'мудрость' => $this->needWisdom,
|
2021-01-28 23:58:07 +00:00
|
|
|
|
];
|
|
|
|
|
$addsLines = [
|
2022-12-16 23:20:43 +00:00
|
|
|
|
'Сила' => $this->addStrength,
|
|
|
|
|
'Ловкость' => $this->addDexterity,
|
|
|
|
|
'Интуиция' => $this->addIntuition,
|
|
|
|
|
'Выносливость' => $this->addEndurance,
|
|
|
|
|
'Интеллект' => $this->addIntelligence,
|
|
|
|
|
'Мудрость' => $this->addWisdom,
|
|
|
|
|
'Точность' => $this->addAccuracy,
|
|
|
|
|
'Увёртливость' => $this->addEvasion,
|
|
|
|
|
'Шанс крита' => $this->addCriticals,
|
2021-01-28 21:05:34 +00:00
|
|
|
|
];
|
2021-08-29 22:34:50 +00:00
|
|
|
|
$str = "<b>$this->name</b> (Масса: $this->weight)";
|
2022-12-16 23:20:43 +00:00
|
|
|
|
$str .= '<br> Стоимость: ' . $this->cost;
|
2021-08-29 22:34:50 +00:00
|
|
|
|
$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
|
|
|
|
}
|
2022-12-16 23:20:43 +00:00
|
|
|
|
if ($this->addMinPhysicalDamage && !$this->addMaxPhysicalDamage) {
|
|
|
|
|
$damage = $this->addMinPhysicalDamage . ' - ' . $this->addMinPhysicalDamage;
|
|
|
|
|
} elseif (!$this->addMinPhysicalDamage && $this->addMaxPhysicalDamage) {
|
|
|
|
|
$damage = $this->addMaxPhysicalDamage . ' - ' . $this->addMaxPhysicalDamage;
|
|
|
|
|
} elseif ($this->addMinPhysicalDamage && $this->addMaxPhysicalDamage) {
|
|
|
|
|
$damage = $this->addMinPhysicalDamage . ' - ' . $this->addMaxPhysicalDamage;
|
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
|
|
|
|
|
2022-12-16 23:20:43 +00:00
|
|
|
|
public static function getItemById($itemId): Item
|
2021-08-30 16:30:56 +00:00
|
|
|
|
{
|
2022-12-16 23:20:43 +00:00
|
|
|
|
return new Item(Db::getInstance()->ofetch('select * from items where id = ?', $itemId));
|
2021-08-30 16:30:56 +00:00
|
|
|
|
}
|
2022-12-16 23:20:43 +00:00
|
|
|
|
}
|