From 5dccafbea26068142abf7d3faea843906ce85afe Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Tue, 20 Dec 2011 12:42:19 +0000 Subject: [PATCH] Multiple choice response is now an index of the response, rather than the whole text of it. --- .../MultipleChoiceAwaitingDecision.java | 16 ++-- .../com/gempukku/lotro/at/AbstractAtTest.java | 14 +++- .../com/gempukku/lotro/at/DeathAtTest.java | 2 +- .../lotro/at/IndividualCardAtTest.java | 73 ++++++++++++++++++- .../src/main/webapp/js/gameUi.js | 64 ++++++++-------- 5 files changed, 121 insertions(+), 48 deletions(-) diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/MultipleChoiceAwaitingDecision.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/MultipleChoiceAwaitingDecision.java index 4ec4bf97c..cd6207e52 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/MultipleChoiceAwaitingDecision.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/MultipleChoiceAwaitingDecision.java @@ -15,18 +15,12 @@ public abstract class MultipleChoiceAwaitingDecision extends AbstractAwaitingDec public final void decisionMade(String result) throws DecisionResultInvalidException { if (result == null) throw new DecisionResultInvalidException(); - int index = resultIndex(result); - if (index < 0) - throw new DecisionResultInvalidException(); - validDecisionMade(index, result); - } - - private int resultIndex(String result) { - for (int i = 0; i < _possibleResults.length; i++) { - if (_possibleResults[i].equals(result)) - return i; + try { + int index = Integer.parseInt(result); + validDecisionMade(index, _possibleResults[index]); + } catch (NumberFormatException exp) { + throw new DecisionResultInvalidException("Unkown response number"); } - return -1; } } diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/AbstractAtTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/AbstractAtTest.java index f425ec257..250d0a599 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/AbstractAtTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/AbstractAtTest.java @@ -62,13 +62,13 @@ public abstract class AbstractAtTest { playerDecided(P2, "0"); // Seating choice - playerDecided(P1, "1"); + playerDecided(P1, "0"); } protected void skipMulligans() throws DecisionResultInvalidException { // Mulligans - playerDecided(P1, "No"); - playerDecided(P2, "No"); + playerDecided(P1, "0"); + playerDecided(P2, "0"); } protected void validateContents(String[] array1, String[] array2) { @@ -97,6 +97,14 @@ public abstract class AbstractAtTest { return null; } + protected String getMultipleDecisionIndex(AwaitingDecision awaitingDecision, String result) { + String[] actionTexts = (String[]) awaitingDecision.getDecisionParameters().get("results"); + for (int i = 0; i < actionTexts.length; i++) + if (actionTexts[i].equals(result)) + return String.valueOf(i); + return null; + } + private void addPlayerDeck(String player, Map decks, Map> additionalCardsInDeck) { LotroDeck deck = createSimplestDeck(); if (additionalCardsInDeck != null) { diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/DeathAtTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/DeathAtTest.java index 22b955402..03c2f502b 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/DeathAtTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/DeathAtTest.java @@ -45,7 +45,7 @@ public class DeathAtTest extends AbstractAtTest { // Decide not to move assertEquals(Phase.REGROUP, _game.getGameState().getCurrentPhase()); - playerDecided(P1, "No"); + playerDecided(P1, getMultipleDecisionIndex(_userFeedback.getAwaitingDecision(P1), "No")); // Fellowship of player2 assertEquals(Phase.FELLOWSHIP, _game.getGameState().getCurrentPhase()); diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/IndividualCardAtTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/IndividualCardAtTest.java index 4acb3392e..d2a0c9b3a 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/IndividualCardAtTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/IndividualCardAtTest.java @@ -233,7 +233,7 @@ public class IndividualCardAtTest extends AbstractAtTest { // End fellowship phase playerDecided(P1, ""); - // End fellowship phase + // End shadow phase playerDecided(P2, ""); playerDecided(P1, "0"); @@ -280,4 +280,75 @@ public class IndividualCardAtTest extends AbstractAtTest { assertEquals(0, _game.getGameState().getWounds(_game.getGameState().findCardById(Integer.parseInt(legolasCardId)))); } + + @Test + public void endofTheGameGivingDamagePlusOne() throws DecisionResultInvalidException { + initializeSimplestGame(); + + skipMulligans(); + + PhysicalCardImpl aragorn = new PhysicalCardImpl(100, "1_89", P1, _library.getLotroCardBlueprint("1_89")); + PhysicalCardImpl urukHaiRaidingParty = new PhysicalCardImpl(100, "1_158", P2, _library.getLotroCardBlueprint("1_158")); + PhysicalCardImpl endOfTheGame = new PhysicalCardImpl(100, "10_30", P1, _library.getLotroCardBlueprint("10_30")); + + _game.getGameState().addCardToZone(_game, aragorn, Zone.FREE_CHARACTERS); + _game.getGameState().addWound(aragorn); + _game.getGameState().addWound(aragorn); + _game.getGameState().addWound(aragorn); + + _game.getGameState().addCardToZone(_game, endOfTheGame, Zone.HAND); + + // End fellowship phase + playerDecided(P1, ""); + + _game.getGameState().addCardToZone(_game, urukHaiRaidingParty, Zone.SHADOW_CHARACTERS); + + // End shadow phase + playerDecided(P2, ""); + + // End maneuvers phase + playerDecided(P1, ""); + playerDecided(P2, ""); + + // End arhcery phase + playerDecided(P1, ""); + playerDecided(P2, ""); + + // End assignment phase + playerDecided(P1, ""); + playerDecided(P2, ""); + + // Assign + playerDecided(P1, aragorn.getCardId() + " " + urukHaiRaidingParty.getCardId()); + + // Start skirmish + playerDecided(P1, String.valueOf(aragorn.getCardId())); + + AwaitingDecision playSkirmishEvent = _userFeedback.getAwaitingDecision(P1); + assertEquals(AwaitingDecisionType.CARD_ACTION_CHOICE, playSkirmishEvent.getDecisionType()); + playerDecided(P1, "0"); + + assertEquals(10, _game.getModifiersQuerying().getStrength(_game.getGameState(), aragorn)); + + // End skirmish phase + playerDecided(P2, ""); + playerDecided(P1, ""); + + AwaitingDecision skirmishWinResponse = _userFeedback.getAwaitingDecision(P1); + assertEquals(AwaitingDecisionType.ACTION_CHOICE, skirmishWinResponse.getDecisionType()); + playerDecided(P1, getCardActionId(skirmishWinResponse, "Required")); + + AwaitingDecision effectChoice = _userFeedback.getAwaitingDecision(P1); + assertEquals(AwaitingDecisionType.MULTIPLE_CHOICE, effectChoice.getDecisionType()); + + int index = -1; + String[] choices = ((String[]) effectChoice.getDecisionParameters().get("results")); + for (int i = 0; i < choices.length; i++) + if (choices[i].startsWith("Make ")) + index = i; + + playerDecided(P1, String.valueOf(index)); + + assertEquals(2, _game.getGameState().getWounds(urukHaiRaidingParty)); + } } diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js index 7791a51df..0f07b1537 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js @@ -609,21 +609,21 @@ var GempLotrGameUI = Class.extend({ initializeDialogs: function() { this.smallDialog = $("
") .dialog({ - autoOpen: false, - closeOnEscape: false, - resizable: false, - width: 400, - height: 200 - }); + autoOpen: false, + closeOnEscape: false, + resizable: false, + width: 400, + height: 200 + }); this.cardActionDialog = $("
") .dialog({ - autoOpen: false, - closeOnEscape: false, - resizable: true, - width: 600, - height: 300 - }); + autoOpen: false, + closeOnEscape: false, + resizable: true, + width: 600, + height: 300 + }); var that = this; @@ -638,11 +638,11 @@ var GempLotrGameUI = Class.extend({ this.infoDialog = $("
") .dialog({ - autoOpen: false, - closeOnEscape: true, - resizable: false, - title: "Card information" - }); + autoOpen: false, + closeOnEscape: true, + resizable: false, + title: "Card information" + }); var swipeOptions = { threshold: 20, @@ -1113,12 +1113,12 @@ var GempLotrGameUI = Class.extend({ if (!this.replayMode) { this.smallDialog.dialog("option", "buttons", - { - "OK": function() { - $(this).dialog("close"); - that.decisionFunction(id, $("#integerDecision").val()); - } - }); + { + "OK": function() { + $(this).dialog("close"); + that.decisionFunction(id, $("#integerDecision").val()); + } + }); } $("#integerDecision").SpinnerControl({ type: 'range', @@ -1145,7 +1145,7 @@ var GempLotrGameUI = Class.extend({ var html = text + "
"; var that = this; @@ -1154,12 +1154,12 @@ var GempLotrGameUI = Class.extend({ if (!this.replayMode) { this.smallDialog.dialog("option", "buttons", - { - "OK": function() { - $(this).dialog("close"); - that.decisionFunction(id, $("#multipleChoiceDecision").val()); - } - }); + { + "OK": function() { + $(this).dialog("close"); + that.decisionFunction(id, $("#multipleChoiceDecision").val()); + } + }); } this.smallDialog.dialog("open"); @@ -1523,8 +1523,8 @@ var GempLotrGameUI = Class.extend({ $(div).find('LI.hover').removeClass('hover'); $(this).parent().addClass('hover'); }).mouseout(function() { - $(div).find('LI.hover').removeClass('hover'); - }); + $(div).find('LI.hover').removeClass('hover'); + }); var getRidOfContextMenu = function() { $(div).remove();