b9b4c01cf0
Signed-off-by: lopar <lopar.4ever@gmail.com>
245 lines
10 KiB
PHP
245 lines
10 KiB
PHP
<?php
|
||
|
||
namespace Battles;
|
||
|
||
use Battles\Models\User\Effects;
|
||
use Exceptions\GameException;
|
||
|
||
class UserInfo extends UserStats
|
||
{
|
||
private const PERCENT_20 = (20 / 100);
|
||
private const PERCENT_80 = (80 / 100);
|
||
use Rooms;
|
||
|
||
/**
|
||
* Отображает куклу персонажа (образ и слоты).
|
||
*
|
||
* @param int $isBattle установить 1, если куклу нужно отобразить в поединке (показывает параметры при наведении
|
||
* на образ).
|
||
* @param int $isMain установить 1, если куклу надо показать на странице игрока (по клику на предмет снимает
|
||
* его).
|
||
*
|
||
* @throws GameException
|
||
*/
|
||
private function UserInfoDoll(int $isBattle = 0, int $isMain = 0): string
|
||
{
|
||
$di = new DressedItems($this->id);
|
||
$stats = new UserStats($this->id);
|
||
$dressedItems = $di->getItemsInSlots();
|
||
$str = null;
|
||
for ($i = 1; $i <= 12; $i++) {
|
||
$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);
|
||
} 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);
|
||
}
|
||
} else {
|
||
$str .= sprintf('<img src="/i/sh/noitem.png" class="item-wrap-normal" title="Пустой слот [%s]" alt="Пустой слот [%s]">', $i, $i);
|
||
}
|
||
$str .= sprintf('</div><!-- slot-%s -->', $i);
|
||
}
|
||
$str .= '<div class="slot-image">';
|
||
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);
|
||
} else {
|
||
$str .= '<img src="/i/shadow/' . $this->shadow . '" alt="' . $this->login . '">';
|
||
}
|
||
$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],
|
||
|
||
];
|
||
$str = null;
|
||
$i = 0;
|
||
foreach ($arr as $item => $value) {
|
||
$str .= "<div class='column' style='text-align: right; margin-right: 10px;'>$item</div><div class='column' style='width: max-content;'>$value</div>";
|
||
if (in_array($i, [6, 9])) {
|
||
$str .= "<div style='margin-top: 10px;'></div><div></div>";
|
||
}
|
||
$i++;
|
||
}
|
||
return sprintf(
|
||
"<div class='info'>%s</div><!-- info --><div class='stats-container' style='display: grid; grid-template-columns: 150px 100px; font-size: 1.2em;'>%s</div>",
|
||
Nick::id($this->id)->full(1),
|
||
$str
|
||
);
|
||
}
|
||
|
||
private function showProgressBar(int $value, int $max_value)
|
||
{
|
||
$values = [
|
||
'%20%' => (int)round(self::PERCENT_20 * $max_value),
|
||
'%80%' => (int)round(self::PERCENT_80 * $max_value),
|
||
'%value' => $value,
|
||
'%max' => $max_value
|
||
];
|
||
$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);
|
||
}
|
||
|
||
/** Для вызова из main.php
|
||
* @throws GameException
|
||
*/
|
||
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();
|
||
|
||
$nameString = Nick::id($this->id)->full();
|
||
|
||
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;
|
||
}
|
||
|
||
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],
|
||
|
||
];
|
||
}
|
||
|
||
/** Для вызова из inf.php
|
||
* @throws GameException
|
||
*/
|
||
public function showUserInfo()
|
||
{
|
||
$str = null;
|
||
$hidden = UserEffect::hasHiddenProfile($this->id);
|
||
if ($this->block && !User::getInstance()->getAdmin()) {
|
||
$str .= "<span class='error'>Персонаж $this->login заблокирован!</span>";
|
||
} elseif (!empty($hidden) && !User::getInstance()->getAdmin()) {
|
||
$str .= "<span class='error'>Персонаж $this->login обезличен $hidden.</span>";
|
||
} else {
|
||
$str .= '<div class="user-info-container">';
|
||
$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 -->';
|
||
$str .= '<hr><!-- Нижняя часть -->';
|
||
$str .= '<div class="user-info-container-lower">';
|
||
$str .= '<h2>Об игроке</h2>';
|
||
$str .= $this->profile()->getRealname() ? "Имя: {$this->profile()->getRealname()}" : '';
|
||
$str .= $this->profile()->getInfo() ? '<br>' . nl2br($this->profile()->getInfo()) : '';
|
||
$str .= '</div><!-- u-i-c-l -->';
|
||
if (User::getInstance()->getAdmin()) {
|
||
$str .= UserPrivateInfo::get(User::getInstance());
|
||
}
|
||
}
|
||
echo $str;
|
||
}
|
||
|
||
public function showUserDoll($isBattle = 0, $isMain = 0): string
|
||
{
|
||
try {
|
||
return '<div class="user-info-container">' . $this->UserInfoDoll($isBattle, $isMain) . '</div><!-- u-i-c -->';
|
||
} catch (GameException $e) {
|
||
return $e;
|
||
}
|
||
}
|
||
|
||
/** Отображение на main.php
|
||
*/
|
||
public function showUserInfoMain(): string
|
||
{
|
||
try {
|
||
return '<div class="user-doll-container">' . $this->UserInfoDoll() . '</div><!-- user-doll-container -->' . $this->userInfoStats();
|
||
} catch (GameException $e) {
|
||
return $e;
|
||
}
|
||
}
|
||
|
||
public function showUserEffects(): string
|
||
{
|
||
$effs = Effects::getAll($this->id);
|
||
$img = UserEffect::$effectImage;
|
||
$r = '';
|
||
foreach ($effs as $effect) {
|
||
$timeleft = timeOut($effect->remaining_time - time());
|
||
$r .= "
|
||
<div>
|
||
<img class='image' src='/i/{$img[$effect->type]}' alt='$effect->name'>
|
||
<span class='title'>$effect->name</span>
|
||
<div class='timeleft'>$timeleft</div>
|
||
</div>
|
||
";
|
||
}
|
||
return $r;
|
||
}
|
||
} |