Completed
Push — master ( b2206c...5f69d8 )
by Jakub
02:25
created

CombatActionSelector::getAllowedActions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
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
?>