Из shop уехали все запросы в класс. Теперь он только отображает.

This commit is contained in:
lopar
2021-08-30 01:34:50 +03:00
parent 4cf370327f
commit d2c8c8d7d5
7 changed files with 115 additions and 250 deletions
+36 -28
View File
@@ -102,6 +102,14 @@ class Item
$this->typename = 'Хлам';
}
$this->item_cost = $this->calculateItemCost();
}
/** Рассчёт стоимости предмета в зависимости от его характеристик.
* @return int
*/
private function calculateItemCost(): int
{
$sum_stats =
$this->add_strength +
$this->add_dexterity +
@@ -121,8 +129,7 @@ class Item
$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);
$this->item_cost = $result < 1 ? 1 : $result;
return $result < 1 ? 1 : $result;
}
protected function wrap(int $number): string
@@ -134,50 +141,51 @@ class Item
}
}
protected function printAllInfo()
public function getAllInfo(): string
{
$needsLines = [
"сила" => $this->need_strength,
"ловкость" => $this->need_dexterity,
"интуиция" => $this->need_intuition,
"выносливость" => $this->need_endurance,
"интеллект" => $this->need_intelligence,
"мудрость" => $this->need_wisdom,
'сила' => $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,
'Сила' => $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->item_cost;
echo "<br> Долговечность: " . $this->durability;
echo "<br><em>$this->typename</em><br>";
$str = "<b>$this->name</b> (Масса: $this->weight)";
$str .= '<br> Стоимость: ' . $this->item_cost;
$str .= '<br> Долговечность: ' . $this->durability;
$str .= "<br><em>$this->typename</em><br>";
foreach ($needsLines as $stat => $value) {
if ($value > 0) {
echo "<br>Требуется $stat" . $this->wrap($value);
$str .= "<br>Требуется $stat" . $this->wrap($value);
}
}
foreach ($addsLines as $stat => $value) {
if ($value) {
echo "<br>$stat" . $this->wrap($value);
$str .= "<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;
$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;
$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;
$damage = $this->add_min_physical_damage . ' - ' . $this->add_max_physical_damage;
}
if (isset($damage)) {
echo "<br>Урон: " . $damage;
$str .= '<br>Урон: ' . $damage;
}
return $str;
}
}