2020-09-16 15:13:25 +00:00
|
|
|
<?php
|
|
|
|
# Date: 16.09.2020 (08:45)
|
2020-10-28 20:21:08 +00:00
|
|
|
namespace Battles\Magic;
|
2022-06-10 23:18:04 +00:00
|
|
|
|
|
|
|
use Battles\Database\Db;
|
|
|
|
|
2020-09-16 15:13:25 +00:00
|
|
|
class Magic
|
|
|
|
{
|
2022-06-10 23:18:04 +00:00
|
|
|
protected string $status;
|
|
|
|
private Db $db;
|
|
|
|
private object $magic;
|
|
|
|
|
|
|
|
public function __construct(Db $db, int $id)
|
|
|
|
{
|
|
|
|
$this->magic = $db->ofetch('select * from magic where id = ?', $id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMagic(): object
|
|
|
|
{
|
|
|
|
return $this->magic;
|
|
|
|
}
|
2020-09-16 15:13:25 +00:00
|
|
|
|
2022-06-10 23:18:04 +00:00
|
|
|
protected function isVisible($caster, $target): bool
|
2020-09-16 15:13:25 +00:00
|
|
|
{
|
|
|
|
if ($caster->battle != $target->battle || $caster->room != $target->room) {
|
|
|
|
$this->status = 'Вы не видите цель!';
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 23:18:04 +00:00
|
|
|
protected function isNotDead($caster): bool
|
2020-09-16 15:13:25 +00:00
|
|
|
{
|
|
|
|
if ($caster->health < 1) {
|
|
|
|
$this->status = 'Вы мертвы!';
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 23:18:04 +00:00
|
|
|
protected function enoughMana($caster): bool
|
2020-09-16 15:13:25 +00:00
|
|
|
{
|
|
|
|
if ($caster->mana < 1) {
|
|
|
|
$this->status = 'Недостаточно пыли!';
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 23:18:04 +00:00
|
|
|
protected function isNotInBattle($caster): bool
|
2020-09-16 15:13:25 +00:00
|
|
|
{
|
|
|
|
if ($caster->battle) {
|
|
|
|
$this->status = 'Невозможно применить в поединке!';
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2021-01-25 18:00:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Проверка на успех заклинания. Чем выше интеллект, тем выше шанс успеха.
|
|
|
|
* @param $caster - заклинатель (массив значений из базы).
|
|
|
|
* @param int $difficulty - сложность произнесения заклинания. Чем выше значение, тем сложнее проверка. 40 - самая сложная проверка.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2022-06-10 23:18:04 +00:00
|
|
|
protected function isSuccess($caster, int $difficulty = 40): bool
|
2021-01-25 18:00:36 +00:00
|
|
|
{
|
|
|
|
# 40 - потолок стата.
|
|
|
|
if ($difficulty > 40) {
|
|
|
|
$difficulty = 40;
|
|
|
|
}
|
2022-06-10 23:18:04 +00:00
|
|
|
return mt_rand(1, $difficulty) < $caster->intelligence;
|
2021-01-25 18:00:36 +00:00
|
|
|
}
|
2020-09-16 15:13:25 +00:00
|
|
|
}
|