2020-08-30 13:44:57 +03:00
< ? php
2020-10-28 22:21:08 +02:00
namespace Battles ;
2021-02-01 16:40:21 +02:00
use Battles\Models\EffectsModel ;
use Exceptions\GameException ;
2021-03-10 23:38:14 +02:00
class UserInfo extends UserStats
2020-08-30 13:44:57 +03:00
{
2020-08-30 19:28:15 +03:00
use Rooms ;
//Статусы того, кто смотрит на информацию.
public $watcher_id ;
private $watcherIsAdmin ;
private $watcherIsModerator ;
2020-08-30 13:44:57 +03:00
/**
* Отображает куклу персонажа (образ и слоты).
*
2021-01-28 23:05:34 +02:00
* @param int $isBattle установить 1, если куклу нужно отобразить в поединке (показывает параметры при наведении
2020-08-30 13:44:57 +03:00
* на образ).
2021-01-28 23:05:34 +02:00
* @param int $isMain установить 1, если куклу надо показать на странице игрока (по клику на предмет снимает
2020-08-30 13:44:57 +03:00
* его).
*/
private function UserInfoDoll ( $isBattle = 0 , $isMain = 0 )
{
$di = new DressedItems ( $this -> id );
$dressedItems = $di -> getItemsInSlots ();
for ( $i = 1 ; $i <= 12 ; $i ++ ) {
echo sprintf ( '<div class="slot-%s">' , $i );
2021-03-10 23:20:56 +02:00
if ( ! empty ( $dressedItems -> $i )) {
2020-08-30 13:44:57 +03:00
if ( ! $isBattle && $isMain ) {
2021-03-10 23:20:56 +02:00
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 );
2020-08-30 13:44:57 +03:00
} else {
2021-03-10 23:20:56 +02:00
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 );
2020-08-30 13:44:57 +03:00
}
} 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 ) {
2021-03-10 23:47:33 +02:00
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 );
2020-08-30 13:44:57 +03:00
unset ( $sh );
} else {
echo '<img src="/i/shadow/' . $this -> shadow . '" alt="' . $this -> login . '">' ;
}
echo '</div><!-- slot-image -->' ;
}
private function UserInfoStats ( $isMainWindow = 0 )
{
$captions = 'Уровень:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Местонахождение:' ;
$variables =
$this -> level . '<br>' .
parent :: getStat ( 'strength' ) . '<br>' .
parent :: getStat ( 'dexterity' ) . '<br>' .
parent :: getStat ( 'intuition' ) . '<br>' .
parent :: getStat ( 'endurance' ) . '<br>' .
parent :: getStat ( 'intelligence' ) . '<br>' .
parent :: getStat ( 'wisdom' ) . '<br>' .
2020-08-30 19:28:15 +03:00
Rooms :: $roomNames [ $this -> room ];
2020-08-30 13:44:57 +03:00
if ( $isMainWindow ) {
$this -> Bank = new Bank ( $this -> id );
$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>' .
2020-10-28 14:33:50 +02:00
$this -> Bank -> getMoney ();
2020-08-30 13:44:57 +03:00
}
2021-03-10 23:43:48 +02:00
$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
{
if ( ! $this -> watcherIsAdmin || ! $this -> watcherIsModerator ) {
return null ;
2020-08-30 13:44:57 +03:00
}
2021-03-10 23:43:48 +02:00
$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' ]);
2020-08-30 13:44:57 +03:00
}
2021-03-10 23:43:48 +02:00
$adminData = $this -> watcherIsAdmin ? $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
{
$this -> Bank = new Bank ( $this -> id );
$bankMoney = $this -> Bank -> getMoney ();
return <<< INFO
ИД Игрока: $this->id<br>
ИД Комнаты: $this->room<br>
Деньги: $this->money<br>
Деньги в банке: $bankMoney<br>
Опыт: $this->experience<br>
Нераспределённые очки: $this->free_stat_points<br>
INFO ;
2020-08-30 13:44:57 +03:00
}
private function Info ()
{
echo '<div class="user-info-container">' ;
$this -> UserInfoDoll ();
$this -> UserInfoStats ();
2021-03-10 23:43:48 +02:00
echo '<div class="slot-lower"> <!-- statuses! -->' ;
2020-08-30 13:44:57 +03:00
echo '</div><!-- slot-lower -->' ;
echo '<div class="user-signs">' ;
echo sprintf ( '<img src="i/zodiac/%s.png" alt="Родовой знак">' , $this -> showStarSign ());
echo '</div><!-- user-signs -->' ;
echo '</div><!-- user-info-container -->' ;
echo '<hr><!-- Нижняя часть -->' ;
echo '<div class="user-info-container-lower">' ;
echo '<h2>Об игроке</h2>' ;
2021-03-10 23:47:33 +02:00
echo $this -> realname ? " Имя: $this->realname " : " " ;
echo $this -> info ? " <br> " . nl2br ( $this -> info ) : " " ;
2020-08-30 13:44:57 +03:00
echo '</div><!-- user-info-container-lower -->' ;
2021-03-10 23:43:48 +02:00
echo $this -> showPrivateData ();
2020-08-30 13:44:57 +03:00
}
public function showUserInfo ()
{
$this -> WatcherStatus ();
2021-02-01 16:40:21 +02:00
$effects = new EffectsModel ( $this -> id );
2020-08-30 13:44:57 +03:00
if ( $this -> block && ( ! $this -> watcherIsAdmin || ! $this -> watcherIsModerator )) {
2021-03-10 23:45:16 +02:00
echo " <span class='error'>Персонаж $this->login заблокирован!</span> " ;
2021-01-28 23:05:34 +02:00
} elseif ( $effects -> getHideUserInfoStatus () && ( ! $this -> watcherIsAdmin || ! $this -> watcherIsModerator )) {
if ( $effects -> getHideUserInfoStatus () == - 1 ) {
2020-08-30 13:44:57 +03:00
$date = 'навсегда' ;
} else {
2021-01-28 23:05:34 +02:00
$date = 'до' . date ( 'd.m.Y' , strtotime ( $effects -> getHideUserInfoStatus ()));
2020-08-30 13:44:57 +03:00
}
2021-03-10 23:45:16 +02:00
echo " <span class='error'>Персонаж $this->login обезличен $date .</span> " ;
2020-08-30 13:44:57 +03:00
} else {
$this -> Info ();
}
}
2020-08-30 19:28:15 +03:00
private function WatcherStatus ()
{
2021-01-28 23:05:34 +02:00
$query = parent :: $db -> fetch ( 'SELECT align, admin FROM users WHERE id = ?' , $this -> watcher_id );
2020-08-30 19:28:15 +03:00
if ( $query [ 'admin' ]) {
$this -> watcherIsAdmin = 1 ;
}
if ( $query [ 'align' ] == 1 ) {
$this -> watcherIsModerator = 1 ;
}
}
2020-08-30 13:44:57 +03:00
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 -->' ;
}
}