public void testSetRandomShouldSetRandomToBeforeRandom() {
   // GIVEN
   underTest = new FightBeforeRoundTransformer();
   final FfFightCommand command = new FfFightCommand();
   final FightCommandMessageList messages = new FightCommandMessageList();
   Whitebox.setInternalState(command, "messages", messages);
   final FightRoundBoundingCommand fightRandom = new FightRoundBoundingCommand(command);
   // WHEN
   underTest.setBounding(command, fightRandom);
   // THEN
   Assert.assertSame(command.getBeforeBounding(), fightRandom);
 }
 public void testShouldExecutePostHandlerWhenCaptainAttackStrengthTooLowShouldReturnFalse() {
   // GIVEN
   expect(command.getEnemies()).andReturn(Arrays.asList("7", "8"));
   final ImmutableMap<String, Integer> attackStrengths = ImmutableMap.of("7", 14, "8", 13);
   expect(command.getAttackStrengths()).andReturn(attackStrengths).times(2);
   mockControl.replay();
   // WHEN
   final boolean returned =
       underTest.shouldExecutePostHandler(command, resolvationData, results, data);
   // THEN
   Assert.assertFalse(returned);
 }
 public void
     testShouldExecutePostHandlerWhenLostAgainstHighCaptainAttackStrengthShouldReturnTrue() {
   // GIVEN
   results = new FightRoundResult[] {FightRoundResult.LOSE, FightRoundResult.TIE};
   expect(command.getEnemies()).andReturn(Arrays.asList("7", "8"));
   final ImmutableMap<String, Integer> attackStrengths = ImmutableMap.of("7", 18, "8", 13);
   expect(command.getAttackStrengths()).andReturn(attackStrengths).times(2);
   mockControl.replay();
   // WHEN
   final boolean returned =
       underTest.shouldExecutePostHandler(command, resolvationData, results, data);
   // THEN
   Assert.assertTrue(returned);
 }
 @Override
 public List<ParagraphData> doResolve(
     final FfFightCommand command, final ResolvationData resolvationData) {
   command.setLuckTestAllowed(false);
   request.setAttribute("characterRecord", "ff12characterRecord.jsp");
   return superResolver.doResolve(command, resolvationData);
 }
 private void resolveBattleRound(
     final FfFightCommand command,
     final ResolvationData resolvationData,
     final List<ParagraphData> resolveList) {
   final FfCharacter character = (FfCharacter) resolvationData.getCharacter();
   final FfCharacterHandler characterHandler =
       (FfCharacterHandler) resolvationData.getCharacterHandler();
   final String lastFightCommand =
       characterHandler.getInteractionHandler().getLastFightCommand(character);
   if (FfFightCommand.ATTACKING.equals(lastFightCommand)) {
     handleAttacking(command, resolvationData, resolveList);
   } else {
     command.setBattleType("ff15ship");
     command.setOngoing(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 testShouldExecutePostHandlerWhenEnemiesDoesNotContainSevenShouldReturnFalse() {
   // GIVEN
   expect(command.getEnemies()).andReturn(Arrays.asList("3", "75", "44"));
   mockControl.replay();
   // WHEN
   final boolean returned =
       underTest.shouldExecutePostHandler(command, resolvationData, results, data);
   // THEN
   Assert.assertFalse(returned);
 }
 @Override
 public List<ParagraphData> doResolve(
     final FfFightCommand command, final ResolvationData resolvationData) {
   final List<ParagraphData> resolveList = new ArrayList<>();
   resolveBattlingParties(command, resolvationData, null);
   final FfCharacterHandler characterHandler =
       (FfCharacterHandler) resolvationData.getCharacterHandler();
   command.setOngoing(true);
   resolveBattleRound(command, resolvationData, resolveList);
   characterHandler
       .getAttributeHandler()
       .sanityCheck((FfCharacter) resolvationData.getCharacter());
   resolveBattlingParties(command, resolvationData, resolveList);
   return resolveList;
 }
Example #9
0
 @Override
 public void executePostHandler(
     final FfFightCommand command,
     final ResolvationData resolvationData,
     final FightRoundResult[] results,
     final BasicEnemyPrePostFightDataContainer data) {
   final int[] randomNumber = getGenerator().getRandomNumber(1);
   final String dice = getRenderer().render(getGenerator().getDefaultDiceSide(), randomNumber);
   final FightCommandMessageList messages = command.getMessages();
   messages.addKey("page.ff.label.random.after", dice, randomNumber[0]);
   final Ff20Character character = (Ff20Character) resolvationData.getCharacter();
   if (randomNumber[0] < LUCK_LOWER_LIMIT) {
     character.changeStamina(STAMINA_EXTRA_DEDUCTION);
     messages.addKey("page.ff20.fight.daioni.stamina");
   } else if (randomNumber[0] > LUCK_UPPER_LIMIT) {
     character.changeSkill(SKILL_EXTRA_DEDUCTION);
     messages.addKey("page.ff20.fight.daioni.skill");
   } else {
     character.changeLuck(LUCK_EXTRA_DEDUCTION);
     messages.addKey("page.ff20.fight.daioni.luck");
   }
 }
 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);
 }
  @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);
    }
  }