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

CombatActionSelector::chooseAction()   B

Complexity

Conditions 8
Paths 7

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 8.1867

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 19
ccs 12
cts 14
cp 0.8571
c 0
b 0
f 0
rs 8.4444
cc 8
nc 7
nop 2
crap 8.1867
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
?>