Completed
Push — master ( 946f06...d235f7 )
by Jakub
06:52 queued 03:15
created

CombatActionSelector   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 29
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedActions() 0 4 1
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 getAllowedActions(): array {
17 1
    $allowedActions = Constants::getConstantsValues(CombatAction::class, "ACTION_");
18 1
    return array_values(array_filter($allowedActions, function(string $value) {
19 1
      return ($value !== CombatAction::ACTION_POISON);
20 1
    }));
21
  }
22
  
23
  public function chooseAction(CombatBase $combat, Character $character): ?string {
24 1
    if($character->hitpoints < 1) {
25
      return NULL;
26 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...
27 1
      return CombatAction::ACTION_HEALING;
28
    }
29 1
    $attackTarget = $combat->selectAttackTarget($character);
30 1
    if(is_null($attackTarget)) {
31
      return NULL;
32
    }
33 1
    if(count($character->usableSkills) > 0) {
34 1
      $skill = $character->usableSkills[0];
35 1
      if($skill instanceof CharacterAttackSkill) {
36 1
        return CombatAction::ACTION_SKILL_ATTACK;
37 1
      } elseif($skill instanceof  CharacterSpecialSkill) {
38 1
        return CombatAction::ACTION_SKILL_SPECIAL;
39
      }
40
    }
41 1
    return CombatAction::ACTION_ATTACK;
42
  }
43
}
44
?>