Code smell.

This commit is contained in:
Ivor Barhansky
2022-12-17 01:20:43 +02:00
parent b1f578f4b0
commit 0398425205
45 changed files with 875 additions and 851 deletions
+18 -24
View File
@@ -19,7 +19,7 @@ class UserStats extends User
protected int $wisdom;
protected int $health;
protected int $mana;
protected int $free_stat_points = 0;
protected int $freeStatPoints = 0;
protected int $level;
private const STAT_MAXIMUM_AMOUNT = 40;
private const ERROR_STAT_IS_MAXIMUM = 'Ошибка: Параметр достиг своего лимита!';
@@ -54,7 +54,7 @@ class UserStats extends User
$this->wisdom = $data->wisdom;
$this->health = $data->health;
$this->mana = $data->mana;
$this->free_stat_points = $data->free_stat_points;
$this->freeStatPoints = $data->free_stat_points;
$this->level = $data->level;
parent::__construct($user);
$this->maxHealth = round(($this->endurance * 3) + ($this->endurance / 2) * ($this->level - 1) + ($this->endurance / 5) * (($this->level - 1) * ($this->level - 2) / 2));
@@ -64,7 +64,7 @@ class UserStats extends User
/**
* Отдаёт информацию о базовом(!) стате.
*
* @param string $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition',
* @param string $statName - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition',
* 'endurance', 'intelligence', 'wisdom'.
* @param int $isMainWindow - переключатель "главного окна". Если включить, дополнительно будет показывать ссылку
* на повышение стата на 1, при условии наличия свободных очков статов.
@@ -72,15 +72,15 @@ class UserStats extends User
* @return string
* @throws GameException
*/
public function getStat(string $stat_name, int $isMainWindow = 0): string
public function getStat(string $statName, int $isMainWindow = 0): string
{
if (!in_array($stat_name, self::STAT_NAMES_ARRAY)) {
if (!in_array($statName, self::STAT_NAMES_ARRAY)) {
throw new GameException(self::ERROR_STAT_UNKNOWN);
}
$stat = strval($this->$stat_name);
if ($this->free_stat_points && $isMainWindow && $this->$stat_name < self::STAT_MAXIMUM_AMOUNT) {
$stat = strval($this->$statName);
if ($this->freeStatPoints && $isMainWindow && $this->$statName < self::STAT_MAXIMUM_AMOUNT) {
$rand = strval(mt_rand());
$stat .= " <a href='/main.php?edit=$rand&ups=$stat_name'>[+]</a>";
$stat .= " <a href='/main.php?edit=$rand&ups=$statName'>[+]</a>";
}
return $stat;
}
@@ -89,20 +89,20 @@ class UserStats extends User
* Повышает один из выбранных статов на 1, но не выше self::STAT_MAXIMUM_AMOUNT при условии наличия свободных очков
* статов.
*
* @param string $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition',
* @param string $statName - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition',
* 'endurance', 'intelligence', 'wisdom'.
*
* @throws GameException
*/
public function addOnePointToStat(string $stat_name)
public function addOnePointToStat(string $statName)
{
if (!in_array($stat_name, self::STAT_NAMES_ARRAY)) {
if (!in_array($statName, self::STAT_NAMES_ARRAY)) {
throw new GameException(self::ERROR_STAT_UNKNOWN);
}
if ($this->free_stat_points <= 0 || $this->$stat_name >= self::STAT_MAXIMUM_AMOUNT) {
if ($this->freeStatPoints <= 0 || $this->$statName >= self::STAT_MAXIMUM_AMOUNT) {
throw new GameException(self::ERROR_STAT_IS_MAXIMUM);
} else {
Stats::addOne($stat_name, $this->id);
Stats::addOne($statName, $this->id);
}
}
@@ -132,7 +132,7 @@ class UserStats extends User
*/
public function getFreeStatPoints()
{
return $this->free_stat_points;
return $this->freeStatPoints;
}
/**
@@ -160,12 +160,6 @@ class UserStats extends User
foreach (self::STAT_NAMES_ARRAY as $stat) {
$obj->$stat = max(0, $stats->$stat + $itemBonuses->{'item_' . $stat} + $effectBonuses->{'effect_' . $stat});
}
//$obj->strength = max(0, $stats->strength + $itemBonuses->item_strength + $effectBonuses->effect_strength);
//$obj->dexterity = max(0, $stats->dexterity + $itemBonuses->item_dexterity + $effectBonuses->effect_dexterity);
//$obj->intuition = max(0, $stats->intuition + $itemBonuses->item_intuition + $effectBonuses->effect_intuition);
//$obj->endurance = max(0, $stats->endurance + $itemBonuses->item_endurance + $effectBonuses->effect_endurance);
//$obj->intelligence = max(0, $stats->intelligence + $itemBonuses->item_intelligence + $effectBonuses->effect_intelligence);
//$obj->wisdom = max(0, $stats->wisdom + $itemBonuses->item_wisdom + $effectBonuses->effect_wisdom);
$obj->accuracy = max(0, $itemBonuses->item_accuracy);
$obj->evasion = max(0, $itemBonuses->item_evasion);
$obj->criticals = max(0, $itemBonuses->item_criticals);
@@ -177,9 +171,9 @@ class UserStats extends User
public function levelUp(): string
{
$this->level += 1;
$this->free_stat_points += 2;
$this->freeStatPoints += 2;
$this->save();
Chat::addSYSMessage('Внимание, вы получили ' . $this->level . 'уровень. Доступны очки распределения параметров.');
Chat::sendSys('Внимание, вы получили ' . $this->level . 'уровень. Доступны очки распределения параметров.');
return 'Персонаж перешёл на ' . $this->level . 'уровень.';
}
@@ -197,9 +191,9 @@ class UserStats extends User
$this->wisdom,
$this->health,
$this->mana,
$this->free_stat_points,
$this->freeStatPoints,
$this->level,
$this->id //where
]);
}
}
}