2020-09-16 15:15:37 +00:00
< ? php
# Date: 16.09.2020 (08:23)
// Магия лечения травм
2020-10-28 20:21:08 +00:00
namespace Battles\Magic ;
2021-01-28 21:05:34 +00:00
2022-08-09 19:57:43 +00:00
use Battles\Database\Db , Battles\User , Battles\UserEffect ;
2020-09-16 15:15:37 +00:00
2021-01-25 17:58:58 +00:00
class CureInjury extends Magic
2020-09-16 15:15:37 +00:00
{
private $target ;
2021-01-28 21:05:34 +00:00
private $login ;
2022-08-09 19:57:43 +00:00
//use UserEffects;
2020-09-16 15:15:37 +00:00
/**
* Магия лечения травм . Если у персонажа несколько травм , лечится самая тяжёлая .
2021-01-28 21:05:34 +00:00
* @ param int $target - кого лечим .
* @ param int $injuryType - тип травмы , которую лечим . 11 лёгкая , 12 средняя , 13 тяжёлая , 14 неизлечимая , 15 все травмы .
2020-09-16 15:15:37 +00:00
*/
2021-01-28 21:05:34 +00:00
public function __construct ( int $target , int $injuryType )
2020-09-16 15:15:37 +00:00
{
2022-01-26 23:15:33 +00:00
$db = Db :: getInstance ();
2020-09-16 15:38:18 +00:00
$this -> target = $target ;
2021-01-28 21:05:34 +00:00
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 );
2022-08-09 19:57:43 +00:00
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 ];
2020-09-16 15:15:37 +00:00
} else {
2021-01-28 21:05:34 +00:00
$injuryName = $injury -> name ;
2020-09-16 15:15:37 +00:00
}
2021-01-28 21:05:34 +00:00
$ok = " Вы вылечили повреждение ${ injuryName } персонажу $this->login . " ;
2022-08-09 19:57:43 +00:00
} elseif ( $injury -> effect_id && $injuryType === 15 && UserEffect :: massRemove ( $target , [ 11 , 12 , 13 , 14 ])) {
2021-01-28 21:05:34 +00:00
$ok = " Вы вылечили все повреждения персонажу $this->login . " ;
2020-09-16 15:15:37 +00:00
}
2021-01-28 21:05:34 +00:00
return $ok ;
2020-09-16 15:15:37 +00:00
}
/**
* Проверки на успех .
* @ return bool
*/
2021-01-28 21:05:34 +00:00
private function isUsable () : bool
2020-09-16 15:15:37 +00:00
{
2022-01-26 23:15:33 +00:00
$this -> target = $this -> target == $_SESSION [ 'uid' ] ? User :: getInstance () : User :: getInstance ( $this -> target );
2021-05-12 19:04:33 +00:00
$this -> login = $this -> target -> getLogin ();
2022-01-26 23:15:33 +00:00
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 );
2020-09-16 15:15:37 +00:00
}
}