Passed
Push — master ( f2d70f...ce79d3 )
by Jakub
02:17
created

BaseCharacterSkill::setLevel()   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
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
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
 */
17 1
abstract class BaseCharacterSkill {
18 1
  use \Nette\SmartObject;
19
  
20
  public const MAX_LEVEL = 10;
21
  
22
  /** @var BaseSkill */
23
  protected $skill;
24
  /** @var int */
25
  protected $level;
26
  /** @var int */
27
  protected $cooldown = 0;
28
  
29
  public function __construct(BaseSkill $skill, int $level) {
30 1
    $this->skill = $skill;
31 1
    $this->setLevel($level);
32 1
  }
33
  
34
  public function getLevel(): int {
35 1
    return $this->level;
36
  }
37
  
38
  public function getCooldown(): int {
39
    return $this->cooldown;
40
  }
41
  
42
  public function setLevel(int $level) {
43 1
    $this->level = Numbers::range($level, 1, static::MAX_LEVEL);
44 1
  }
45
  
46
  public function getSkillType(): string {
47 1
    if($this->skill instanceof SkillAttack) {
48 1
      return "attack";
49 1
    } elseif($this->skill instanceof SkillSpecial) {
50 1
      return "special";
51
    }
52
    return "";
53
  }
54
  
55
  public function canUse(): bool {
56 1
    return ($this->cooldown < 1);
57
  }
58
  
59
  public function resetCooldown(): void {
60 1
    $this->cooldown = $this->skill->cooldown;
61 1
  }
62
  
63
  public function decreaseCooldown(): void {
64 1
    if($this->cooldown > 0) {
65 1
      $this->cooldown--;
66
    }
67 1
  }
68
}
69
?>