@Override protected void handleAttacking( final FfFightCommand command, final ResolvationData resolvationData, final List<ParagraphData> resolveList) { command.increaseBattleRound(); command.getMessages().setRoundMessage(command.getRoundNumber()); final FfFightRoundResolver roundResolver = getBeanFactory().getBean(Ship15FightRoundResolver.class); roundResolver.resolveRound(command, resolvationData, null); if (allEnemiesDead(command.getResolvedEnemies())) { command.setOngoing(false); for (final FightOutcome outcome : command.getWin()) { if (command.getRoundNumber() >= outcome.getMin() && command.getRoundNumber() <= outcome.getMax()) { resolveList.add(outcome.getParagraphData()); } } } else if (shipIsDestroyed(resolvationData)) { command.setOngoing(false); resolveList.add(command.getLose()); } else { command.setOngoing(true); command.setKeepOpen(true); } }
@BeforeMethod public void setUpMethod() { command = new FfFightCommand(); init(command); Whitebox.setInternalState(command, "roundNumber", 1); fixEnemy(); enemies = new ArrayList<>(); command.getResolvedEnemies().clear(); mockControl.reset(); }
public void testResolveRoundWhenSingleMagicalEnemyIsHitWithMagicalWeaponShouldCauseDamageAndReturnRoundResultWithWin() { // GIVEN enemies.add(selectedEnemy); command.getResolvedEnemies().addAll(enemies); selectedEnemy.setKillableByNormal(false); selectedEnemy.setKillableByBlessed(false); expect(interactionHandler.peekLastFightCommand(character, "enemyId")).andReturn("9"); expect(generator.getRandomNumber(2)).andReturn(SELF_ATTACK_STRENGTH_ROLL); expect(attributeHandler.resolveValue(character, "attackStrength")).andReturn(0); expect(generator.getRandomNumber(2)).andReturn(ENEMY_ATTACK_STRENGTH_ROLL); expect(attributeHandler.resolveValue(character, "skill")).andReturn(10); expect(diceResultRenderer.render(6, SELF_ATTACK_STRENGTH_ROLL)) .andReturn(SELF_ATTACK_STRENGTH_RENDER); expectText( "page.ff.label.fight.single.attackStrength.self", new Object[] {SELF_ATTACK_STRENGTH_RENDER, 17}); logger.debug("Attack strength for self: {}", 17); expect(diceResultRenderer.render(6, ENEMY_ATTACK_STRENGTH_ROLL)) .andReturn(ENEMY_ATTACK_STRENGTH_RENDER); expectText( "page.ff.label.fight.single.attackStrength.enemy", new Object[] {"Goblin", ENEMY_ATTACK_STRENGTH_RENDER, 15}); logger.debug("Attack strength for {}: {}", "Goblin", 15); final FfItem weapon = new FfItem("7", "Sword", ItemType.weapon1); weapon.setMagical(true); weapon.setStaminaDamage(3); expect(itemHandler.getEquippedWeapon(character)).andReturn(weapon).times(2); expect(attributeHandler.resolveValue(character, "baseStaminaDamage")).andReturn(0); expectText("page.ff.label.fight.single.successfulAttack", new Object[] {"Goblin"}); mockControl.replay(); // WHEN final FightRoundResult[] returned = underTest.resolveRound(command, resolvationData, beforeRoundResult); // THEN Assert.assertEquals(returned.length, 1); Assert.assertEquals(returned[0], FightRoundResult.WIN); }