| Conditions | 4 |
| Paths | 4 |
| Total Lines | 15 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 4.128 |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 | } |
||
| 33 | ?> |