@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// Магия восстановления здоровья
|
||||
use Battles\Magic\Magic;
|
||||
use Battles\User;
|
||||
use Krugozor\Database\Mysql\Exception;
|
||||
class Healing extends Magic
|
||||
{
|
||||
private $target;
|
||||
private $magicPower;
|
||||
|
||||
/**
|
||||
* Магия лечения.
|
||||
* @param $target - кого лечим.
|
||||
* @param $power - на сколько лечим.
|
||||
* @param null $isPercentage - если включён, считает $power в процентах, иначе, по-умолчанию просто как число.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($target, $power, $isPercentage = null)
|
||||
{
|
||||
$this->magicPower = $power;
|
||||
$this->target = $target;
|
||||
if ($target && $this->isUsable()) {
|
||||
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}.";
|
||||
} else {
|
||||
return $this->status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверки на успех.
|
||||
* @return bool
|
||||
*/
|
||||
private function isUsable():bool
|
||||
{
|
||||
$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->skillCheck($caster);
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class Sharpen extends Magic
|
||||
$newMaxPhysicalDamage = $item['add_max_physical_damage'] + $sharpenStrength;
|
||||
$newItemName = $item['name'] . " [+$sharpenStrength]";
|
||||
|
||||
db::c()->query('UPDATE battles.inventory WHERE item_id = ?i SET name = "?s", add_min_physical_damage = "?s", add_max_physical_damage = "?s"', $item['item_id'], $newItemName, $newMinPhysicalDamage, $newMaxPhysicalDamage);
|
||||
db::c()->query('UPDATE battles.inventory SET name = "?s", add_min_physical_damage = "?s", add_max_physical_damage = "?s" WHERE item_id = ?i ', $newItemName, $newMinPhysicalDamage, $newMaxPhysicalDamage, $item['item_id']);
|
||||
return "У вас получилось изготовить предмет $newItemName!";
|
||||
} else {
|
||||
return $this->status;
|
||||
|
||||
Reference in New Issue
Block a user