2020-08-30 10:44:57 +00:00
< ? php
2021-08-20 17:40:06 +00:00
2020-10-28 20:21:08 +00:00
namespace Battles ;
2021-08-20 17:40:06 +00:00
2022-01-26 23:15:33 +00:00
use Battles\Database\Db ;
2021-02-01 14:40:21 +00:00
use Battles\Models\EffectsModel ;
2021-03-10 21:38:14 +00:00
class UserInfo extends UserStats
2020-08-30 10:44:57 +00:00
{
2020-08-30 16:28:15 +00:00
use Rooms ;
2021-08-20 17:40:06 +00:00
private int $bankMoney ;
public function __construct ( $user )
{
parent :: __construct ( $user );
$bank = new Bank ( $this -> id );
$this -> bankMoney = $bank -> getMoney ();
}
2020-08-30 16:28:15 +00:00
2020-08-30 10:44:57 +00:00
/**
* Отображает куклу персонажа ( образ и слоты ) .
*
2021-01-28 21:05:34 +00:00
* @ param int $isBattle установить 1 , если куклу нужно отобразить в поединке ( показывает параметры при наведении
2020-08-30 10:44:57 +00:00
* на образ ) .
2021-01-28 21:05:34 +00:00
* @ param int $isMain установить 1 , если куклу надо показать на странице игрока ( по клику на предмет снимает
2020-08-30 10:44:57 +00:00
* е г о ) .
*/
2021-08-20 17:40:06 +00:00
private function UserInfoDoll ( int $isBattle = 0 , int $isMain = 0 )
2020-08-30 10:44:57 +00: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 21:20:56 +00:00
if ( ! empty ( $dressedItems -> $i )) {
2020-08-30 10:44:57 +00:00
if ( ! $isBattle && $isMain ) {
2021-03-10 21:20:56 +00: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 10:44:57 +00:00
} else {
2021-03-10 21:20:56 +00: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 10:44:57 +00: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 21:47:33 +00: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 10:44:57 +00:00
unset ( $sh );
} else {
echo '<img src="/i/shadow/' . $this -> shadow . '" alt="' . $this -> login . '">' ;
}
echo '</div><!-- slot-image -->' ;
}
2021-08-20 17:40:06 +00:00
private function ttz ()
{
2022-01-25 16:16:09 +00:00
$stat = $this -> getFullStats ();
2021-08-20 17:40:06 +00:00
$arr = [
'Уровень' => $this -> level ,
'Сила' => $this -> printStat ( 'strength' ),
'Ловкость' => $this -> printStat ( 'dexterity' ),
'Интуиция' => $this -> printStat ( 'intuition' ),
'Выносливость' => $this -> printStat ( 'endurance' ),
'Интеллект' => $this -> printStat ( 'intelligence' ),
'Мудрость' => $this -> printStat ( 'wisdom' ),
2022-01-25 16:16:09 +00:00
'Уворот' => $stat -> evasion ,
'Точность' => $stat -> accuracy ,
'Шанс крита' => $stat -> criticals ,
'Урон' => $stat -> min_physical_damage . ' - ' . $stat -> max_physical_damage ,
2021-08-20 17:40:06 +00:00
'Локация' => 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
{
2022-01-25 16:16:09 +00:00
$stat = $this -> getFullStats ();
return $this -> getFreeStatPoints () ? $this -> getStat ( $statName , 1 ) . '(' . $stat -> $statName . ')' : $stat -> $statName ;
2021-08-20 17:40:06 +00:00
}
//TODO вызывать из main.php
2020-08-30 10:44:57 +00:00
private function UserInfoStats ( $isMainWindow = 0 )
{
2022-01-25 16:16:09 +00:00
$stat = $this -> getFullStats ();
2020-08-30 10:44:57 +00:00
$captions = 'Уровень:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Местонахождение:' ;
$variables =
$this -> level . '<br>' .
2022-01-25 16:16:09 +00:00
$stat -> strength . '<br>' .
$stat -> dexterity . '<br>' .
$stat -> intuition . '<br>' .
$stat -> endurance . '<br>' .
$stat -> intelligence . '<br>' .
$stat -> wisdom . '<br>' .
2020-08-30 16:28:15 +00:00
Rooms :: $roomNames [ $this -> room ];
2020-08-30 10:44:57 +00: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 17:40:06 +00:00
$this -> bankMoney ;
2020-08-30 10:44:57 +00:00
}
2021-03-10 21:43:48 +00:00
$nameString = null ;
2022-01-25 16:37:12 +00:00
if ( $this -> align ) {
if ( file_exists ( " /i/align_ $this->align .png " )) {
$nameString .= " <img src='/i/align_ $this->align .png' alt='Склонность'> " ;
} else {
$nameString .= " <svg width=16 height=16><circle cx=8 cy=8 r=6 stroke=darkorange stroke-width=1 fill=orange></circle></svg> " ;
}
} else {
$nameString .= " " ;
}
2021-03-10 21:43:48 +00:00
$nameString .= $this -> block ? " <span class='private' style='text-decoration: line-through;'> $this->login </span> " : " <b> $this->login </b> " ;
2022-01-25 16:37:12 +00:00
if ( $this -> clan ) {
if ( file_exists ( " /i/clan/ $this->clan .png " )) {
$nameString .= " <img src='/i/clan/ $this->clan .png' alt='Клан'> " ;
} else {
$nameString .= " <svg width=16 height=16><circle cx=8 cy=8 r=6 stroke=darkred stroke-width=1 fill=red></circle></svg> " ;
}
} else {
$nameString .= " " ;
}
2021-03-10 21:43:48 +00:00
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 10:44:57 +00:00
}
2022-01-26 23:15:33 +00:00
$adminData = User :: getInstance () -> getAdmin () ? $this -> showAdminOnlyData () : null ;
2021-03-10 21:43:48 +00: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 17:40:06 +00:00
⁑ ИД Игрока : $this -> id < br >
⁑ ИД Комнаты : $this -> room < br >
⁑ Деньги : $this -> money < br >
⁑ Деньги в банке : $this -> bankMoney < br >
⁑ Опыт : $this -> experience < br >
⁑ Нераспределённые очки : $this -> free_stat_points < br >
2021-03-10 21:43:48 +00:00
INFO ;
2020-08-30 10:44:57 +00:00
}
private function Info ()
{
echo '<div class="user-info-container">' ;
$this -> UserInfoDoll ();
2021-08-20 17:40:06 +00:00
$this -> ttz ();
echo '<div class="slot-lower"> <!-- statuses! --></div>' ;
echo '</div><!-- u-i-c -->' ;
2020-08-30 10:44:57 +00:00
echo '<hr><!-- Нижняя часть -->' ;
echo '<div class="user-info-container-lower">' ;
echo '<h2>О б игроке</h2>' ;
2021-03-10 21:47:33 +00:00
echo $this -> realname ? " Имя: $this->realname " : " " ;
echo $this -> info ? " <br> " . nl2br ( $this -> info ) : " " ;
2021-08-20 17:40:06 +00:00
echo '</div><!-- u-i-c-l -->' ;
2022-01-26 23:15:33 +00:00
if ( User :: getInstance () -> getAdmin () || User :: getInstance () -> getAlign () == 1 ) {
2021-08-20 17:40:06 +00:00
echo $this -> showPrivateData ();
}
2020-08-30 10:44:57 +00:00
}
public function showUserInfo ()
{
2021-02-01 14:40:21 +00:00
$effects = new EffectsModel ( $this -> id );
2020-08-30 10:44:57 +00:00
2022-01-26 23:15:33 +00:00
if ( $this -> block && ( ! User :: getInstance () -> getAdmin () || ! User :: getInstance () -> getAlign () == 1 )) {
2021-03-10 21:45:16 +00:00
echo " <span class='error'>Персонаж $this->login заблокирован!</span> " ;
2022-01-26 23:15:33 +00:00
} elseif ( $effects -> getHideUserInfoStatus () && ( ! User :: getInstance () -> getAdmin () || ! User :: getInstance () -> getAlign () == 1 )) {
2021-01-28 21:05:34 +00:00
if ( $effects -> getHideUserInfoStatus () == - 1 ) {
2020-08-30 10:44:57 +00:00
$date = 'навсегда' ;
} else {
2021-01-28 21:05:34 +00:00
$date = 'до' . date ( 'd.m.Y' , strtotime ( $effects -> getHideUserInfoStatus ()));
2020-08-30 10:44:57 +00:00
}
2021-03-10 21:45:16 +00:00
echo " <span class='error'>Персонаж $this->login обезличен $date .</span> " ;
2020-08-30 10:44:57 +00: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 19:47:52 +00:00
public function showUserEffects () : string
{
2022-01-26 23:15:33 +00:00
$effs = Db :: getInstance () -> ofetchAll ( 'SELECT * FROM users_effects WHERE owner_id = ?' , $this -> id );
2021-03-11 19:47:52 +00:00
$img = UserEffects :: $effectImage ;
$r = '' ;
foreach ( $effs as $effect ) {
$timeleft = timeOut ( $effect -> remaining_time - time ());
$r .= "
< div >
2021-08-20 17:40:06 +00:00
< img class = 'image' src = '/i/{$img[$effect->type]}' alt = '$effect->name' >
< span class = 'title' > $effect -> name </ span >
2021-03-11 19:47:52 +00:00
< div class = 'timeleft' > $timeleft </ div >
</ div >
" ;
}
return $r ;
}
2020-08-30 10:44:57 +00:00
}