Conditions | 4 |
Paths | 4 |
Total Lines | 15 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 4.128 |
Changes | 0 |
1 | <?php |
||
34 | public function chooseAction(CombatBase $combat, Character $character): ?string { |
||
35 | 1 | if($character->hitpoints < 1) { |
|
36 | return null; |
||
37 | } |
||
38 | /** @var ICombatAction[] $actions */ |
||
39 | 1 | $actions = $combat->combatActions->toArray(); |
|
40 | 1 | usort($actions, function(ICombatAction $a, ICombatAction $b) { |
|
41 | 1 | return $a->getPriority() < $b->getPriority(); |
|
42 | 1 | }); |
|
43 | 1 | foreach($actions as $action) { |
|
44 | 1 | if($action->shouldUse($combat, $character)) { |
|
45 | 1 | return $action->getName(); |
|
46 | } |
||
47 | } |
||
48 | return $this->defaultAction; |
||
49 | } |
||
51 | ?> |