setters and default values
This commit is contained in:
parent
87bcfe5b30
commit
c5f8f958d6
100
classes/User.php
100
classes/User.php
@ -3,24 +3,24 @@
|
||||
class User
|
||||
{
|
||||
public $id;
|
||||
public $login;
|
||||
public $email;
|
||||
public $login = '<em>Некто</em>';
|
||||
public $email = '<em>неизвестно</em>';
|
||||
public $realname;
|
||||
public $borndate;
|
||||
public $info;
|
||||
public $level;
|
||||
public $align;
|
||||
public $clan;
|
||||
public $money;
|
||||
public $strength;
|
||||
public $dexterity;
|
||||
public $intuition;
|
||||
public $endurance;
|
||||
public $intelligence;
|
||||
public $wisdom;
|
||||
public $level = 0;
|
||||
public $align = 0;
|
||||
public $clan = 0;
|
||||
public $money = 0;
|
||||
public $strength = 0;
|
||||
public $dexterity = 0;
|
||||
public $intuition = 0;
|
||||
public $endurance = 0;
|
||||
public $intelligence = 0;
|
||||
public $wisdom = 0;
|
||||
public $ip;
|
||||
public $session_id;
|
||||
public $admin;
|
||||
public $admin = 0;
|
||||
public $enter_game;
|
||||
public $room;
|
||||
public $block;
|
||||
@ -33,6 +33,8 @@ class User
|
||||
public $chestArmor = 0;
|
||||
public $legArmor = 0;
|
||||
public const STAT_MAXIMUM_AMOUNT = 40;
|
||||
private const ERROR_STAT_IS_MAXIMUM = 'Ошибка: Параметр достиг своего лимита!';
|
||||
private const ERROR_STAT_UNKNOWN = 'Ошибка: Неизвестный параметр!';
|
||||
// Пока несуществующие, для совместимости.
|
||||
public $married = 'Someone или нет.';
|
||||
public $experience = 200;
|
||||
@ -133,7 +135,7 @@ class User
|
||||
echo $variables;
|
||||
echo '</div><!-- column -->';
|
||||
echo '</div><!-- stats-container -->';
|
||||
echo '<div class="debug">TODO: Сделать рассчёт здоровья и модификаторов. Вывести полоску здоровья когда будет от чего отталкиваться.</div>';
|
||||
echo '<div class="debug">TODO: Сделать рассчёт модификаторов. Вывести полоску здоровья когда будет от чего отталкиваться.</div>';
|
||||
echo '</div><!-- user-info -->';
|
||||
}
|
||||
|
||||
@ -188,6 +190,76 @@ class User
|
||||
return $this->wisdom;
|
||||
}
|
||||
|
||||
public function setStrength()
|
||||
{
|
||||
if ($this->strength <= self::STAT_MAXIMUM_AMOUNT && $this->stat_points > 0) {
|
||||
db::c()->query('UPDATE users SET strength = strength + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
|
||||
} else {
|
||||
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
|
||||
}
|
||||
}
|
||||
|
||||
public function setDexterity()
|
||||
{
|
||||
if ($this->dexterity <= self::STAT_MAXIMUM_AMOUNT && $this->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->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->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->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->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);
|
||||
}
|
||||
}
|
||||
|
||||
public function addOnePointToStat($stat_name)
|
||||
{
|
||||
$allowed = ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'];
|
||||
if (in_array($stat_name, $allowed)) {
|
||||
if ($this->stat_points > 0 && $this->$stat_name <= self::STAT_MAXIMUM_AMOUNT) {
|
||||
$query = 'UPDATE users SET ?f = ?f + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i';
|
||||
db::c()->query($query, $stat_name, $stat_name, $this->id);
|
||||
} else {
|
||||
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
|
||||
}
|
||||
} else {
|
||||
throw new Exception(self::ERROR_STAT_UNKNOWN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function UserInfo()
|
||||
{
|
||||
echo '<div class="user-info-container">';
|
||||
|
Loading…
Reference in New Issue
Block a user