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 ;
use Battles\UserEffects ;
use Battles\User ;
2021-01-25 17:58:58 +00:00
use db ;
use Krugozor\Database\Mysql\Exception ;
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 ;
use UserEffects ;
/**
* Магия лечения травм . Если у персонажа несколько травм , лечится самая тяжёлая .
* @ param $target - кого лечим .
* @ param $injuryType - тип травмы , которую лечим . 11 лёгкая , 12 средняя , 13 тяжёлая , 14 неизлечимая .
2021-01-25 17:58:58 +00:00
* @ throws Exception
2020-09-16 15:15:37 +00:00
*/
public function __construct ( $target , $injuryType )
{
2020-09-16 15:38:18 +00:00
$this -> target = $target ;
2020-09-16 15:15:37 +00:00
if ( $target && $this -> isUsable ()) {
2021-01-25 17:58:58 +00:00
$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' , $target ) -> fetch_object ();
2020-09-16 15:38:18 +00:00
$targetName = $this -> target -> login ;
if ( in_array ( $injury -> effect_id , [ 11 , 12 , 13 , 14 ]) && $injuryType >= $injury -> type ) {
2021-01-25 17:58:58 +00:00
db :: c () -> query ( 'DELETE FROM users_effects WHERE effect_id = ?i' , $injury -> effect_id );
2020-09-16 15:15:37 +00:00
if ( empty ( $injury -> name ) || $injury -> name == 'Неизвестный эффект' ) {
$injuryName = self :: $effectName [ $injury -> type ];
} else {
$injuryName = $injury -> name ;
}
return " Вы вылечили повреждение ${ injuryName } персонажу ${ targetName } . " ;
2020-09-16 15:38:18 +00:00
} elseif ( $injury -> effect_id && $injuryType == 15 ) {
2021-01-25 17:58:58 +00:00
db :: c () -> query ( 'DELETE FROM users_effects WHERE type IN (11,12,13,14) AND owner_id = ?i' , $target );
2020-09-16 15:38:18 +00:00
return " Вы вылечили все повреждения персонажу ${ targetName } . " ;
2020-09-16 15:15:37 +00:00
} 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 ));
}
}