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

CharacterAttackSkill::getSkillType()   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
/**
7
 * Character skill attack
8
 *
9
 * @author Jakub Konečný
10
 * @property-read SkillAttack $skill
11
 * @property-read int $damage
12
 * @property-read int $hitRate
13
 */
14 1
final class CharacterAttackSkill extends BaseCharacterSkill {
15
  /** @var SkillAttack */
16
  protected $skill;
17
  
18
  public function __construct(SkillAttack $skill, int $level) {
19 1
    parent::__construct($skill, $level);
20 1
  }
21
22
  public function getSkillType(): string {
23 1
    return "attack";
24
  }
25
26
  /**
27
   * @return SkillAttack
28
   */
29
  public function getSkill(): SkillAttack {
30 1
    return $this->skill;
31
  }
32
  
33
  public function getDamage(): int {
34 1
    $damage = 0;
35 1
    if(substr($this->skill->baseDamage, -1) === "%") {
36 1
      $damage += (int) $this->skill->baseDamage;
37
    }
38 1
    if(substr($this->skill->damageGrowth, -1) === "%") {
39 1
      $damage += (int) $this->skill->damageGrowth * ($this->level - 1);
40
    }
41 1
    return $damage;
42
  }
43
  
44
  public function getHitRate(): int {
45 1
    if(is_string($this->skill->hitRate) AND substr($this->skill->hitRate, -1) === "%") {
46 1
      return (int) $this->skill->hitRate;
47
    }
48 1
    return 100;
49
  }
50
}
51
?>