Основные классы переехали на обёртку PDO. Плановое №16.

This commit is contained in:
lopar
2021-01-28 23:05:34 +02:00
parent 0099c235a7
commit 8402912098
22 changed files with 284 additions and 1940 deletions
+18 -20
View File
@@ -2,7 +2,8 @@
// Магия восстановления здоровья
use Battles\Magic\Magic;
use Battles\User;
use Krugozor\Database\Mysql\Exception;
use Battles\Database\DBPDO;
class Healing extends Magic
{
private $target;
@@ -10,38 +11,35 @@ class Healing extends Magic
/**
* Магия лечения.
* @param $target - кого лечим.
* @param $power - на сколько лечим.
* @param $target - кого лечим.
* @param $power - на сколько лечим.
* @param null $isPercentage - если включён, считает $power в процентах, иначе, по-умолчанию просто как число.
*
* @throws Exception
*/
public function __construct($target, $power, $isPercentage = null)
{
$this->magicPower = $power;
$this->target = $target;
if ($target && $this->isUsable()) {
if ($isPercentage) {
$healHealthAmount = $this->target->health + $this->target->maxHealth / 100 * $this->magicPower;
} else {
$healHealthAmount = $this->target->health + $this->magicPower;
}
if ($healHealthAmount > $this->target->maxHealth) {
$healHealthAmount = $this->target->maxHealth;
}
db::c()->query('UPDATE users SET health = ?i WHERE id = ?i', $healHealthAmount, $this->target->id);
$targetName = $this->target->login;
return "Вы восстановили ${healHealthAmount} здоровья персонажу ${targetName}.";
} else {
if (!$this->isUsable()) {
return $this->status;
}
if ($isPercentage) {
$healHealthAmount = $this->target->health + $this->target->maxHealth / 100 * $this->magicPower;
} else {
$healHealthAmount = $this->target->health + $this->magicPower;
}
if ($healHealthAmount > $this->target->maxHealth) {
$healHealthAmount = $this->target->maxHealth;
}
DBPDO::INIT()->execute('UPDATE users SET health = ? WHERE id = ?', [$healHealthAmount, $this->target->id]);
$targetName = $this->target->login;
return "Вы восстановили ${healHealthAmount} здоровья персонажу ${targetName}.";
}
/**
* Проверки на успех.
* @return bool
*/
private function isUsable():bool
private function isUsable(): bool
{
$caster = new User($_SESSION['uid']);
if ($this->target == $_SESSION['uid']) {
@@ -49,6 +47,6 @@ class Healing extends Magic
} else {
$this->target = new User($this->target);
}
return $this->isVisible($caster, $this->target) && $this->isNotDead($caster) && $this->enoughMana($caster) && $this->skillCheck($caster);
return $this->isVisible($caster, $this->target) && $this->isNotDead($caster) && $this->enoughMana($caster) && $this->isSuccess($caster);
}
}