Passed
Push — master ( d0ce80...210dba )
by Jakub
06:27
created

BaseCharacterSkill   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 8
eloc 15
c 3
b 1
f 0
dl 0
loc 39
ccs 13
cts 14
cp 0.9286
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getLevel() 0 2 1
A __construct() 0 4 1
A resetCooldown() 0 2 1
A isUsable() 0 2 1
A setLevel() 0 2 1
A decreaseCooldown() 0 3 2
A getCooldown() 0 2 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
  use \Nette\SmartObject;
20
21
  /** @var BaseSkill */
22
  protected $skill;
23
  protected int $level;
24
  protected int $cooldown = 0;
25
  
26
  public function __construct(BaseSkill $skill, int $level) {
27 1
    $this->skill = $skill;
28 1
    $this->setLevel($level);
29 1
    $this->resetCooldown();
30 1
  }
31
32
  abstract protected function getSkillType(): string;
33
  
34
  protected function getLevel(): int {
35 1
    return $this->level;
36
  }
37
  
38
  protected function getCooldown(): int {
39
    return $this->cooldown;
40
  }
41
  
42
  protected function setLevel(int $level): void {
43 1
    $this->level = Numbers::range($level, 0, $this->skill->levels);
44 1
  }
45
  
46
  protected function isUsable(): bool {
47 1
    return ($this->cooldown < 1);
48
  }
49
  
50
  public function resetCooldown(): void {
51 1
    $this->cooldown = $this->skill->cooldown;
52 1
  }
53
  
54
  public function decreaseCooldown(): void {
55 1
    if($this->cooldown > 0) {
56 1
      $this->cooldown--;
57
    }
58 1
  }
59
}
60
?>