fix: guard invalid turn transitions
This commit is contained in:
@@ -93,8 +93,25 @@ final class CombatEngine
|
||||
throw new CombatException('Matches require alpha and bravo teams.');
|
||||
}
|
||||
|
||||
$livingTeams = ['alpha' => false, 'bravo' => false];
|
||||
|
||||
foreach ($match->units as $unit) {
|
||||
if (!$unit->isDefeated()) {
|
||||
$livingTeams[$unit->teamId] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$livingTeams['alpha'] || !$livingTeams['bravo']) {
|
||||
throw new CombatException('Cannot end turn while a team is eliminated.');
|
||||
}
|
||||
|
||||
$endingTeamId = $match->activeTeamId;
|
||||
$nextTeamId = $endingTeamId === 'alpha' ? 'bravo' : 'alpha';
|
||||
|
||||
if ($nextTeamId === 'alpha' && $match->round === PHP_INT_MAX) {
|
||||
throw new CombatException('Match round limit reached.');
|
||||
}
|
||||
|
||||
$units = [];
|
||||
|
||||
foreach ($match->units as $unit) {
|
||||
|
||||
Reference in New Issue
Block a user