Completed
Push — master ( a5d74c...946f06 )
by Jakub
06:04
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
dl 0
loc 19
ccs 12
cts 14
cp 0.8571
rs 7.7777
c 0
b 0
f 0
cc 8
eloc 14
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
  public function getAllowedActions(): array {
15 1
    $allowedActions = Constants::getConstantsValues(CombatAction::class, "ACTION_");
16 1
    return array_values(array_filter($allowedActions, function(string $value) {
17 1
      return ($value !== CombatAction::ACTION_POISON);
18 1
    }));
19
  }
20
  
21
  public function chooseAction(CombatBase $combat, Character $character): ?string {
22 1
    if($character->hitpoints < 1) {
23
      return NULL;
24 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...
25 1
      return CombatAction::ACTION_HEALING;
26
    }
27 1
    $attackTarget = $combat->selectAttackTarget($character);
28 1
    if(is_null($attackTarget)) {
29
      return NULL;
30
    }
31 1
    if(count($character->usableSkills) > 0) {
32 1
      $skill = $character->usableSkills[0];
33 1
      if($skill instanceof CharacterAttackSkill) {
34 1
        return CombatAction::ACTION_SKILL_ATTACK;
35 1
      } elseif($skill instanceof  CharacterSpecialSkill) {
36 1
        return CombatAction::ACTION_SKILL_SPECIAL;
37
      }
38
    }
39 1
    return CombatAction::ACTION_ATTACK;
40
  }
41
}
42
?>