battles/classes/Battles/Magic/Magic.php

63 lines
1.8 KiB
PHP

<?php
# Date: 16.09.2020 (08:45)
namespace Battles\Magic;
class Magic
{
protected $status;
protected function isVisible($caster, $target):bool
{
if ($caster->battle != $target->battle || $caster->room != $target->room) {
$this->status = 'Вы не видите цель!';
return false;
} else {
return true;
}
}
protected function isNotDead($caster):bool
{
if ($caster->health < 1) {
$this->status = 'Вы мертвы!';
return false;
} else {
return true;
}
}
protected function enoughMana($caster):bool
{
if ($caster->mana < 1) {
$this->status = 'Недостаточно пыли!';
return false;
} else {
return true;
}
}
protected function isNotInBattle($caster):bool
{
if ($caster->battle) {
$this->status = 'Невозможно применить в поединке!';
return false;
} else {
return true;
}
}
/**
* Проверка на успех заклинания. Чем выше интеллект, тем выше шанс успеха.
* @param $caster - заклинатель (массив значений из базы).
* @param int $difficulty - сложность произнесения заклинания. Чем выше значение, тем сложнее проверка. 40 - самая сложная проверка.
*
* @return bool
*/
protected function isSuccess($caster, int $difficulty = 40):bool
{
# 40 - потолок стата.
if ($difficulty > 40) {
$difficulty = 40;
}
return mt_rand(1,$difficulty) < $caster->intelligence;
}
}