265 lines
11 KiB
PHP
265 lines
11 KiB
PHP
<?php
|
||
|
||
namespace Battles;
|
||
|
||
use Battles\Database\DBPDO;
|
||
use Battles\Models\EffectsModel;
|
||
|
||
class UserInfo extends UserStats
|
||
{
|
||
use Rooms;
|
||
|
||
private int $bankMoney;
|
||
//Тот, кто смотрит на информацию.
|
||
private User $watcher;
|
||
|
||
public function __construct($user)
|
||
{
|
||
parent::__construct($user);
|
||
$bank = new Bank($this->id);
|
||
$this->bankMoney = $bank->getMoney();
|
||
}
|
||
|
||
/**
|
||
* Отображает куклу персонажа (образ и слоты).
|
||
*
|
||
* @param int $isBattle установить 1, если куклу нужно отобразить в поединке (показывает параметры при наведении
|
||
* на образ).
|
||
* @param int $isMain установить 1, если куклу надо показать на странице игрока (по клику на предмет снимает
|
||
* его).
|
||
*/
|
||
private function UserInfoDoll(int $isBattle = 0, int $isMain = 0)
|
||
{
|
||
$di = new DressedItems($this->id);
|
||
$dressedItems = $di->getItemsInSlots();
|
||
for ($i = 1; $i <= 12; $i++) {
|
||
echo sprintf('<div class="slot-%s">', $i);
|
||
if (!empty($dressedItems->$i)) {
|
||
if (!$isBattle && $isMain) {
|
||
echo 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 {
|
||
echo 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 {
|
||
echo sprintf('<img src="/i/sh/noitem.png" class="item-wrap-normal" title="Пустой слот [%s]" alt="Пустой слот [%s]">', $i, $i);
|
||
}
|
||
echo sprintf('</div><!-- slot-%s -->', $i);
|
||
}
|
||
echo '<div class="slot-image">';
|
||
if ($isBattle) {
|
||
echo 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, $this->login, $this->login, $this->level, $this->strength, $this->dexterity, $this->intuition, $this->endurance, $this->intelligence, $this->wisdom);
|
||
unset($sh);
|
||
} else {
|
||
echo '<img src="/i/shadow/' . $this->shadow . '" alt="' . $this->login . '">';
|
||
}
|
||
echo '</div><!-- slot-image -->';
|
||
}
|
||
|
||
private function ttz()
|
||
{
|
||
$arr = [
|
||
'Уровень' => $this->level,
|
||
'Сила' => $this->printStat('strength'),
|
||
'Ловкость' => $this->printStat('dexterity'),
|
||
'Интуиция' => $this->printStat('intuition'),
|
||
'Выносливость' => $this->printStat('endurance'),
|
||
'Интеллект' => $this->printStat('intelligence'),
|
||
'Мудрость' => $this->printStat('wisdom'),
|
||
'Уворот' => $this->getFullStats()->evasion,
|
||
'Точность' => $this->getFullStats()->accuracy,
|
||
'Шанс крита' => $this->getFullStats()->criticals,
|
||
'Урон' => $this->getFullStats()->min_physical_damage . ' - ' . $this->getFullStats()->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'>$value</div>";
|
||
if (in_array($i,[6,9])) {
|
||
$str .= "<div style='margin-top: 10px;'></div><div></div>";
|
||
}
|
||
$i++;
|
||
}
|
||
$nameString = $this->align ? "<img src='/i/align_$this->align.png' alt='Склонность'>" : "";
|
||
$nameString .= $this->block ? "<span class='private' style='text-decoration: line-through;'>$this->login</span>" : "<b>$this->login</b>";
|
||
$nameString .= $this->clan ? "<img src='/i/clan/$this->clan.png' alt='Клан'>" : "";
|
||
echo "<div class='info'><b>$nameString</b></div><!-- info -->";
|
||
echo "<div class='stats-container' style='display: grid; grid-template-columns: 150px 100px; font-size: 1.2em;'>$str</div>";
|
||
}
|
||
|
||
private function printStat($statName): string
|
||
{
|
||
return $this->getFreeStatPoints() ? $this->getStat($statName, 1) . '(' . $this->getFullStats()->$statName . ')' : $this->getFullStats()->$statName;
|
||
}
|
||
|
||
//TODO вызывать из main.php
|
||
private function UserInfoStats($isMainWindow = 0)
|
||
{
|
||
$captions = 'Уровень:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Местонахождение:';
|
||
$variables =
|
||
$this->level . '<br>' .
|
||
parent::getFullStats()->strength . '<br>' .
|
||
parent::getFullStats()->dexterity . '<br>' .
|
||
parent::getFullStats()->intuition . '<br>' .
|
||
parent::getFullStats()->endurance . '<br>' .
|
||
parent::getFullStats()->intelligence . '<br>' .
|
||
parent::getFullStats()->wisdom . '<br>' .
|
||
Rooms::$roomNames[$this->room];
|
||
if ($isMainWindow) {
|
||
$captions = 'Уровень:<br>Здоровье:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Опыт:<br>Очки характеристик:<br>Деньги:<br>Деньги в банке:';
|
||
$variables =
|
||
$this->level . '<br>' .
|
||
$this->health . '<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>' .
|
||
$this->money . '<br>' .
|
||
$this->bankMoney;
|
||
}
|
||
$nameString = null;
|
||
$nameString .= $this->align ? "<img src='/i/align_$this->align.png' alt='Склонность'>" : "";
|
||
$nameString .= $this->block ? "<span class='private' style='text-decoration: line-through;'>$this->login</span>" : "<b>$this->login</b>";
|
||
$nameString .= $this->clan ? "<img src='/i/clan/$this->clan.png' alt='Клан'>" : "";
|
||
|
||
echo <<<HTML
|
||
<div class="user-info">
|
||
<div class="info"><b>$nameString</b></div><!-- info -->
|
||
<div class="stats-container">
|
||
<div class="column">$captions</div><!-- column -->
|
||
<div class="column">$variables</div><!-- column -->
|
||
</div><!-- stats-container -->
|
||
</div><!-- user-info -->
|
||
HTML;
|
||
}
|
||
|
||
/**
|
||
* О персонаже для модераторов.
|
||
* @return string|null
|
||
*/
|
||
private function showPrivateData(): ?string
|
||
{
|
||
$birthday = date('d.m.Y', strtotime($this->borndate));
|
||
$userLogs = GameLogs::getUserLogs($this->id);
|
||
$log = null;
|
||
while ($userLogRow = $userLogs->fetchArray(SQLITE3_ASSOC)) {
|
||
$log .= sprintf('<code>%s</code><br>', date('d.m.Y H:i ', strtotime($userLogRow['date'])) . $userLogRow['text']);
|
||
}
|
||
$adminData = $this->watcher->getAdmin() ? $this->showAdminOnlyData() : null;
|
||
return <<<INFO
|
||
<div class="secret-info">
|
||
E-Mail: $this->email<br>
|
||
ДР Игрока: $birthday<br>
|
||
IP Регистрации: $this->ip<br>
|
||
$adminData<br>
|
||
<div class="secret-info-user-log"><b>Личное дело</b><br>
|
||
$log
|
||
</div><!-- secret-info-user-log -->
|
||
</div><!-- secret-info -->
|
||
INFO;
|
||
}
|
||
|
||
/**
|
||
* О персонаже для администраторов.
|
||
* @return string|null
|
||
*/
|
||
private function showAdminOnlyData(): ?string
|
||
{
|
||
return <<<INFO
|
||
⁑ ИД Игрока: $this->id<br>
|
||
⁑ ИД Комнаты: $this->room<br>
|
||
⁑ Деньги: $this->money<br>
|
||
⁑ Деньги в банке: $this->bankMoney<br>
|
||
⁑ Опыт: $this->experience<br>
|
||
⁑ Нераспределённые очки: $this->free_stat_points<br>
|
||
INFO;
|
||
|
||
}
|
||
|
||
private function Info()
|
||
{
|
||
echo '<div class="user-info-container">';
|
||
$this->UserInfoDoll();
|
||
$this->ttz();
|
||
echo '<div class="slot-lower"> <!-- statuses! --></div>';
|
||
echo '</div><!-- u-i-c -->';
|
||
echo '<hr><!-- Нижняя часть -->';
|
||
echo '<div class="user-info-container-lower">';
|
||
echo '<h2>Об игроке</h2>';
|
||
echo $this->realname ? "Имя: $this->realname" : "";
|
||
echo $this->info ? "<br>" . nl2br($this->info) : "";
|
||
echo '</div><!-- u-i-c-l -->';
|
||
if ($this->watcher->getAdmin() || $this->watcher->getAlign() == 1) {
|
||
echo $this->showPrivateData();
|
||
}
|
||
}
|
||
|
||
public function showUserInfo()
|
||
{
|
||
$effects = new EffectsModel($this->id);
|
||
|
||
if ($this->block && (!$this->watcher->getAdmin() || !$this->watcher->getAlign() == 1)) {
|
||
echo "<span class='error'>Персонаж $this->login заблокирован!</span>";
|
||
} elseif ($effects->getHideUserInfoStatus() && (!$this->watcher->getAdmin() || !$this->watcher->getAlign() == 1)) {
|
||
if ($effects->getHideUserInfoStatus() == -1) {
|
||
$date = 'навсегда';
|
||
} else {
|
||
$date = 'до' . date('d.m.Y', strtotime($effects->getHideUserInfoStatus()));
|
||
}
|
||
echo "<span class='error'>Персонаж $this->login обезличен $date.</span>";
|
||
} else {
|
||
$this->Info();
|
||
}
|
||
}
|
||
|
||
public function showUserDoll($isBattle = 0, $isMain = 0)
|
||
{
|
||
echo '<div class="user-info-container">';
|
||
$this->UserInfoDoll($isBattle, $isMain);
|
||
echo '</div><!-- user-info-container -->';
|
||
}
|
||
|
||
public function showUserInfoMain()
|
||
{
|
||
echo '<div class="user-info-container">';
|
||
$this->UserInfoDoll();
|
||
$this->userInfoStats(1);
|
||
echo '</div><!-- user-info-container -->';
|
||
}
|
||
|
||
public function showUserEffects(): string
|
||
{
|
||
$effs = DBPDO::INIT()->ofetchAll('SELECT * FROM users_effects WHERE owner_id = ?', $this->id);
|
||
$img = UserEffects::$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;
|
||
}
|
||
|
||
/**
|
||
* @param mixed $watcher_id
|
||
*/
|
||
public function setWatcher(int $watcher_id): void
|
||
{
|
||
$this->watcher = new User($watcher_id);
|
||
}
|
||
|
||
|
||
} |