2019-12-23 18:04:05 +00:00
|
|
|
<?php
|
2020-09-16 06:29:43 +00:00
|
|
|
// Магия восстагновления здоровья
|
2020-10-28 20:21:08 +00:00
|
|
|
use Battles\User;
|
2020-10-30 00:33:02 +00:00
|
|
|
class Healing extends \Battles\Magic\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
|
|
|
/**
|
|
|
|
* Магия лечения.
|
|
|
|
* @param $target - кого лечим.
|
|
|
|
* @param $power - на сколько лечим.
|
|
|
|
* @param null $isPercentage - если включён, считает $power в процентах, иначе, по-умочанию просто как число.
|
|
|
|
*/
|
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;
|
2020-08-30 19:32:08 +00:00
|
|
|
if ($target && $this->isUsable()) {
|
2020-09-16 06:29:43 +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;
|
|
|
|
}
|
|
|
|
db::c()->query('UPDATE users SET health = ?i WHERE id = ?i', $healHealthAmount, $this->target->id);
|
|
|
|
$targetName = $this->target->login;
|
|
|
|
return "Вы восстановили ${healHealthAmount} здоровья персонажу ${targetName}.";
|
2019-12-23 18:04:05 +00:00
|
|
|
} else {
|
2020-08-30 19:32:08 +00:00
|
|
|
return $this->status;
|
2019-12-23 18:04:05 +00:00
|
|
|
}
|
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
|
|
|
|
*/
|
2020-08-30 19:32:08 +00:00
|
|
|
private function isUsable()
|
|
|
|
{
|
|
|
|
$caster = new User($_SESSION['uid']);
|
2020-09-16 06:29:43 +00:00
|
|
|
if ($this->target == $_SESSION['uid']) {
|
|
|
|
$this->target = $caster;
|
2020-08-30 19:32:08 +00:00
|
|
|
} else {
|
2020-09-16 06:29:43 +00:00
|
|
|
$this->target = new User($this->target);
|
2020-08-30 19:32:08 +00:00
|
|
|
}
|
2020-09-16 06:29:43 +00:00
|
|
|
return ($this->isVisible($caster, $this->target) && $this->isNotDead($caster) && $this->enoughMana($caster));
|
2019-12-23 18:04:05 +00:00
|
|
|
}
|
|
|
|
}
|