2019-12-23 18:04:05 +00:00
|
|
|
|
<?php
|
|
|
|
|
// Магия исцеления
|
|
|
|
|
// Все их соберём, вместе соберём...
|
|
|
|
|
|
2020-08-30 19:32:08 +00:00
|
|
|
|
class Healing
|
|
|
|
|
{
|
|
|
|
|
private $target;
|
|
|
|
|
private $magicPower;
|
|
|
|
|
private $status = null;
|
|
|
|
|
|
|
|
|
|
public function __construct($target, $power, $isPercentage = null)
|
|
|
|
|
{
|
|
|
|
|
$this->magicPower = $power;
|
|
|
|
|
if ($target && $this->isUsable()) {
|
|
|
|
|
//TODO: Проверка на то, что магу хватает навыка владения школой магии.
|
|
|
|
|
//IDEA: Можно добавить проверку на интеллект, где при определённом интеллекте шанс на успех становится 95-100%.
|
|
|
|
|
return $this->useSpell($isPercentage);
|
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 19:32:08 +00:00
|
|
|
|
private function isUsable()
|
|
|
|
|
{
|
|
|
|
|
$caster = new User($_SESSION['uid']);
|
|
|
|
|
$this->target = new User($this->target);
|
|
|
|
|
if ($caster->battle != $this->target->battle || $caster->room != $this->target->room) {
|
|
|
|
|
$this->status = 'Вы не видите цель!';
|
|
|
|
|
} elseif ($caster->health < 1) {
|
|
|
|
|
$this->status = 'Вы мертвы!';
|
|
|
|
|
} elseif ($caster->mana < 1) {
|
|
|
|
|
$this->status = 'Недостаточно пыли!';
|
|
|
|
|
}
|
|
|
|
|
if ($this->status) {
|
|
|
|
|
return false;
|
2019-12-23 18:04:05 +00:00
|
|
|
|
}
|
2020-08-30 19:32:08 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-12-23 18:04:05 +00:00
|
|
|
|
|
2020-08-30 19:32:08 +00:00
|
|
|
|
private function useSpell($isPercentage)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|