Объединение функций отображения и редактирования статов в глобальные.
This commit is contained in:
parent
713f426328
commit
83b78abab2
150
classes/User.php
150
classes/User.php
@ -112,15 +112,34 @@ class User
|
||||
private function UserInfoStats($isMainWindow = 0)
|
||||
{
|
||||
$captions = 'Уровень:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Местонахождение:';
|
||||
$variables = $this->level . '<br>' . $this->getStrength() . '<br>' . $this->getDexterity() . '<br>' . $this->getIntuition() . '<br>' . $this->getEndurance() . '<br>' . $this->getIntelligence() . '<br>' . $this->getWisdom() . '<br>' . $this->getRoomName($this->room);
|
||||
$variables =
|
||||
$this->level . '<br>' .
|
||||
$this->getStat('strength') . '<br>' .
|
||||
$this->getStat('dexterity') . '<br>' .
|
||||
$this->getStat('intuition') . '<br>' .
|
||||
$this->getStat('endurance') . '<br>' .
|
||||
$this->getStat('intelligence') . '<br>' .
|
||||
$this->getStat('wisdom') . '<br>' .
|
||||
$this->getRoomName($this->room);
|
||||
if ($isMainWindow) {
|
||||
$this->Bank = new Bank($this->id);
|
||||
$captions = 'Уровень:<br>Здоровье:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Опыт:<br>Очки характеристик:<br>Деньги:<br>Деньги в банке:';
|
||||
$variables = $this->level . '<br>' . $this->health . '<br>' . $this->getStrength(1) . '<br>' . $this->getDexterity(1) . '<br>' . $this->getIntuition(1) . '<br>' . $this->getEndurance(1) . '<br>' . $this->getIntelligence(1) . '<br>' . $this->getWisdom(1) . '<br>' . $this->experience . '<br>' . $this->free_stat_points . '<br>' . $this->money . '<br>' . $this->Bank->money;
|
||||
$variables =
|
||||
$this->level . '<br>' .
|
||||
$this->health . '<br>' .
|
||||
$this->getStat('strength', 1) . '<br>' .
|
||||
$this->getStat('dexterity', 1) . '<br>' .
|
||||
$this->getStat('intuition', 1) . '<br>' .
|
||||
$this->getStat('endurance', 1) . '<br>' .
|
||||
$this->getStat('intelligence', 1) . '<br>' .
|
||||
$this->getStat('wisdom', 1) . '<br>' .
|
||||
$this->experience . '<br>' .
|
||||
$this->free_stat_points . '<br>' .
|
||||
$this->money . '<br>' .
|
||||
$this->Bank->money;
|
||||
}
|
||||
|
||||
if ($this->align) {
|
||||
$nameString = sprintf('<img src="/i/align_%s.png" >', $this->align);
|
||||
$nameString = sprintf('<img src="/i/align_%s.png" alt="Склонность">', $this->align);
|
||||
}
|
||||
if ($this->block) {
|
||||
$nameString .= '<span class="private"><s>' . $this->login . '</s></span>';
|
||||
@ -128,7 +147,7 @@ class User
|
||||
$nameString .= ' <b>' . $this->login . '</b> ';
|
||||
}
|
||||
if ($this->clan) {
|
||||
$nameString .= sprintf('<img src="/i/clan/%s.png" >', $this->clan);
|
||||
$nameString .= sprintf('<img src="/i/clan/%s.png" alt="Клан">', $this->clan);
|
||||
}
|
||||
echo '<div class="user-info">';
|
||||
echo '<div class="info">';
|
||||
@ -146,111 +165,32 @@ class User
|
||||
echo '</div><!-- user-info -->';
|
||||
}
|
||||
|
||||
public function getStrength($isMainWindow = 0)
|
||||
/**
|
||||
* Отдаёт информацию о базовом(!) стате.
|
||||
* @param $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'.
|
||||
* @param int $isMainWindow - переключатель "главного окна". Если включить, дополнительно будет показывать ссылку на повышение стата на 1, при условии наличия свободных очков статов.
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getStat($stat_name, $isMainWindow = 0)
|
||||
{
|
||||
if ($this->free_stat_points && $isMainWindow && $this->strength < self::STAT_MAXIMUM_AMOUNT) {
|
||||
//main.php?edit=1&ups=sila
|
||||
return sprintf('%s <a href="#">[+]</a>', $this->strength);
|
||||
}
|
||||
return $this->strength;
|
||||
}
|
||||
|
||||
public function getDexterity($isMainWindow = 0)
|
||||
{
|
||||
if ($this->free_stat_points && $isMainWindow && $this->dexterity < self::STAT_MAXIMUM_AMOUNT) {
|
||||
//main.php?edit=1&ups=lovk
|
||||
return sprintf('%s <a href="#">[+]</a>', $this->dexterity);
|
||||
}
|
||||
return $this->dexterity;
|
||||
}
|
||||
|
||||
public function getIntuition($isMainWindow = 0)
|
||||
{
|
||||
if ($this->free_stat_points && $isMainWindow && $this->intuition < self::STAT_MAXIMUM_AMOUNT) {
|
||||
//main.php?edit=1&ups=inta...
|
||||
return sprintf('%s <a href="#">[+]</a>', $this->intuition);
|
||||
}
|
||||
return $this->intuition;
|
||||
}
|
||||
|
||||
public function getEndurance($isMainWindow = 0)
|
||||
{
|
||||
if ($this->free_stat_points && $isMainWindow && $this->endurance < self::STAT_MAXIMUM_AMOUNT) {
|
||||
return sprintf('%s <a href="#">[+]</a>', $this->endurance);
|
||||
}
|
||||
return $this->endurance;
|
||||
}
|
||||
|
||||
public function getIntelligence($isMainWindow = 0)
|
||||
{
|
||||
if ($this->free_stat_points && $isMainWindow && $this->intelligence < self::STAT_MAXIMUM_AMOUNT) {
|
||||
return sprintf('%s <a href="#">[+]</a>', $this->intelligence);
|
||||
}
|
||||
return $this->intelligence;
|
||||
}
|
||||
|
||||
public function getWisdom($isMainWindow = 0)
|
||||
{
|
||||
if ($this->free_stat_points && $isMainWindow && $this->wisdom < self::STAT_MAXIMUM_AMOUNT) {
|
||||
return sprintf('%s <a href="#">[+]</a>', $this->wisdom);
|
||||
}
|
||||
return $this->wisdom;
|
||||
}
|
||||
|
||||
public function setStrength()
|
||||
{
|
||||
if ($this->strength <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
|
||||
db::c()->query('UPDATE users SET strength = strength + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
|
||||
$allowed = ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'];
|
||||
if (in_array($stat_name, $allowed)) {
|
||||
if ($this->free_stat_points && $isMainWindow && $this->$stat_name < self::STAT_MAXIMUM_AMOUNT) {
|
||||
return sprintf('%s <a href="/main.php?edit=%s&ups=%s">[+]</a>', $this->$stat_name, mt_rand(), $stat_name);
|
||||
} else {
|
||||
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
|
||||
return $this->$stat_name;
|
||||
}
|
||||
}
|
||||
|
||||
public function setDexterity()
|
||||
{
|
||||
if ($this->dexterity <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
|
||||
db::c()->query('UPDATE users SET dexterity = dexterity + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
|
||||
} else {
|
||||
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
|
||||
}
|
||||
}
|
||||
|
||||
public function setIntuition()
|
||||
{
|
||||
if ($this->intuition <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
|
||||
db::c()->query('UPDATE users SET intuition = intuition + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
|
||||
} else {
|
||||
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
|
||||
}
|
||||
}
|
||||
|
||||
public function setEndurance()
|
||||
{
|
||||
if ($this->endurance <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
|
||||
db::c()->query('UPDATE users SET endurance = endurance + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
|
||||
} else {
|
||||
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
|
||||
}
|
||||
}
|
||||
|
||||
public function setIntelligence()
|
||||
{
|
||||
if ($this->intelligence <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
|
||||
db::c()->query('UPDATE users SET intelligence = intelligence + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
|
||||
} else {
|
||||
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
|
||||
}
|
||||
}
|
||||
|
||||
public function setWisdom()
|
||||
{
|
||||
if ($this->wisdom <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
|
||||
db::c()->query('UPDATE users SET wisdom = wisdom + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
|
||||
} else {
|
||||
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
|
||||
throw new Exception(self::ERROR_STAT_UNKNOWN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Повышает один из выбранных статов на 1, но не выше self::STAT_MAXIMUM_AMOUNT при условии наличия свободных очков статов.
|
||||
* @param $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'.
|
||||
* @throws \Krugozor\Database\Mysql\Exception
|
||||
*/
|
||||
public function addOnePointToStat($stat_name)
|
||||
{
|
||||
$allowed = ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'];
|
||||
@ -400,12 +340,12 @@ class User
|
||||
|
||||
public function getHealth(): string
|
||||
{
|
||||
return $this->health.'/'.$this->maxHealth;
|
||||
return $this->health . '/' . $this->maxHealth;
|
||||
}
|
||||
|
||||
public function getMana(): string
|
||||
{
|
||||
return $this->mana.'/'.$this->maxMana;
|
||||
return $this->mana . '/' . $this->maxMana;
|
||||
}
|
||||
|
||||
public function setRoom()
|
||||
|
Loading…
Reference in New Issue
Block a user