diff --git a/classes/User.php b/classes/User.php
index b82e2ec..c5a3ff8 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -112,15 +112,34 @@ class User
private function UserInfoStats($isMainWindow = 0)
{
$captions = 'Уровень:
Сила:
Ловкость:
Интуиция:
Выносливость:
Интеллект:
Мудрость:
Местонахождение:';
- $variables = $this->level . '
' . $this->getStrength() . '
' . $this->getDexterity() . '
' . $this->getIntuition() . '
' . $this->getEndurance() . '
' . $this->getIntelligence() . '
' . $this->getWisdom() . '
' . $this->getRoomName($this->room);
+ $variables =
+ $this->level . '
' .
+ $this->getStat('strength') . '
' .
+ $this->getStat('dexterity') . '
' .
+ $this->getStat('intuition') . '
' .
+ $this->getStat('endurance') . '
' .
+ $this->getStat('intelligence') . '
' .
+ $this->getStat('wisdom') . '
' .
+ $this->getRoomName($this->room);
if ($isMainWindow) {
$this->Bank = new Bank($this->id);
$captions = 'Уровень:
Здоровье:
Сила:
Ловкость:
Интуиция:
Выносливость:
Интеллект:
Мудрость:
Опыт:
Очки характеристик:
Деньги:
Деньги в банке:';
- $variables = $this->level . '
' . $this->health . '
' . $this->getStrength(1) . '
' . $this->getDexterity(1) . '
' . $this->getIntuition(1) . '
' . $this->getEndurance(1) . '
' . $this->getIntelligence(1) . '
' . $this->getWisdom(1) . '
' . $this->experience . '
' . $this->free_stat_points . '
' . $this->money . '
' . $this->Bank->money;
+ $variables =
+ $this->level . '
' .
+ $this->health . '
' .
+ $this->getStat('strength', 1) . '
' .
+ $this->getStat('dexterity', 1) . '
' .
+ $this->getStat('intuition', 1) . '
' .
+ $this->getStat('endurance', 1) . '
' .
+ $this->getStat('intelligence', 1) . '
' .
+ $this->getStat('wisdom', 1) . '
' .
+ $this->experience . '
' .
+ $this->free_stat_points . '
' .
+ $this->money . '
' .
+ $this->Bank->money;
}
-
if ($this->align) {
- $nameString = sprintf('', $this->align);
+ $nameString = sprintf('', $this->align);
}
if ($this->block) {
$nameString .= '' . $this->login . '';
@@ -128,7 +147,7 @@ class User
$nameString .= ' ' . $this->login . ' ';
}
if ($this->clan) {
- $nameString .= sprintf('', $this->clan);
+ $nameString .= sprintf('', $this->clan);
}
echo '
';
echo '
';
@@ -146,111 +165,32 @@ class User
echo '
';
}
- 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
[+]', $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
[+]', $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
[+]', $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
[+]', $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
[+]', $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
[+]', $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
[+]', $this->$stat_name, mt_rand(), $stat_name);
+ } else {
+ return $this->$stat_name;
+ }
} else {
- throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
- }
- }
-
- 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,16 +340,16 @@ 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()
{
-
+
}
}
\ No newline at end of file