battles/magic/CureInjury.php

51 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
# Date: 16.09.2020 (08:23)
// Магия лечения травм
class CureInjury extends Magic
{
private $target;
use UserEffects;
/**
* Магия лечения травм. Если у персонажа несколько травм, лечится самая тяжёлая.
* @param $target - кого лечим.
* @param $injuryType - тип травмы, которую лечим. 11 лёгкая, 12 средняя, 13 тяжёлая, 14 неизлечимая.
* @throws \Krugozor\Database\Mysql\Exception
*/
public function __construct($target, $injuryType)
{
if ($target && $this->isUsable()) {
$injury = db::c()->query('SELECT effect_id, type, name FROM users_effects WHERE type IN (11,12,13,14) AND owner_id = ?i ORDER BY type DESC LIMIT 1', $this->target->id)->fetch_object();
if (in_array($injury->effect_id, [11,12,13,14]) && $injuryType >= $injury->type) {
db::c()->query('DELETE FROM users_effects WHERE effect_id = ?i', $injury->effect_id);
$targetName = $this->target->login;
if (empty($injury->name) || $injury->name == 'Неизвестный эффект') {
$injuryName = self::$effectName[$injury->type];
} else {
$injuryName = $injury->name;
}
return "Вы вылечили повреждение ${injuryName} персонажу ${targetName}.";
} else {
return false;
}
} else {
return $this->status;
}
}
/**
* Проверки на успех.
* @return bool
*/
private function isUsable()
{
$caster = new User($_SESSION['uid']);
if ($this->target == $_SESSION['uid']) {
$this->target = $caster;
} else {
$this->target = new User($this->target);
}
return ($this->isVisible($caster, $this->target) && $this->isNotDead($caster) && $this->enoughMana($caster) && $this->isNotInBattle($caster));
}
}