Completed
Push — master ( 10c9e5...cb21fe )
by Jakub
02:04
created

BaseCharacterSkill   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 47
ccs 17
cts 19
cp 0.8947
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getLevel() 0 2 1
A __construct() 0 3 1
A resetCooldown() 0 2 1
A getSkillType() 0 7 3
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
  }
31
  
32
  public function getLevel(): int {
33 1
    return $this->level;
34
  }
35
  
36
  public function getCooldown(): int {
37
    return $this->cooldown;
38
  }
39
  
40
  public function setLevel(int $level) {
41 1
    $this->level = Numbers::range($level, 1, $this->skill->levels);
42 1
  }
43
  
44
  public function getSkillType(): string {
45 1
    if($this->skill instanceof SkillAttack) {
46 1
      return "attack";
47 1
    } elseif($this->skill instanceof SkillSpecial) {
48 1
      return "special";
49
    }
50
    return "";
51
  }
52
  
53
  public function canUse(): bool {
54 1
    return ($this->cooldown < 1);
55
  }
56
  
57
  public function resetCooldown(): void {
58 1
    $this->cooldown = $this->skill->cooldown;
59 1
  }
60
  
61
  public function decreaseCooldown(): void {
62 1
    if($this->cooldown > 0) {
63 1
      $this->cooldown--;
64
    }
65 1
  }
66
}
67
?>