battles/classes/Battles/Magic/CureInjury.php

61 lines
2.4 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)
// Магия лечения травм
namespace Battles\Magic;
use Battles\Database\Db, Battles\User, Battles\UserEffect;
class CureInjury extends Magic
{
private $target;
private $login;
//use UserEffects;
/**
* Магия лечения травм. Если у персонажа несколько травм, лечится самая тяжёлая.
* @param int $target - кого лечим.
* @param int $injuryType - тип травмы, которую лечим. 11 лёгкая, 12 средняя, 13 тяжёлая, 14 неизлечимая, 15 все травмы.
*/
public function __construct(int $target, int $injuryType)
{
$db = Db::getInstance();
$this->target = $target;
if (!$this->isUsable()) {
return $this->status;
}
$ok = null;
$injury = $db->ofetch('SELECT effect_id, type, name FROM users_effects WHERE type IN (11,12,13,14) AND owner_id = ? ORDER BY type DESC LIMIT 1', $target);
if (in_array($injury->type, [11, 12, 13, 14]) && $injuryType >= $injury->type && UserEffect::remove($target, $injury->effect_id)) {
if (empty($injury->name) || $injury->name === 'Неизвестный эффект') {
$injuryName = UserEffect::$effectName[$injury->type];
} else {
$injuryName = $injury->name;
}
$ok = "Вы вылечили повреждение ${injuryName} персонажу $this->login.";
} elseif ($injury->effect_id && $injuryType === 15 && UserEffect::massRemove($target, [11,12,13,14])) {
$ok = "Вы вылечили все повреждения персонажу $this->login.";
}
return $ok;
}
/**
* Проверки на успех.
* @return bool
*/
private function isUsable(): bool
{
$this->target = $this->target == $_SESSION['uid'] ? User::getInstance() : User::getInstance($this->target);
$this->login = $this->target->getLogin();
return (
$this->isVisible(User::getInstance(), $this->target) &&
$this->isNotDead(User::getInstance()) &&
$this->enoughMana(User::getInstance()) &&
$this->isNotInBattle(User::getInstance())
);
}
public static function cast($target, $type): self
{
return new self($target, $type);
}
}