battles/classes/Battles/Nick.php

104 lines
3.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Battles;
/**
* Разные способы отображения строки с логином персонажа.
*/
const INVIS = '<i>невидимка</i>';
class Nick extends User
{
private function getInvisibilityStatus()
{
return self::$db->fetch('SELECT 1 FROM users_effects WHERE type = 1022 AND owner_id = ?', $this->id);
}
/**
* Отображение иконки склонности.
* @return string
*/
private function getAlignToNickname():?string
{
if ($this->align) {
return sprintf('<img src="i/align_%s.gif">', $this->align);
} else {
return null;
}
}
/**
* Отображение иконки клана.
* @return string
*/
private function getClanToNickname():?string
{
if ($this->clan) {
return sprintf('<img src="i/clan/%s.png">', $this->clan);
} else {
return null;
}
}
/**
* Вызов класса из самого себя. Читать про обратное связывание и пытаться что-то понять.
* @param $playerId
*
* @return Nick
*/
public static function id($playerId): Nick
{
return new self($playerId);
}
/**
* Возвращает строку со склонностью, кланом, логином, уровнем, ссылкой на профиль.
*
* @param int $showInvisibility отображать логин даже если персонаж невидимка.
*
* @return string
*/
public function full($showInvisibility = 0):string
{
if (!$showInvisibility && $this->getInvisibilityStatus()) {
return INVIS;
}
return $this->getAlignToNickname().$this->getClanToNickname().sprintf('<b>%s</b> [%s] <a href="inf.php?%s" target="_blank"><img src="i/inf.gif" style="width:12px;height:11px"></a>', $this->login, $this->level, $this->login);
}
/**
* Возвращает строку с логином или невидимым статусом.
* @param int $showInvisibility отображать логин даже если персонаж невидимка.
* @return string
*/
public function short($showInvisibility = 0):string
{
if (!$showInvisibility && $this->getInvisibilityStatus()) {
return INVIS;
} else {
return htmlspecialchars($this->login);
}
}
/**
* Возвращает строку со склонностью, кланом, логином, уровнем, ссылкой на профиль, здоровьем.
* @return string
*/
public function battle():string
{
return $this->getAlign().$this->getClan().sprintf('<b>%s</b> [%s] <a href="inf.php?%s" target="_blank"><img src="i/inf.gif" style="width:12px;height:11px"></a> <img src="i/herz.gif" alt="HP"> _hp_/_maxhp_', $this->login, $this->level, $this->login);
}
/**
* Возвращает строку с логином и здоровьем, выделяя строку определённым стилем.
* @param $textstyle - Название стиля отображения логина персонажа (main.css) для цветового разделения команд.
*
* @return string
*/
public function battleShort($textstyle):string
{
if ($this->getInvisibilityStatus()) {
return INVIS;
}
else {
return sprintf('<span style="%s">%s</span> [_hp_/_maxhp_]', $textstyle, $this->login);
}
}
}