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

BaseCharacterSkill::getCooldown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 2
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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
?>