177 lines
6.1 KiB
PHP
177 lines
6.1 KiB
PHP
<?php
|
||
|
||
abstract class Item
|
||
{
|
||
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;
|
||
const ITEM_TYPE_LEGS = 3;
|
||
const ITEM_TYPE_BOOTS = 4;
|
||
const ITEM_TYPE_GLOVES = 5;
|
||
const ITEM_TYPE_WEAPON = 6;
|
||
const ITEM_TYPE_SHIELD = 7;
|
||
const ITEM_TYPE_BELT = 8;
|
||
public const ITEM_TYPE_RING = 9;
|
||
const ITEM_TYPE_AMULET = 10;
|
||
const ITEM_TYPE_CONSUMABLE = 20;
|
||
const ITEM_TYPE_OTHER = 50;
|
||
const ITEM_TYPE_TRASH = 100;
|
||
|
||
/**
|
||
* Item constructor.
|
||
*
|
||
* @param $row
|
||
*/
|
||
public function __construct($row)
|
||
{
|
||
foreach ($this as $key => $value) {
|
||
if (isset($row[$key])) {
|
||
$this->$key = $row[$key];
|
||
}
|
||
}
|
||
|
||
switch ($this->item_type) {
|
||
case self::ITEM_TYPE_HELMET:
|
||
$this->typename = 'Шлем';
|
||
break;
|
||
case self::ITEM_TYPE_ARMOR:
|
||
$this->typename = 'Броня';
|
||
break;
|
||
case self::ITEM_TYPE_LEGS:
|
||
$this->typename = 'Поножи';
|
||
break;
|
||
case self::ITEM_TYPE_BOOTS:
|
||
$this->typename = 'Сапоги';
|
||
break;
|
||
case self::ITEM_TYPE_GLOVES:
|
||
$this->typename = 'Перчатки';
|
||
break;
|
||
case self::ITEM_TYPE_WEAPON:
|
||
$this->typename = 'Оружие';
|
||
break;
|
||
case self::ITEM_TYPE_SHIELD:
|
||
$this->typename = 'Щит';
|
||
break;
|
||
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 = 'Хлам';
|
||
}
|
||
}
|
||
|
||
abstract public function printInfo();
|
||
|
||
public function printImage()
|
||
{
|
||
echo <<<IMG
|
||
<img src="/i/sh/{$this->image}" class="item-wrap-normal" alt="">
|
||
IMG;
|
||
}
|
||
|
||
protected function wrap($number)
|
||
{
|
||
if ($number > 0) {
|
||
return ": <b>" . $number . "</b>";
|
||
} else {
|
||
return ": <b style='color: maroon;'>" . $number . "</b>";
|
||
}
|
||
}
|
||
|
||
protected function printAllInfo()
|
||
{
|
||
echo "<b>" . $this->name . "</b> (Масса: " . $this->weight . ")";
|
||
if ($this->durability) {
|
||
echo "<br> Долговечность: " . $this->durability;
|
||
}
|
||
echo "<br><em>{$this->typename}</em><br>";
|
||
if ($this->need_strength > 0) {
|
||
echo "<br>Требуется сила" . $this->wrap($this->need_strength);
|
||
}
|
||
if ($this->need_dexterity > 0) {
|
||
echo "<br>Требуется ловкость" . $this->wrap($this->need_dexterity);
|
||
}
|
||
if ($this->need_intuition > 0) {
|
||
echo "<br>Требуется интуиция" . $this->wrap($this->need_intuition);
|
||
}
|
||
if ($this->need_endurance > 0) {
|
||
echo "<br>Требуется выносливость" . $this->wrap($this->need_endurance);
|
||
}
|
||
if ($this->need_intelligence > 0) {
|
||
echo "<br>Требуется интеллект" . $this->wrap($this->need_intelligence);
|
||
}
|
||
if ($this->need_wisdom > 0) {
|
||
echo "<br>Требуется мудрость" . $this->wrap($this->need_wisdom);
|
||
}
|
||
if ($this->add_strength) {
|
||
echo "<br>Сила" . $this->wrap($this->add_strength);
|
||
}
|
||
if ($this->add_dexterity) {
|
||
echo "<br>Ловкость" . $this->wrap($this->add_dexterity);
|
||
}
|
||
if ($this->add_intuition) {
|
||
echo "<br>Интуиция" . $this->wrap($this->add_intuition);
|
||
}
|
||
if ($this->add_endurance) {
|
||
echo "<br>Выносливость" . $this->wrap($this->add_endurance);
|
||
}
|
||
if ($this->add_intelligence) {
|
||
echo "<br>Интеллект" . $this->wrap($this->add_intelligence);
|
||
}
|
||
if ($this->add_wisdom) {
|
||
echo "<br>Мудрость" . $this->wrap($this->add_wisdom);
|
||
}
|
||
if ($this->add_accuracy) {
|
||
echo "<br>Точность" . $this->wrap($this->add_accuracy);
|
||
}
|
||
if ($this->add_evasion) {
|
||
echo "<br>Увёртливость" . $this->wrap($this->add_evasion);
|
||
}
|
||
if ($this->add_criticals) {
|
||
echo "<br>Шанс крита" . $this->wrap($this->add_criticals);
|
||
}
|
||
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;
|
||
}
|
||
if (isset($damage)) {
|
||
echo "<br>Урон: " . $damage;
|
||
}
|
||
}
|
||
} |