Passed
Push — master ( dd3471...ff1e5a )
by Jakub
02:42
created

BaseCharacterSkill   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 8
eloc 15
dl 0
loc 41
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

7 Methods

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