Часть логов теперь пишется в SQLITE, а не в текстовые файлы (#33). Проинициализирован класс Nick в свитках.

This commit is contained in:
Igor Barkov (iwork)
2021-08-26 17:44:14 +03:00
parent 6fa217b93b
commit 5e264f837a
65 changed files with 438 additions and 233 deletions

View File

@@ -3,6 +3,7 @@
namespace Battles;
use Battles\Database\DBPDO;
use Exceptions\GameException;
class UserStats extends User
@@ -22,16 +23,16 @@ class UserStats extends User
//// Неизменяемые для игрока(!) переменные.
// Удар кулаком всегда 1-2.
protected $minDamage = 1;
protected $maxDamage = 2;
protected int $minDamage = 1;
protected int $maxDamage = 2;
// Природная броня всегда 0.
// Зачем их три, если во всех формулах она одна?
protected $headArmor = 0;
protected $chestArmor = 0;
protected $legArmor = 0;
protected int $headArmor = 0;
protected int $chestArmor = 0;
protected int $legArmor = 0;
// Динамически рассчитываемые
protected $maxHealth;
protected $maxMana;
protected int $maxHealth;
protected int $maxMana;
/**
* UserStats constructor.
@@ -48,7 +49,7 @@ class UserStats extends User
/**
* Отдаёт информацию о базовом(!) стате.
*
* @param $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition',
* @param $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition',
* 'endurance', 'intelligence', 'wisdom'.
* @param int $isMainWindow - переключатель "главного окна". Если включить, дополнительно будет показывать ссылку
* на повышение стата на 1, при условии наличия свободных очков статов.
@@ -220,4 +221,36 @@ class UserStats extends User
return self::$db->ofetch($query);
}
public function levelUp(): string
{
$this->level += 1;
$this->free_stat_points += 2;
$this->saveStats();
Chat::addSYSMessage('Внимание, вы получили ' . $this->level . 'уровень. Доступны очки распределения параметров.');
return 'Персонаж перешёл на ' . $this->level . 'уровень.';
}
/** Сохраняет в базу актуальные статы, здоровье, ману, свободные очки статов и уровень.
*
*/
private function saveStats()
{
$query = 'update users set strength = ?, dexterity = ?, intuition = ?, endurance = ?,
intelligence = ?, wisdom = ?, health = ?, mana = ?, free_stat_points = ?,
level = ? where id = ?';
$vals = [
$this->strength, //set
$this->dexterity,
$this->intuition,
$this->endurance,
$this->intelligence,
$this->wisdom,
$this->health,
$this->mana,
$this->free_stat_points,
$this->level,
$this->id //where
];
DBPDO::$db->execute($query, $vals);
}
}