Passed
Push — master ( 9ad4f6...7fb37f )
by Jakub
01:42
created

BaseCharacterSkill::isUsable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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