$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; } } } 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 = 'Хлам'; } $this->item_cost = $this->calculateItemCost(); } /** Рассчёт стоимости предмета в зависимости от его характеристик. * @return int */ private function calculateItemCost(): int { $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); return $result < 1 ? 1 : $result; } protected function wrap(int $number): string { if ($number > 0) { return ": " . $number . ""; } else { return ": " . $number . ""; } } public function getAllInfo(): string { $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, ]; $str = "$this->name (Масса: $this->weight)"; $str .= '
Стоимость: ' . $this->item_cost; $str .= '
Долговечность: ' . $this->durability; $str .= "
$this->typename
"; foreach ($needsLines as $stat => $value) { if ($value > 0) { $str .= "
Требуется $stat" . $this->wrap($value); } } foreach ($addsLines as $stat => $value) { if ($value) { $str .= "
$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; } if (isset($damage)) { $str .= '
Урон: ' . $damage; } return $str; } }