From 96694641b9712f84221b326e56960ab7b32c59b3 Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Mon, 20 May 2013 12:04:00 +0000 Subject: [PATCH] Dig: reveal optional remembers if you've chosen to reveal the card. uses playerController to decide whether to reveal or not --- .../ability/effects/ChooseTypeEffect.java | 39 ++++++++++--------- .../forge/card/ability/effects/DigEffect.java | 30 +++++++------- .../forge/card/cost/CostPartWithList.java | 5 +-- src/main/java/forge/card/cost/CostReveal.java | 3 +- src/main/java/forge/game/GameAction.java | 8 ++-- src/main/java/forge/game/ai/AiController.java | 4 ++ 6 files changed, 46 insertions(+), 43 deletions(-) diff --git a/src/main/java/forge/card/ability/effects/ChooseTypeEffect.java b/src/main/java/forge/card/ability/effects/ChooseTypeEffect.java index e9a2211129a..03ce88fdcf4 100644 --- a/src/main/java/forge/card/ability/effects/ChooseTypeEffect.java +++ b/src/main/java/forge/card/ability/effects/ChooseTypeEffect.java @@ -1,5 +1,6 @@ package forge.card.ability.effects; +import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -37,31 +38,33 @@ public class ChooseTypeEffect extends SpellAbilityEffect { validTypes.addAll(Arrays.asList(sa.getParam("ValidTypes").split(","))); } + if (type.equals("Card")) { + if (validTypes.isEmpty()) validTypes.addAll(Constant.CardTypes.CARD_TYPES); + } else if (type.equals("Creature")) { + if (validTypes.isEmpty()) validTypes.addAll(CardType.getCreatureTypes()); + } else if (type.equals("Basic Land")) { + if (validTypes.isEmpty()) validTypes.addAll(CardType.getBasicTypes()); + } else if (type.equals("Land")) { + if (validTypes.isEmpty()) validTypes.addAll(CardType.getLandTypes()); + } // end if-else if + + for (final String s : invalidTypes) { + validTypes.remove(s); + } + + final Target tgt = sa.getTarget(); final List tgtPlayers = getTargetPlayers(sa); - for (final Player p : tgtPlayers) { - if ((tgt == null) || p.canBeTargetedBy(sa)) { - if (type.equals("Card")) { - if (validTypes.isEmpty()) validTypes.addAll(Constant.CardTypes.CARD_TYPES); - } else if (type.equals("Creature")) { - if (validTypes.isEmpty()) validTypes.addAll(CardType.getCreatureTypes()); - } else if (type.equals("Basic Land")) { - if (validTypes.isEmpty()) validTypes.addAll(CardType.getBasicTypes()); - } else if (type.equals("Land")) { - if (validTypes.isEmpty()) validTypes.addAll(CardType.getLandTypes()); - } // end if-else if - - if( !validTypes.isEmpty()) { - for (final String s : invalidTypes) { - validTypes.remove(s); - } + if( !validTypes.isEmpty()) { + for (final Player p : tgtPlayers) { + if ((tgt == null) || p.canBeTargetedBy(sa)) { String choice = p.getController().chooseSomeType(type, sa.getParam("AILogic"), validTypes, invalidTypes); card.setChosenType(choice); } - } - } + } else + throw new InvalidParameterException(sa.getSourceCard() + "'s ability resulted in no types to choose from"); } } diff --git a/src/main/java/forge/card/ability/effects/DigEffect.java b/src/main/java/forge/card/ability/effects/DigEffect.java index 5d2da03a018..61381dbf9a9 100644 --- a/src/main/java/forge/card/ability/effects/DigEffect.java +++ b/src/main/java/forge/card/ability/effects/DigEffect.java @@ -19,7 +19,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiChoose; -import forge.gui.GuiDialog; +import forge.util.Lang; import forge.util.MyRandom; public class DigEffect extends SpellAbilityEffect { @@ -116,21 +116,18 @@ public class DigEffect extends SpellAbilityEffect { final Card dummy = new Card(); dummy.setName("[No valid cards]"); + boolean hasRevealed = true; if (sa.hasParam("Reveal")) { GuiChoose.one("Revealing cards from library", top); // Singletons.getModel().getGameAction().revealToCopmuter(top.toArray()); // - for when it exists } else if (sa.hasParam("RevealOptional")) { - String question = "Reveal: "; - for (final Card c : top) { - question += c + " "; - } - if (p.isHuman() && GuiDialog.confirm(host, question)) { - GuiChoose.one(host + "Revealing cards from library", top); - // Singletons.getModel().getGameAction().revealToCopmuter(top.toArray()); - } else if (p.isComputer() && (top.get(0).isInstant() || top.get(0).isSorcery())) { - GuiChoose.one(host + "Revealing cards from library", top); - } + String question = "Reveal: " + Lang.joinHomogenous(top) +"?"; + + hasRevealed = p.getController().confirmAction(sa, null, question); + if ( hasRevealed ) + p.getGame().getAction().reveal(top, p); + } else if (sa.hasParam("RevealValid")) { final String revealValid = sa.getParam("RevealValid"); final List toReveal = CardLists.getValidCards(top, revealValid, host.getController(), host); @@ -149,7 +146,7 @@ public class DigEffect extends SpellAbilityEffect { choser.getController().reveal("Looking at cards from library", top, library.getZoneType(), library.getPlayer()); } - if ((sa.hasParam("RememberRevealed")) && !sa.hasParam("RevealValid")) { + if ((sa.hasParam("RememberRevealed")) && !sa.hasParam("RevealValid") && hasRevealed) { for (final Card one : top) { host.addRemembered(one); } @@ -317,14 +314,15 @@ public class DigEffect extends SpellAbilityEffect { // now, move the rest to destZone2 if (destZone2.equals(ZoneType.Library)) { if (choser.isHuman()) { + String prompt = "Put the rest on top of the library in any order"; + if (libraryPosition2 == -1) { + prompt = "Put the rest on the bottom of the library in any order"; + } // put them in any order while (rest.size() > 0) { Card chosen; if (!skipReorder && rest.size() > 1) { - String prompt = "Put the rest on top of the library in any order"; - if (libraryPosition2 == -1) { - prompt = "Put the rest on the bottom of the library in any order"; - } + chosen = GuiChoose.one(prompt, rest); } else { chosen = rest.get(0); diff --git a/src/main/java/forge/card/cost/CostPartWithList.java b/src/main/java/forge/card/cost/CostPartWithList.java index c09b85a2f68..c42317f663f 100644 --- a/src/main/java/forge/card/cost/CostPartWithList.java +++ b/src/main/java/forge/card/cost/CostPartWithList.java @@ -18,7 +18,6 @@ package forge.card.cost; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import forge.Card; import forge.CardUtil; @@ -99,7 +98,7 @@ public abstract class CostPartWithList extends CostPart { } // always returns true, made this to inline with return - public final boolean executePayment(SpellAbility ability, Collection targetCards) { + public final boolean executePayment(SpellAbility ability, List targetCards) { if(canPayListAtOnce()) { // This is used by reveal. Without it when opponent would reveal hand, you'll get N message boxes. this.list.addAll(targetCards); doListPayment(ability, targetCards); @@ -113,7 +112,7 @@ public abstract class CostPartWithList extends CostPart { protected abstract void doPayment(SpellAbility ability, Card targetCard); // Overload these two only together, set to true and perform payment on list protected boolean canPayListAtOnce() { return false; } - protected void doListPayment(SpellAbility ability, Collection targetCards) { }; + protected void doListPayment(SpellAbility ability, List targetCards) { }; /** * TODO: Write javadoc for this method. diff --git a/src/main/java/forge/card/cost/CostReveal.java b/src/main/java/forge/card/cost/CostReveal.java index 50af125ece7..ad2ee5e91b9 100644 --- a/src/main/java/forge/card/cost/CostReveal.java +++ b/src/main/java/forge/card/cost/CostReveal.java @@ -18,7 +18,6 @@ package forge.card.cost; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import com.google.common.collect.Lists; @@ -222,7 +221,7 @@ public class CostReveal extends CostPartWithList { @Override protected boolean canPayListAtOnce() { return true; } @Override - protected void doListPayment(SpellAbility ability, Collection targetCards) { + protected void doListPayment(SpellAbility ability, List targetCards) { ability.getActivatingPlayer().getGame().getAction().reveal(targetCards, ability.getActivatingPlayer()); } diff --git a/src/main/java/forge/game/GameAction.java b/src/main/java/forge/game/GameAction.java index f5e54724e24..71195601c7c 100644 --- a/src/main/java/forge/game/GameAction.java +++ b/src/main/java/forge/game/GameAction.java @@ -18,7 +18,6 @@ package forge.game; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -1404,10 +1403,11 @@ public class GameAction { * @param targetCard * @param activatingPlayer */ - public void reveal(Collection cards, Player cardOwner) { + public void reveal(List cards, Player cardOwner) { + ZoneType zt = cards.isEmpty() ? ZoneType.Hand : game.getZoneOf(cards.get(0)).getZoneType(); for(Player p : game.getPlayers()) { - if ( cardOwner == p) continue; - p.getController().reveal(cardOwner + " reveals card", cards, ZoneType.Hand, cardOwner); + if (cardOwner == p /*&& zt.isKnown()*/) continue; + p.getController().reveal(cardOwner + " reveals card from " + zt, cards, zt, cardOwner); } } diff --git a/src/main/java/forge/game/ai/AiController.java b/src/main/java/forge/game/ai/AiController.java index e817e00653f..c4d5c1e8e71 100644 --- a/src/main/java/forge/game/ai/AiController.java +++ b/src/main/java/forge/game/ai/AiController.java @@ -720,6 +720,10 @@ public class AiController { case Encode: return true; + case Dig: + Card topc = player.getZone(ZoneType.Library).get(0); + return topc.isInstant() || topc.isSorcery(); + default: } String exMsg = String.format("AI confirmAction does not know what to decide about %s API with %s mode.", api, mode);