battles/classes/Battles/Item.php

169 lines
5.7 KiB
PHP
Raw Normal View History

2019-01-11 16:02:57 +00:00
<?php
namespace Battles;
2019-01-11 19:16:39 +00:00
abstract class Item
2019-01-11 16:02:57 +00:00
{
2020-07-22 14:04:15 +00:00
protected $item_id;
protected $name;
protected $item_type;
protected $durability;
protected $price;
protected $need_strength;
protected $need_dexterity;
protected $need_intuition;
protected $need_endurance;
protected $need_intelligence;
protected $need_wisdom;
protected $add_strength;
protected $add_dexterity;
protected $add_intuition;
protected $add_endurance;
protected $add_intelligence;
protected $add_wisdom;
protected $add_accuracy;
protected $add_evasion;
protected $add_criticals;
protected $add_min_physical_damage;
protected $add_max_physical_damage;
protected $weight;
protected $image;
public const ITEM_TYPES_ALLOWED_IN_SLOTS = [1,2,3,4,5,6,7,8,9,10,11,12];
public const ITEM_TYPE_HELMET = 1;
public const ITEM_TYPE_ARMOR = 2;
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;
public const ITEM_TYPE_AMULET = 10;
public const ITEM_TYPE_CONSUMABLE = 20;
public const ITEM_TYPE_OTHER = 50;
public const ITEM_TYPE_TRASH = 100;
private $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)
{
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
switch ($this->item_type) {
2020-07-22 14:04:15 +00:00
case self::ITEM_TYPE_HELMET:
$this->typename = 'Шлем';
break;
2020-07-22 14:04:15 +00:00
case self::ITEM_TYPE_ARMOR:
$this->typename = 'Броня';
break;
2020-07-22 14:04:15 +00:00
case self::ITEM_TYPE_LEGS:
$this->typename = 'Поножи';
break;
2020-07-22 14:04:15 +00:00
case self::ITEM_TYPE_BOOTS:
$this->typename = 'Сапоги';
break;
2020-07-22 14:04:15 +00:00
case self::ITEM_TYPE_GLOVES:
$this->typename = 'Перчатки';
break;
2020-07-22 14:04:15 +00:00
case self::ITEM_TYPE_WEAPON:
$this->typename = 'Оружие';
break;
2020-07-22 14:04:15 +00:00
case self::ITEM_TYPE_SHIELD:
$this->typename = 'Щит';
break;
2020-07-22 14:04:15 +00:00
case self::ITEM_TYPE_BELT:
$this->typename = 'Пояс';
break;
case self::ITEM_TYPE_RING:
$this->typename = 'Кольцо';
break;
case self::ITEM_TYPE_AMULET:
$this->typename = 'Амулет';
break;
case self::ITEM_TYPE_CONSUMABLE:
$this->typename = 'Расходуемый предмет';
break;
default:
$this->typename = 'Хлам';
2019-01-11 22:50:10 +00:00
}
2019-01-11 16:02:57 +00:00
}
2019-01-11 19:39:37 +00:00
2019-01-12 10:17:20 +00:00
abstract public function printInfo();
2019-01-12 20:02:08 +00:00
public function printImage()
2019-01-11 19:39:37 +00:00
{
2019-01-12 19:51:08 +00:00
echo <<<IMG
2020-07-22 14:04:15 +00:00
<img src="/i/sh/{$this->image}" class="item-wrap-normal" alt="">
2019-01-12 19:51:08 +00:00
IMG;
2019-01-11 19:39:37 +00:00
}
2019-01-11 19:49:00 +00:00
protected function wrap(int $number):string
2019-01-11 20:05:09 +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
}
protected function printAllInfo()
2019-01-11 20:05:09 +00:00
{
$needsLines = [
"сила" => $this->need_strength,
"ловкость" =>$this->need_dexterity,
"интуиция" =>$this->need_intuition,
"выносливость" =>$this->need_endurance,
"интеллект" =>$this->need_intelligence,
"мудрость" =>$this->need_wisdom,
];
$addsLines = [
"Сила" => $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,
];
echo "<b>" . $this->name . "</b> (Масса: " . $this->weight . ")";
echo "<br> Долговечность: " . $this->durability;
echo "<br><em>{$this->typename}</em><br>";
foreach ($needsLines as $stat => $value) {
if ($value > 0) {
echo "<br>Требуется $stat" . $this->wrap($value);
}
}
foreach ($addsLines as $stat => $value) {
if ($value) {
echo "<br>$stat" . $this->wrap($value);
}
}
if ($this->add_min_physical_damage && !$this->add_max_physical_damage) {
$damage = $this->add_min_physical_damage . " - " . $this->add_min_physical_damage;
} elseif (!$this->add_min_physical_damage && $this->add_max_physical_damage) {
$damage = $this->add_max_physical_damage . " - " . $this->add_max_physical_damage;
} elseif ($this->add_min_physical_damage && $this->add_max_physical_damage) {
$damage = $this->add_min_physical_damage . " - " . $this->add_max_physical_damage;
}
2020-07-22 09:50:14 +00:00
if (isset($damage)) {
echo "<br>Урон: " . $damage;
2019-01-14 13:46:20 +00:00
}
}
2019-01-11 16:02:57 +00:00
}