From 887521d366b8c549eef1265c10b85d052ed9088e Mon Sep 17 00:00:00 2001 From: Matteo Vaccari Date: Sun, 5 Nov 2023 21:18:28 +0100 Subject: [PATCH] Fix bug in attacker killed in battle back --- src/model/commands/close_combat_command.js | 3 +-- .../commands/close_combat_command.test.js | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/model/commands/close_combat_command.js b/src/model/commands/close_combat_command.js index 7043505..e5fc651 100644 --- a/src/model/commands/close_combat_command.js +++ b/src/model/commands/close_combat_command.js @@ -52,8 +52,7 @@ export class CloseCombatCommand extends AbstractCombatCommand { game.damageUnit(attackingUnit, totalDamage); if (game.isUnitDead(attackingUnit)) { events.push(new UnitKilledEvent(attackingUnit, attackingHex)); - } - if (retreatHexes.length > 0) { + } else if (retreatHexes.length > 0) { game.unshiftPhase(new AttackerRetreatPhase(attackingHex, retreatHexes)); } } diff --git a/src/model/commands/close_combat_command.test.js b/src/model/commands/close_combat_command.test.js index 717c268..517a3c3 100644 --- a/src/model/commands/close_combat_command.test.js +++ b/src/model/commands/close_combat_command.test.js @@ -122,6 +122,27 @@ describe('defender cannot evade', () => { }); }); + describe('attacker killed, flags irrelevant', () => { + const defenderDice = Array(4).fill(RESULT_HEAVY).concat([RESULT_FLAG]); + let game = makeGame(new NullScenario(), diceReturning( + Array(5).fill(RESULT_LIGHT).concat(defenderDice))); + game.placeUnit(hexOf(1, 5), attacker); + game.placeUnit(hexOf(1, 4), defender); + + const events = closeCombatCommand.play(game); + + test('next phase', () => { + expect(game.currentPhase).toBeInstanceOf(PlayCardPhase); + expect(game.phases.length).toEqual(1); + }); + + test('attacker killed', () => { + expect(game.unitAt(hexOf(1, 4))).toBe(defender); + expect(game.unitAt(hexOf(1, 5))).toBeUndefined(); + expect(game.killedUnitsOfSide(Side.ROMAN)).toEqual([attacker]); + }); + }); + describe('attacker retreats', () => { let game = makeGame(new NullScenario(), diceReturning([ RESULT_LIGHT, RESULT_LIGHT,RESULT_LIGHT,RESULT_LIGHT,RESULT_LIGHT,