ChangeZoneEffect: will use inputs where possible (zone == battlefield or zone == gui player's hand) to ease card selection

added facedown Predicate
removed import-related warnings
This commit is contained in:
Maxmtg
2013-05-07 12:10:32 +00:00
parent 0b61dd7c5d
commit f9a7b3cd84
5 changed files with 28 additions and 19 deletions

View File

@@ -167,6 +167,13 @@ public final class CardPredicates {
} }
}; };
public static final Predicate<Card> FACE_DOWN = new Predicate<Card>() {
@Override
public boolean apply(Card c) {
return c.isFaceDown();
}
};
/** /**
* a Predicate<Card> to get all cards that are untapped. * a Predicate<Card> to get all cards that are untapped.
*/ */

View File

@@ -1,14 +1,8 @@
package forge.card.ability.ai; package forge.card.ability.ai;
import java.util.List;
import forge.Card;
import forge.CardLists;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
import forge.game.zone.ZoneType;
public class FlipACoinAi extends SpellAbilityAi { public class FlipACoinAi extends SpellAbilityAi {

View File

@@ -10,6 +10,7 @@ import forge.Card;
import forge.CardCharacteristicName; import forge.CardCharacteristicName;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates; import forge.CardPredicates;
import forge.FThreads;
import forge.GameEntity; import forge.GameEntity;
import forge.card.ability.AbilityUtils; import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect; import forge.card.ability.SpellAbilityEffect;
@@ -19,6 +20,7 @@ import forge.card.spellability.SpellAbility;
import forge.card.spellability.SpellAbilityStackInstance; import forge.card.spellability.SpellAbilityStackInstance;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.card.trigger.TriggerType; import forge.card.trigger.TriggerType;
import forge.control.input.InputSelectCardsFromList;
import forge.game.GameState; import forge.game.GameState;
import forge.game.ai.ComputerUtilCard; import forge.game.ai.ComputerUtilCard;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
@@ -693,17 +695,14 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
if (!defined) { if (!defined) {
if (origin.contains(ZoneType.Library) && !defined && !sa.hasParam("NoLooking")) { if (origin.contains(ZoneType.Library) && !defined && !sa.hasParam("NoLooking")) {
final int fetchNum = Math.min(player.getCardsIn(ZoneType.Library).size(), 4); final int fetchNum = Math.min(player.getCardsIn(ZoneType.Library).size(), 4);
List<Card> shown = !decider.hasKeyword("LimitSearchLibrary") ? player.getCardsIn(ZoneType.Library) : player.getCardsIn(ZoneType.Library, fetchNum);
// Look at whole library before moving onto choosing a card // Look at whole library before moving onto choosing a card
GuiChoose.oneOrNone(sa.getSourceCard().getName() + " - Looking at Library", decider.getController().reveal(sa.getSourceCard().getName() + " - Looking at library", shown, ZoneType.Library, player);
!decider.hasKeyword("LimitSearchLibrary")
? player.getCardsIn(ZoneType.Library)
: player.getCardsIn(ZoneType.Library, fetchNum));
} }
// Look at opponents hand before moving onto choosing a card // Look at opponents hand before moving onto choosing a card
if (origin.contains(ZoneType.Hand) && player.isOpponentOf(decider)) { if (origin.contains(ZoneType.Hand) && player.isOpponentOf(decider)) {
GuiChoose.oneOrNone(sa.getSourceCard().getName() + " - Looking at Opponent's Hand", player decider.getController().reveal(sa.getSourceCard().getName() + " - Looking at Opponent's Hand", player.getCardsIn(ZoneType.Hand), ZoneType.Hand, player);
.getCardsIn(ZoneType.Hand));
} }
fetchList = AbilityUtils.filterListByType(fetchList, sa.getParam("ChangeType"), sa); fetchList = AbilityUtils.filterListByType(fetchList, sa.getParam("ChangeType"), sa);
} }
@@ -712,7 +711,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
final boolean champion = sa.hasParam("Champion"); final boolean champion = sa.hasParam("Champion");
final String forget = sa.getParam("ForgetChanged"); final String forget = sa.getParam("ForgetChanged");
final String imprint = sa.getParam("Imprint"); final String imprint = sa.getParam("Imprint");
final String selectPrompt = sa.hasParam("SelectPrompt") ? sa.getParam("SelectPrompt") : "Select a card"; final String selectPrompt = sa.hasParam("SelectPrompt") ? sa.getParam("SelectPrompt") : "Select a card from " + origin;
final String totalcmc = sa.getParam("WithTotalCMC"); final String totalcmc = sa.getParam("WithTotalCMC");
int totcmc = AbilityUtils.calculateAmount(card, totalcmc, sa); int totcmc = AbilityUtils.calculateAmount(card, totalcmc, sa);
@@ -735,15 +734,25 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
break; break;
} }
// card has to be on battlefield or in own hand
boolean canUseInputToSelectCard = origin.size() == 1 && ( origin.get(0) == ZoneType.Battlefield || origin.get(0) == ZoneType.Hand && player == decider);
Object o; Object o;
if (sa.hasParam("AtRandom")) { if (sa.hasParam("AtRandom")) {
o = Aggregates.random(fetchList); o = Aggregates.random(fetchList);
} else if (sa.hasParam("Mandatory")) {
o = GuiChoose.one(selectPrompt, fetchList);
} else if (sa.hasParam("Defined")) { } else if (sa.hasParam("Defined")) {
o = fetchList.get(0); o = fetchList.get(0);
} else { } else {
o = GuiChoose.oneOrNone(selectPrompt, fetchList); boolean mustChoose = sa.hasParam("Mandatory");
if( canUseInputToSelectCard ) {
InputSelectCardsFromList inp = new InputSelectCardsFromList(1, 1, fetchList);
inp.setCancelAllowed(!mustChoose);
inp.setMessage(selectPrompt);
FThreads.setInputAndWait(inp);
o = inp.getSelected().get(0);
}
else
o = GuiChoose.getChoices(selectPrompt, 0, mustChoose ? 1 : 0, fetchList);
} }
if (o != null) { if (o != null) {
@@ -887,7 +896,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
} }
} }
if (sa.hasParam("Reveal") && !movedCards.isEmpty()) { if (sa.hasParam("Reveal") && !movedCards.isEmpty()) {
GuiChoose.one(card + " - Revealed card: ", movedCards); decider.getController().reveal(card + " - Revealed card: ", movedCards, origin.get(0), player);
} }
if ((origin.contains(ZoneType.Library) && !destination.equals(ZoneType.Library) && !defined) if ((origin.contains(ZoneType.Library) && !destination.equals(ZoneType.Library) && !defined)

View File

@@ -20,7 +20,6 @@ package forge.card.staticability;
import java.util.HashMap; import java.util.HashMap;
import forge.Card; import forge.Card;
import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;

View File

@@ -54,7 +54,7 @@ class ZoneAction extends ForgeAction {
for (Card crd : choices) { for (Card crd : choices) {
Card toAdd = crd; Card toAdd = crd;
if (crd.isFaceDown()) { if (crd.isFaceDown()) {
if (crd.canBeSeenBy(Singletons.getControl().getLobby().getGuiPlayer().getPlayer(crd.getGame()))) { if (crd.canBeSeenBy(Singletons.getControl().getPlayer())) {
toAdd = CardFactory.copyCard(crd); toAdd = CardFactory.copyCard(crd);
toAdd.setState(CardCharacteristicName.Original); toAdd.setState(CardCharacteristicName.Original);
} else { } else {