Code smell.

This commit is contained in:
Ivor Barhansky
2022-12-17 01:20:43 +02:00
parent b1f578f4b0
commit 0398425205
45 changed files with 875 additions and 851 deletions
+109 -88
View File
@@ -7,8 +7,27 @@ use Exceptions\GameException;
class UserInfo extends UserStats
{
private const STRENGTH = 'Сила';
private const DEXTERITY = 'Ловкость';
private const INTUITION = 'Интуиция';
private const ENDURANCE = 'Выносливость';
private const INTELLIGENCE = 'Интеллект';
private const WISDOM = 'Мудрость';
private const PERCENT_20 = (20 / 100);
private const PERCENT_80 = (80 / 100);
private const LEVEL = 'Уровень';
private const HEALTH = 'Здоровье';
private const MANA = 'Пыль';
private const EXPERIENCE = 'Опыт';
private const FREE_STAT_POINTS = 'Очки характеристик';
private const MONEY = 'Деньги';
private const MONEY_IN_BANK = self::MONEY . ' в банке';
private const EVASION = 'Уворот';
private const ACCURACY = 'Точность';
private const CRITICALS = 'Шанс крита';
private const DAMAGE = 'Урон';
private const LOCATION = 'Локация';
use Rooms;
/**
@@ -16,12 +35,12 @@ class UserInfo extends UserStats
*
* @param int $isBattle установить 1, если куклу нужно отобразить в поединке (показывает параметры при наведении
* на образ).
* @param int $isMain установить 1, если куклу надо показать на странице игрока (по клику на предмет снимает
* @param int $isMain установить 1, если куклу надо показать на странице игрока (по клику на предмет снимает
* его).
*
* @throws GameException
*/
private function UserInfoDoll(int $isBattle = 0, int $isMain = 0): string
private function userInfoDoll(int $isBattle = 0, int $isMain = 0): string
{
$di = new DressedItems($this->id);
$stats = new UserStats($this->id);
@@ -31,11 +50,21 @@ class UserInfo extends UserStats
$str .= sprintf('<div class="slot-%s">', $i);
if (!empty($dressedItems->$i)) {
if (!$isBattle && $isMain) {
$str .= sprintf('<a href="?edit=%s&drop=%s"><img src="/i/sh/%s" class="item-wrap-normal" alt="%s" title="%s"></a>',
mt_rand(), $i, $dressedItems->$i->image, $dressedItems->$i->name, $dressedItems->$i->name);
$str .= sprintf(
'<a href="?edit=%s&drop=%s"><img src="/i/sh/%s" class="item-wrap-normal" alt="%s" title="%s"></a>',
mt_rand(),
$i,
$dressedItems->$i->image,
$dressedItems->$i->name,
$dressedItems->$i->name
);
} else {
$str .= sprintf('<img src="/i/sh/%s" class="item-wrap-normal tip" alt="%s"><span class="tiptext"><strong>%s</strong></span>',
$dressedItems->$i->image, $dressedItems->$i->name, $dressedItems->$i->name);
$str .= sprintf(
'<img src="/i/sh/%s" class="item-wrap-normal tip" alt="%s"><span class="tiptext"><strong>%s</strong></span>',
$dressedItems->$i->image,
$dressedItems->$i->name,
$dressedItems->$i->name
);
}
} else {
$str .= sprintf('<img src="/i/sh/noitem.png" class="item-wrap-normal" title="Пустой слот [%s]" alt="Пустой слот [%s]">', $i, $i);
@@ -43,47 +72,42 @@ class UserInfo extends UserStats
$str .= sprintf('</div><!-- slot-%s -->', $i);
}
$str .= '<div class="slot-image">';
$str .= '<img src="/i/shadow/' . $this->shadow . '" alt="' . $this->login;
if ($isBattle) {
$str .= sprintf('<img src="/i/shadow/%s" alt="%s" class="tip"><span class="tiptext"><b>%s</b>Уровень: %s<br>Сила: %s<br>Ловкость: %s<br>Интуиция: %s<br>Выносливость: %s<br>Интеллект: %s<br>Мудрость: %s</span>',
$this->shadow, $stats->getLogin(), $stats->getLogin(), $stats->getLevel(), $stats->getStat('strength'), $stats->getStat('dexterity'), $stats->getStat('intuition'), $stats->getStat('endurance'), $stats->getStat('intelligence'), $stats->getStat('wisdom'));
unset($sh);
$str .= '" class = "tip">';
$str .= '<span class="tiptext"><b>' . $stats->getLogin() . '</b>';
$str .= self::LEVEL . ': ' . $stats->getLevel();
$str .= '<br>' . self::STRENGTH . ': ' . $stats->getStat('strength');
$str .= '<br>' . self::DEXTERITY . ': ' . $stats->getStat('dexterity');
$str .= '<br>' . self::INTUITION . ': ' . $stats->getStat('intuition');
$str .= '<br>' . self::ENDURANCE . ': ' . $stats->getStat('endurance');
$str .= '<br>' . self::INTELLIGENCE . ': ' . $stats->getStat('intelligence');
$str .= '<br>' . self::WISDOM . ': ' . $stats->getStat('wisdom');
$str .= '</span>';
} else {
$str .= '<img src="/i/shadow/' . $this->shadow . '" alt="' . $this->login . '">';
$str .= '">';
}
$str .= '</div><!-- slot-image -->';
return $str;
}
public function test(): array
{
return [
'Сила' => $this->strength,
'Ловкость' => $this->dexterity,
'Интуиция' => $this->intuition,
'Выносливость' => $this->endurance,
'Интеллект' => $this->intelligence,
'Мудрость' => $this->wisdom,
];
}
/** Вызов из inf.php */
private function ttz(): string
{
$stat = $this->getFullStats();
$arr = [
'Уровень' => $this->level,
'Сила' => $this->strength,
'Ловкость' => $this->dexterity,
'Интуиция' => $this->intuition,
'Выносливость' => $this->endurance,
'Интеллект' => $this->intelligence,
'Мудрость' => $this->wisdom,
'Уворот' => $stat->evasion,
'Точность' => $stat->accuracy,
'Шанс крита' => $stat->criticals,
'Урон' => $stat->min_physical_damage . ' - ' . $stat->max_physical_damage,
'Локация' => Rooms::$roomNames[$this->room],
self::LEVEL => $this->level,
self::STRENGTH => $this->strength,
self::DEXTERITY => $this->dexterity,
self::INTUITION => $this->intuition,
self::ENDURANCE => $this->endurance,
self::INTELLIGENCE => $this->intelligence,
self::WISDOM => $this->wisdom,
self::EVASION => $stat->evasion,
self::ACCURACY => $stat->accuracy,
self::CRITICALS => $stat->criticals,
self::DAMAGE => $stat->min_physical_damage . ' - ' . $stat->max_physical_damage,
self::LOCATION => Rooms::$roomNames[$this->room],
];
$str = null;
@@ -102,13 +126,13 @@ class UserInfo extends UserStats
);
}
private function showProgressBar(int $value, int $max_value)
private function showProgressBar(int $value, int $maxValue)
{
$values = [
'%20%' => (int)round(self::PERCENT_20 * $max_value),
'%80%' => (int)round(self::PERCENT_80 * $max_value),
'%20%' => (int)round(self::PERCENT_20 * $maxValue),
'%80%' => (int)round(self::PERCENT_80 * $maxValue),
'%value' => $value,
'%max' => $max_value
'%max' => $maxValue
];
$string = '<meter max="%max" low="%20%" high="%80%" optimum="%max" value="%value">%value / %max</meter>';
return str_replace(array_keys($values), array_values($values), $string);
@@ -117,60 +141,57 @@ class UserInfo extends UserStats
/** Для вызова из main.php
* @throws GameException
*/
private function UserInfoStats(): string
private function userInfoStats(): string
{
$captions = 'Уровень:<br>Здоровье:<br>Пыль:
<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:
<br>Опыт:<br>Очки характеристик:<br>Деньги:<br>Деньги в банке:
';
$variables =
$this->level . '<br>' .
$this->showProgressBar($this->health, $this->maxHealth) . '<br>' .
$this->showProgressBar($this->mana, $this->maxMana) . '<br>' .
parent::getStat('strength', 1) . '<br>' .
parent::getStat('dexterity', 1) . '<br>' .
parent::getStat('intuition', 1) . '<br>' .
parent::getStat('endurance', 1) . '<br>' .
parent::getStat('intelligence', 1) . '<br>' .
parent::getStat('wisdom', 1) . '<br>' .
$this->experience . '<br>' .
$this->free_stat_points . '<br>' .
User::getInstance()->money()->get() . '<br>' .
User::getInstance()->money()->getBank();
$data = [
self::LEVEL => $this->level,
self::HEALTH => $this->showProgressBar($this->health, $this->maxHealth),
self::MANA => $this->showProgressBar($this->mana, $this->maxMana),
self::STRENGTH => parent::getStat('strength', 1),
self::DEXTERITY => parent::getStat('dexterity', 1),
self::INTUITION => parent::getStat('intuition', 1),
self::ENDURANCE => parent::getStat('endurance', 1),
self::INTELLIGENCE => parent::getStat('intelligence', 1),
self::WISDOM => parent::getStat('wisdom', 1),
self::EXPERIENCE => $this->experience,
self::FREE_STAT_POINTS => $this->freeStatPoints,
self::MONEY => User::getInstance()->money()->get(),
self::MONEY_IN_BANK => User::getInstance()->money()->getBank(),
];
$nameString = Nick::id($this->id)->full();
$str = '<div class="user-info">';
$str .= '<div class="info"><b>' . Nick::id($this->id)->full() . '</b></div><!-- info -->';
$str .= '<div class="stats-container">';
foreach ($data as $caption => $variable) {
$str .= '<div class="column" style="float: left;">' . $caption . '</div><!-- column -->';
$str .= '<div class="column">' . $variable . '</div><!-- column -->';
}
$str .= '</div><!-- stats-container -->';
$str .= '</div><!-- user-info -->';
return <<<HTML
<div class="user-info">
<div class="info"><b>$nameString</b></div><!-- info -->
<div class="stats-container">
<div class="column" style="float: left;">$captions</div><!-- column -->
<div class="column">$variables</div><!-- column -->
</div><!-- stats-container -->
</div><!-- user-info -->
HTML;
return $str;
}
public function userInfoStatsTest(): array
{
$stat = $this->getFullStats();
return [
'Сила' => $this->strength,
'Ловкость' => $this->dexterity,
'Интуиция' => $this->intuition,
'Выносливость' => $this->endurance,
'Интеллект' => $this->intelligence,
'Мудрость' => $this->wisdom,
'<br>HP' => $this->health . ' / ' . $this->maxHealth,
'MP' => $this->mana . ' / ' . $this->maxMana,
'Уворот' => $stat->evasion,
'Точность' => $stat->accuracy,
'Шанс крита' => $stat->criticals,
'Урон' => $stat->min_physical_damage . ' - ' . $stat->max_physical_damage,
'<br>Уровень' => $this->level,
'Опыт' => $this->experience,
'Деньги' => $this->money()->get(),
'<br>Локация' => Rooms::$roomNames[$this->room],
self::STRENGTH => $this->strength,
self::DEXTERITY => $this->dexterity,
self::INTUITION => $this->intuition,
self::ENDURANCE => $this->endurance,
self::INTELLIGENCE => $this->intelligence,
self::WISDOM => $this->wisdom,
'<br>' . self::HEALTH => $this->health . ' / ' . $this->maxHealth,
self::MANA => $this->mana . ' / ' . $this->maxMana,
self::EVASION => $stat->evasion,
self::ACCURACY => $stat->accuracy,
self::CRITICALS => $stat->criticals,
self::DAMAGE => $stat->min_physical_damage . ' - ' . $stat->max_physical_damage,
'<br>' . self::LEVEL => $this->level,
self::EXPERIENCE => $this->experience,
self::MONEY => $this->money()->get(),
'<br>' . self::LOCATION => Rooms::$roomNames[$this->room],
];
}
@@ -188,7 +209,7 @@ HTML;
$str .= "<span class='error'>Персонаж $this->login обезличен $hidden.</span>";
} else {
$str .= '<div class="user-info-container">';
$str .= $this->UserInfoDoll();
$str .= $this->userInfoDoll();
$str .= $this->ttz();
$str .= '<div class="slot-lower" style="font-size: xxx-large">' . $this->showProgressBar($this->health, $this->maxHealth) . '<br>' . $this->showProgressBar($this->mana, $this->maxMana) . '</div>';
$str .= '</div><!-- u-i-c -->';
@@ -208,7 +229,7 @@ HTML;
public function showUserDoll($isBattle = 0, $isMain = 0): string
{
try {
return '<div class="user-info-container">' . $this->UserInfoDoll($isBattle, $isMain) . '</div><!-- u-i-c -->';
return '<div class="user-info-container">' . $this->userInfoDoll($isBattle, $isMain) . '</div><!-- u-i-c -->';
} catch (GameException $e) {
return $e;
}
@@ -219,7 +240,7 @@ HTML;
public function showUserInfoMain(): string
{
try {
return '<div class="user-doll-container">' . $this->UserInfoDoll() . '</div><!-- user-doll-container -->' . $this->userInfoStats();
return '<div class="user-doll-container">' . $this->userInfoDoll() . '</div><!-- user-doll-container -->' . $this->userInfoStats();
} catch (GameException $e) {
return $e;
}
@@ -242,4 +263,4 @@ HTML;
}
return $r;
}
}
}