Passed
Push — master ( ff1e5a...9ad4f6 )
by Jakub
02:27
created

CombatActionSelector::getDefaultAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
nc 1
nop 0
cc 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
use HeroesofAbenez\Combat\CombatActions\ICombatAction;
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
    }
20
    /** @var ICombatAction[] $actions */
21 1
    $actions = $combat->combatActions->toArray();
22 1
    usort($actions, function(ICombatAction $a, ICombatAction $b) {
23 1
      return $a->getPriority() < $b->getPriority();
24 1
    });
25 1
    foreach($actions as $action) {
26 1
      if($action->shouldUse($combat, $character)) {
27 1
        return $action->getName();
28
      }
29
    }
30
    return null;
31
  }
32
}
33
?>