BaseCharacterSkill::getLevel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
rs 10
ccs 1
cts 1
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
use Nexendrie\Utils\Numbers;
7
8
/**
9
 * Base character skill
10
 *
11
 * @author Jakub Konečný
12
 * @property-read BaseSkill $skill
13
 * @property int $level
14
 * @property-read int $cooldown
15
 * @property-read string $skillType
16
 * @property-read bool $usable
17
 */
18 1
abstract class BaseCharacterSkill
19
{
20
    use \Nette\SmartObject;
21
22
    protected int $level;
23
    protected int $cooldown = 0;
24
25 1
    public function __construct(protected BaseSkill $skill, int $level)
26
    {
27 1
        $this->setLevel($level);
28 1
        $this->resetCooldown();
29 1
    }
30
31
    abstract protected function getSkillType(): string;
32
33
    protected function getLevel(): int
34
    {
35 1
        return $this->level;
36
    }
37
38
    protected function getCooldown(): int
39
    {
40
        return $this->cooldown;
41
    }
42
43
    protected function setLevel(int $level): void
44
    {
45 1
        $this->level = Numbers::range($level, 0, $this->skill->levels);
46 1
    }
47
48
    protected function isUsable(): bool
49
    {
50 1
        return ($this->cooldown < 1);
51
    }
52
53
    public function resetCooldown(): void
54
    {
55 1
        $this->cooldown = $this->skill->cooldown;
56 1
    }
57
58
    public function decreaseCooldown(): void
59
    {
60 1
        if ($this->cooldown > 0) {
61 1
            $this->cooldown--;
62
        }
63 1
    }
64
}
65