Completed
Push — master ( 97de22...5eb6e2 )
by Jakub
02:02
created

CombatActionSelector   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

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

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
use Nexendrie\Utils\Constants;
7
8
/**
9
 * CombatActionSelector
10
 *
11
 * @author Jakub Konečný
12
 */
13 1
final class CombatActionSelector implements ICombatActionSelector {
14 1
  use \Nette\SmartObject;
15
  
16
  public function chooseAction(CombatBase $combat, Character $character): ?string {
17 1
    if($character->hitpoints < 1) {
18
      return null;
19 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...
20 1
      return CombatAction::ACTION_HEALING;
21
    }
22 1
    $attackTarget = $combat->selectAttackTarget($character);
23 1
    if(is_null($attackTarget)) {
24
      return null;
25
    }
26 1
    if(count($character->usableSkills) > 0) {
27 1
      $skill = $character->usableSkills[0];
28 1
      if($skill instanceof CharacterAttackSkill) {
29 1
        return CombatAction::ACTION_SKILL_ATTACK;
30 1
      } elseif($skill instanceof  CharacterSpecialSkill) {
31 1
        return CombatAction::ACTION_SKILL_SPECIAL;
32
      }
33
    }
34 1
    return CombatAction::ACTION_ATTACK;
35
  }
36
}
37
?>