2020-08-30 13:44:57 +03:00
< ? php
2021-08-20 20:40:06 +03:00
2020-10-28 22:21:08 +02:00
namespace Battles ;
2021-08-20 20:40:06 +03:00
2021-03-11 21:47:52 +02:00
use Battles\Database\DBPDO ;
2021-02-01 16:40:21 +02:00
use Battles\Models\EffectsModel ;
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 ;
2021-08-20 20:40:06 +03:00
private int $bankMoney ;
//Тот, кто смотрит на информацию.
private User $watcher ;
public function __construct ( $user )
{
parent :: __construct ( $user );
$bank = new Bank ( $this -> id );
$this -> bankMoney = $bank -> getMoney ();
}
2020-08-30 19:28:15 +03:00
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
* его).
*/
2021-08-20 20:40:06 +03:00
private function UserInfoDoll ( int $isBattle = 0 , int $isMain = 0 )
2020-08-30 13:44:57 +03:00
{
$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 -->' ;
}
2021-08-20 20:40:06 +03:00
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
2020-08-30 13:44:57 +03:00
private function UserInfoStats ( $isMainWindow = 0 )
{
$captions = 'Уровень:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Местонахождение:' ;
$variables =
$this -> level . '<br>' .
2021-03-11 20:14:41 +02:00
parent :: getFullStats () -> strength . '<br>' .
parent :: getFullStats () -> dexterity . '<br>' .
parent :: getFullStats () -> intuition . '<br>' .
parent :: getFullStats () -> endurance . '<br>' .
parent :: getFullStats () -> intelligence . '<br>' .
parent :: getFullStats () -> wisdom . '<br>' .
2020-08-30 19:28:15 +03:00
Rooms :: $roomNames [ $this -> room ];
2020-08-30 13:44:57 +03:00
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>' .
2021-08-20 20:40:06 +03:00
$this -> bankMoney ;
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
{
$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-08-20 20:40:06 +03:00
$adminData = $this -> watcher -> getAdmin () ? $this -> showAdminOnlyData () : null ;
2021-03-10 23:43:48 +02:00
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
2021-08-20 20:40:06 +03:00
⁑ ИД Игрока: $this->id<br>
⁑ ИД Комнаты: $this->room<br>
⁑ Деньги: $this->money<br>
⁑ Деньги в банке: $this->bankMoney<br>
⁑ Опыт: $this->experience<br>
⁑ Нераспределённые очки: $this->free_stat_points<br>
2021-03-10 23:43:48 +02:00
INFO ;
2020-08-30 13:44:57 +03:00
}
private function Info ()
{
echo '<div class="user-info-container">' ;
$this -> UserInfoDoll ();
2021-08-20 20:40:06 +03:00
$this -> ttz ();
echo '<div class="slot-lower"> <!-- statuses! --></div>' ;
echo '</div><!-- u-i-c -->' ;
2020-08-30 13:44:57 +03:00
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 ) : " " ;
2021-08-20 20:40:06 +03:00
echo '</div><!-- u-i-c-l -->' ;
if ( $this -> watcher -> getAdmin () || $this -> watcher -> getAlign () == 1 ) {
echo $this -> showPrivateData ();
}
2020-08-30 13:44:57 +03:00
}
public function showUserInfo ()
{
2021-02-01 16:40:21 +02:00
$effects = new EffectsModel ( $this -> id );
2020-08-30 13:44:57 +03:00
2021-08-20 20:40:06 +03:00
if ( $this -> block && ( ! $this -> watcher -> getAdmin () || ! $this -> watcher -> getAlign () == 1 )) {
2021-03-10 23:45:16 +02:00
echo " <span class='error'>Персонаж $this->login заблокирован!</span> " ;
2021-08-20 20:40:06 +03:00
} elseif ( $effects -> getHideUserInfoStatus () && ( ! $this -> watcher -> getAdmin () || ! $this -> watcher -> getAlign () == 1 )) {
2021-01-28 23:05:34 +02:00
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 ();
}
}
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 -->' ;
}
2021-03-11 21:47:52 +02:00
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>
2021-08-20 20:40:06 +03:00
<img class='image' src='/i/ { $img [ $effect -> type ] } ' alt=' $effect->name '>
<span class='title'> $effect->name </span>
2021-03-11 21:47:52 +02:00
<div class='timeleft'> $timeleft </div>
</div>
" ;
}
return $r ;
}
2021-08-20 20:40:06 +03:00
/**
* @param mixed $watcher_id
*/
public function setWatcher ( int $watcher_id ) : void
2021-05-12 21:58:52 +03:00
{
2021-08-20 20:40:06 +03:00
$this -> watcher = new User ( $watcher_id );
2021-05-12 21:58:52 +03:00
}
2021-03-11 21:47:52 +02:00
2021-08-20 20:40:06 +03:00
2020-08-30 13:44:57 +03:00
}