battles/classes/Nick.php

106 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
/**
* Разные способы отображения строки с логином персонажа.
*/
class Nick extends User
{
private function getInvisibilityStatus()
{
return db::c()->query('SELECT 1 FROM users_effects WHERE type = 1022 AND owner_id = ?i', $this->id);
}
/**
* Отображение иконки склонности.
* @return string
*/
private function getAlign()
{
if (isset($this->align)) {
return sprintf('<img src="i/align_%s.gif">', $this->align);
} else {
return '';
}
}
/**
* Отображение иконки клана.
* @return string
*/
private function getClan()
{
if (isset($this->clan)) {
return sprintf('<img src="i/clan/%s.png">', $this->clan);
} else {
return '';
}
}
/**
* Берем ID и возвращаем его. Что-то для обратной совместимости, скорее всего.
* TODO: Отвязаться от функции и удалить.
* @param $playerId
*
* @return Nick
*/
public static function id($playerId)
{
return new self($playerId);
}
/**
* Возвращает строку со склонностью, кланом, логином, уровнем, ссылкой на профиль.
*
* @param int $showInvisibility - По умолчанию 0. Выбрать 1, если надо отображать невидимый статус.
*
* @return string
* @throws \Krugozor\Database\Mysql\Exception
*/
public function full($showInvisibility = 0)
{
if ($showInvisibility && $this->getInvisibilityStatus()) {
return '<i>невидимка</i>';
}
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>', $this->login, $this->level, $this->login);
}
/**
* Возвращает строку с логином или невидимым статусом.
* @return string
* @throws \Krugozor\Database\Mysql\Exception
*/
public function short()
{
if ($this->getInvisibilityStatus()) {
return '<i>невидимка</i>';
} else {
return htmlspecialchars($this->login);
}
}
/**
* Возвращает строку со склонностью, кланом, логином, уровнем, ссылкой на профиль, здоровьем.
* @return string
*/
public function battle()
{
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)
{
if ($this->getInvisibilityStatus()) {
return '<i>невидимка</i>';
}
else {
return sprintf('<span style="%s">%s</span> [_hp_/_maxhp_]', $textstyle, $this->login);
}
}
}