battles/classes/Battles/UserInfo.php

267 lines
11 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Battles;
use Battles\Models\User\Effects;
use Exceptions\GameException;
2021-02-01 14:40:21 +00:00
class UserInfo extends UserStats
{
2022-12-16 23:20:43 +00:00
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);
2022-12-16 23:20:43 +00:00
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;
/**
* Отображает куклу персонажа (образ и слоты).
*
* @param int $isBattle установить 1, если куклу нужно отобразить в поединке (показывает параметры при наведении
* на образ).
2022-12-16 23:20:43 +00:00
* @param int $isMain установить 1, если куклу надо показать на странице игрока (по клику на предмет снимает
* его).
*
* @throws GameException
*/
2022-12-16 23:20:43 +00:00
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) {
2022-12-16 23:20:43 +00:00
$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 {
2022-12-16 23:20:43 +00:00
$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">';
2022-12-16 23:20:43 +00:00
$str .= '<img src="/i/shadow/' . $this->shadow . '" alt="' . $this->login;
if ($isBattle) {
2022-12-16 23:20:43 +00:00
$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 {
2022-12-16 23:20:43 +00:00
$str .= '">';
}
$str .= '</div><!-- slot-image -->';
return $str;
}
/** Вызов из inf.php */
private function ttz(): string
{
$stat = $this->getFullStats();
$arr = [
2022-12-16 23:20:43 +00:00
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;
$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
);
}
2022-12-16 23:20:43 +00:00
private function showProgressBar(int $value, int $maxValue)
{
$values = [
2022-12-16 23:20:43 +00:00
'%20%' => (int)round(self::PERCENT_20 * $maxValue),
'%80%' => (int)round(self::PERCENT_80 * $maxValue),
'%value' => $value,
2022-12-16 23:20:43 +00:00
'%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);
}
/** Для вызова из main.php
* @throws GameException
*/
2022-12-16 23:20:43 +00:00
private function userInfoStats(): string
{
2022-12-16 23:20:43 +00:00
$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(),
];
$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 $str;
}
public function userInfoStatsTest(): array
{
$stat = $this->getFullStats();
return [
2022-12-16 23:20:43 +00:00
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],
];
}
/** Для вызова из 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">';
2022-12-16 23:20:43 +00:00
$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 {
2022-12-16 23:20:43 +00:00
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 {
2022-12-16 23:20:43 +00:00
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;
}
2022-12-16 23:20:43 +00:00
}