Зимние правки. MVC/

Signed-off-by: lopar <lopar.4ever@gmail.com>
This commit is contained in:
lopar
2022-08-09 22:57:43 +03:00
parent 0f62ee20e7
commit b9b4c01cf0
104 changed files with 2254 additions and 2086 deletions
+31 -12
View File
@@ -2,17 +2,17 @@
namespace Battles;
use Battles\Database\Db;
/**
* Разные способы отображения строки с логином персонажа.
*/
const INVIS = '<i>невидимка</i>';
class Nick extends UserStats
class Nick
{
private function isInvisible()
private User $user;
private function __construct(int $userid)
{
return Db::getInstance()->execute('SELECT count(*) FROM users_effects WHERE type = 1022 AND owner_id = ?', $this->id)->fetchColumn();
$this->user = User::getInstance($userid);
}
/**
@@ -21,25 +21,41 @@ class Nick extends UserStats
*/
private function getAlignImage(): ?string
{
return $this->align ? "<img src='i/align_$this->align.gif' alt='Склонность'>" : null;
return $this->getImage($this->user->getAlign(), '/i/align_');
}
/**
* Отображение иконки клана.
* @return string
*/
private function getClanImage(): ?string
private function getClanImage(): string
{
return $this->clan ? "<img src='i/clan/$this->clan.png' alt='Клан'>" : null;
return $this->getImage($this->user->getClan(), '/i/clan/');
}
private function getImage($name, $path): string
{
if (empty($name)) {
return '';
}
$file = $path . $name . '.png';
$alt = '';
if (strpos($path, 'align')) {
$alt = '{a:' . $name . '}';
} elseif (strpos($path, 'clan')) {
$alt = '{c:' . $name . '}';
}
return file_exists($file) ? "<img src='$file' alt='$alt'>" : $alt;
}
private function getInfolinkImage(): string
{
return "<a href='inf.php?$this->login' target='_blank'><img src='i/inf.gif' alt='Ссылка на профиль'></a>";
return "<a href='inf.php?" . $this->user->getLogin() . "' target='_blank'><img src='i/inf.gif' alt='Ссылка на профиль'></a>";
}
/**
* Вызов класса из самого себя. Читать про обратное связывание и пытаться что-то понять.
*
* @param $playerId
*
* @return Nick
@@ -58,7 +74,10 @@ class Nick extends UserStats
*/
public function full(int $showInvisibility = 0): string
{
return !$showInvisibility && $this->isInvisible() ? INVIS : $this->getAlignImage() . $this->getClanImage() . " <b>$this->login</b> [$this->level] " . $this->getInfolinkImage();
if ($showInvisibility === 0 && UserEffect::isInvisible($this->user->getId())) {
return INVIS;
}
return $this->getAlignImage() . '&nbsp;' . $this->getClanImage() . '&nbsp;' . $this->user->getLogin() . " [" . $this->user->getLevel() . "] " . $this->getInfolinkImage();
}
/**
@@ -68,7 +87,7 @@ class Nick extends UserStats
*/
public function short(): string
{
return $this->login;
return $this->user->getLogin();
}
/**
@@ -77,6 +96,6 @@ class Nick extends UserStats
*/
public function battle(): string
{
return $this->full() . "<img src='i/herz.gif' alt='HP'> [$this->health/$this->maxHealth]";
return $this->full() . "<img src='i/herz.gif' alt='HP'> [" . $this->user->stats()->getHealth() . "/" . $this->user->stats()->getMaxHealth() . "]";
}
}