diff --git a/src/main/java/forge/gui/input/Input_Mulligan.java b/src/main/java/forge/gui/input/Input_Mulligan.java index 69ff5e304b3..2f8e306e0b8 100644 --- a/src/main/java/forge/gui/input/Input_Mulligan.java +++ b/src/main/java/forge/gui/input/Input_Mulligan.java @@ -2,7 +2,16 @@ package forge.gui.input; import java.util.ArrayList; -import forge.*; +import forge.AllZone; +import forge.AllZoneUtil; +import forge.ButtonUtil; +import forge.Card; +import forge.CardList; +import forge.ComputerUtil; +import forge.Constant; +import forge.GameActionUtil; +import forge.Phase; +import forge.Player; import forge.card.abilityFactory.AbilityFactory; import forge.card.spellability.SpellAbility; import forge.game.GamePlayerRating; @@ -16,15 +25,15 @@ import forge.quest.data.QuestData; * @version $Id$ */ public class Input_Mulligan extends Input { - /** Constant serialVersionUID=-8112954303001155622L */ + /** Constant serialVersionUID=-8112954303001155622L. */ private static final long serialVersionUID = -8112954303001155622L; - + private static final int MAGIC_NUMBER_OF_SHUFFLES = 100; private static final int AI_MULLIGAN_THRESHOLD = 5; /** {@inheritDoc} */ @Override - public void showMessage() { + public final void showMessage() { ButtonUtil.enableAll(); AllZone.getDisplay().getButtonOK().setText("No"); AllZone.getDisplay().getButtonCancel().setText("Yes"); @@ -33,11 +42,18 @@ public class Input_Mulligan extends Input { /** {@inheritDoc} */ @Override - public void selectButtonOK() { + public final void selectButtonOK() { end(); } - public int doMulligan( Player player, GamePlayerRating playerRating ) { + /** + * + * TODO Write javadoc for this method. + * @param player a Player object + * @param playerRating a GamePlayerRating object + * @return an int + */ + public final int doMulligan(final Player player, final GamePlayerRating playerRating) { CardList hand = AllZoneUtil.getPlayerHand(player); for (Card c : hand) { AllZone.getGameAction().moveToLibrary(c); } for (int i = 0; i < MAGIC_NUMBER_OF_SHUFFLES; i++) { player.shuffle(); } @@ -47,10 +63,10 @@ public class Input_Mulligan extends Input { playerRating.notifyOpeningHandSize(newHand); return newHand; } - + /** {@inheritDoc} */ @Override - public void selectButtonCancel() { + public final void selectButtonCancel() { GamePlayerRating humanRating = AllZone.getGameInfo().getPlayerRating(PlayerIndex.HUMAN); Player humanPlayer = AllZone.getHumanPlayer(); @@ -65,17 +81,17 @@ public class Input_Mulligan extends Input { if (newHand == 0) { end(); } - }//selectButtonOK() + } //selectButtonOK() /** *

end.

*/ - void end() { + final void end() { //Computer mulligan Player aiPlayer = AllZone.getComputerPlayer(); GamePlayerRating aiRating = AllZone.getGameInfo().getPlayerRating(PlayerIndex.AI); boolean aiTakesMulligan = true; - + //Computer mulligans if there are no cards with converted mana cost of 0 in its hand while (aiTakesMulligan) { @@ -85,34 +101,33 @@ public class Input_Mulligan extends Input { if (aiTakesMulligan) { doMulligan(aiPlayer, aiRating); - } + } } //Human Leylines & Chancellors ButtonUtil.reset(); AbilityFactory af = new AbilityFactory(); CardList humanOpeningHand = AllZoneUtil.getPlayerHand(AllZone.getHumanPlayer()); - + for (Card c : humanOpeningHand) { - ArrayList kws = c.getKeyword(); - for(int i = 0;i kws = c.getKeyword(); + for (int i = 0; i < kws.size(); i++) { String kw = kws.get(i); - - if(kw.startsWith("MayEffectFromOpeningHand")) - { + + if (kw.startsWith("MayEffectFromOpeningHand")) { String effName = kw.split(":")[1]; - + SpellAbility effect = af.getAbility(c.getSVar(effName), c); - if(GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) - { + if (GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) { //If we ever let the AI memorize cards in the players hand, this would be a place to do so. AllZone.getGameAction().playSpellAbility_NoStack(effect, false); } } } if (c.getName().startsWith("Leyline")) { - if (GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) + if (GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) { AllZone.getGameAction().moveToPlay(c); + } } } @@ -120,37 +135,41 @@ public class Input_Mulligan extends Input { CardList aiOpeningHand = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer()); for (Card c : aiOpeningHand) { if (!c.getName().startsWith("Leyline")) { - ArrayList kws = c.getKeyword(); - for(int i = 0;i kws = c.getKeyword(); + for (int i = 0; i < kws.size(); i++) { String kw = kws.get(i); - - if(kw.startsWith("MayEffectFromOpeningHand")) - { + + if (kw.startsWith("MayEffectFromOpeningHand")) { String effName = kw.split(":")[1]; - + SpellAbility effect = af.getAbility(c.getSVar(effName), c); - if(effect.doTrigger(false)) //Is there a better way for the AI to decide this? - { - GameActionUtil.showInfoDialg("Computer reveals " + c.getName() + "(" + c.getUniqueNumber() + ")."); + //Is there a better way for the AI to decide this? + if (effect.doTrigger(false)) { + GameActionUtil.showInfoDialg("Computer reveals " + + c.getName() + "(" + c.getUniqueNumber() + ")."); ComputerUtil.playNoStack(effect); } } } } - if (c.getName().startsWith("Leyline") && !(c.getName().startsWith("Leyline of Singularity") - && AllZoneUtil.getCardsInPlay("Leyline of Singularity").size() > 0)) { + if (c.getName().startsWith("Leyline") && !(c.getName().startsWith("Leyline of Singularity") + && AllZoneUtil.getCardsInPlay("Leyline of Singularity").size() > 0)) + { AllZone.getGameAction().moveToPlay(c); AllZone.getGameAction().checkStateEffects(); } } AllZone.getGameAction().checkStateEffects(); - - + + if (AllZone.getGameAction().isStartCut() && !(humanOpeningHand.contains(AllZone.getGameAction().getHumanCut()) - || aiOpeningHand.contains(AllZone.getGameAction().getComputerCut()))) { - AllZone.getGameAction().moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.getHumanPlayer()), AllZone.getGameAction().getHumanCut()); - AllZone.getGameAction().moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.getComputerPlayer()), AllZone.getGameAction().getComputerCut()); + || aiOpeningHand.contains(AllZone.getGameAction().getComputerCut()))) + { + AllZone.getGameAction().moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.getHumanPlayer()), + AllZone.getGameAction().getHumanCut()); + AllZone.getGameAction().moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.getComputerPlayer()), + AllZone.getGameAction().getComputerCut()); } AllZone.getGameAction().checkStateEffects(); Phase.setGameBegins(1);