Completed
Push — master ( 2495a7...8590e9 )
by Jakub
02:49
created

CombatActionSelector   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 8
eloc 16
dl 0
loc 22
ccs 13
cts 16
cp 0.8125
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B chooseAction() 0 19 8
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
/**
7
 * CombatActionSelector
8
 *
9
 * @author Jakub Konečný
10
 */
11 1
final class CombatActionSelector implements ICombatActionSelector {
12 1
  use \Nette\SmartObject;
13
  
14
  public function chooseAction(CombatBase $combat, Character $character): ?string {
15 1
    if($character->hitpoints < 1) {
16
      return null;
17 1
    } elseif(in_array($character, $combat->findHealers()->toArray(), true) AND !is_null($combat->selectHealingTarget($character))) {
0 ignored issues
show
introduced by
Line exceeds 120 characters; contains 132 characters
Loading history...
18
      return CombatAction::ACTION_HEALING;
19
    }
20 1
    $attackTarget = $combat->selectAttackTarget($character);
21 1
    if(is_null($attackTarget)) {
22
      return null;
23
    }
24 1
    if(count($character->usableSkills) > 0) {
25 1
      $skill = $character->usableSkills[0];
26 1
      if($skill instanceof CharacterAttackSkill) {
27 1
        return CombatAction::ACTION_SKILL_ATTACK;
28 1
      } elseif($skill instanceof  CharacterSpecialSkill) {
29 1
        return CombatAction::ACTION_SKILL_SPECIAL;
30
      }
31
    }
32 1
    return CombatAction::ACTION_ATTACK;
33
  }
34
}
35
?>