2019-12-23 18:04:05 +00:00
|
|
|
<?php
|
2021-01-25 20:02:11 +00:00
|
|
|
// Магия восстановления здоровья
|
2021-01-25 18:09:34 +00:00
|
|
|
use Battles\Magic\Magic;
|
2020-10-28 20:21:08 +00:00
|
|
|
use Battles\User;
|
2022-01-26 23:15:33 +00:00
|
|
|
use Battles\Database\Db;
|
2021-01-28 21:05:34 +00:00
|
|
|
|
2021-01-25 18:09:34 +00:00
|
|
|
class Healing extends Magic
|
2020-08-30 19:32:08 +00:00
|
|
|
{
|
2020-09-16 15:13:25 +00:00
|
|
|
private $target;
|
2020-08-30 19:32:08 +00:00
|
|
|
private $magicPower;
|
|
|
|
|
2020-08-30 21:40:58 +00:00
|
|
|
/**
|
|
|
|
* Магия лечения.
|
2021-01-28 21:05:34 +00:00
|
|
|
* @param $target - кого лечим.
|
|
|
|
* @param $power - на сколько лечим.
|
2021-01-25 20:02:11 +00:00
|
|
|
* @param null $isPercentage - если включён, считает $power в процентах, иначе, по-умолчанию просто как число.
|
2020-08-30 21:40:58 +00:00
|
|
|
*/
|
2020-08-30 19:32:08 +00:00
|
|
|
public function __construct($target, $power, $isPercentage = null)
|
|
|
|
{
|
|
|
|
$this->magicPower = $power;
|
2020-09-16 15:38:18 +00:00
|
|
|
$this->target = $target;
|
2021-01-28 21:05:34 +00:00
|
|
|
if (!$this->isUsable()) {
|
2020-08-30 19:32:08 +00:00
|
|
|
return $this->status;
|
2019-12-23 18:04:05 +00:00
|
|
|
}
|
2021-01-28 21:05:34 +00:00
|
|
|
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;
|
|
|
|
}
|
2022-01-26 23:15:33 +00:00
|
|
|
Db::getInstance()->execute('UPDATE users SET health = ? WHERE id = ?', [$healHealthAmount, $this->target->id]);
|
2021-01-28 21:05:34 +00:00
|
|
|
$targetName = $this->target->login;
|
|
|
|
return "Вы восстановили ${healHealthAmount} здоровья персонажу ${targetName}.";
|
2020-08-30 19:32:08 +00:00
|
|
|
}
|
2019-12-23 18:04:05 +00:00
|
|
|
|
2020-08-30 21:40:58 +00:00
|
|
|
/**
|
|
|
|
* Проверки на успех.
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-01-28 21:05:34 +00:00
|
|
|
private function isUsable(): bool
|
2020-08-30 19:32:08 +00:00
|
|
|
{
|
2022-01-26 23:15:33 +00:00
|
|
|
$this->target = $this->target == $_SESSION['uid'] ? User::getInstance() : User::getInstance($this->target);
|
|
|
|
return $this->isVisible(User::getInstance(), $this->target) && $this->isNotDead(User::getInstance()) && $this->enoughMana(User::getInstance()) && $this->isSuccess(User::getInstance());
|
2019-12-23 18:04:05 +00:00
|
|
|
}
|
|
|
|
}
|