diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java index 0fea24e9805..7f9a60a2e32 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java @@ -39,6 +39,7 @@ import forge.card.spellability.AbilityActivated; import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; +import forge.card.spellability.SpellAbilityRestriction; import forge.card.spellability.Target; import forge.gui.GuiUtils; import forge.util.MyRandom; @@ -365,16 +366,35 @@ public final class AbilityFactoryPlay { && !GameActionUtil.showYesNoDialog(source, sb.toString())) { return; } + // lands will be played if (tgtCard.isLand()) { controller.playLand(tgtCard); return; } - ArrayList sas = tgtCard.getBasicSpells(); + // get basic spells (no flashback, etc.) + ArrayList SpellAbilities = tgtCard.getBasicSpells(); + ArrayList sas = new ArrayList(); + for (SpellAbility s : SpellAbilities) { + s.setActivatingPlayer(controller); + SpellAbilityRestriction res = s.getRestrictions(); + // timing restrictions still apply + if (res.checkTimingRestrictions(tgtCard, s)) { + sas.add(s); + } + } if (sas.isEmpty()) { return; } - SpellAbility tgtSA = sas.get(0); + SpellAbility tgtSA = null; + // only one mode can be used + if (sas.size() == 1) { + tgtSA = sas.get(0); + } else if (sa.getActivatingPlayer().isHuman()) { + tgtSA = (SpellAbility) GuiUtils.getChoice("Select a spell to cast", sas.toArray()); + } else { + tgtSA = sas.get(0); + } if (params.containsKey("WithoutManaCost")) { if (controller.isHuman()) { diff --git a/src/main/java/forge/card/spellability/SpellAbilityRestriction.java b/src/main/java/forge/card/spellability/SpellAbilityRestriction.java index be2f534a755..6bbad7c1fec 100644 --- a/src/main/java/forge/card/spellability/SpellAbilityRestriction.java +++ b/src/main/java/forge/card/spellability/SpellAbilityRestriction.java @@ -207,6 +207,46 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { return true; } + + /** + *

+ * checkZoneRestrictions. + *

+ * @param c + * a {@link forge.Card} object. + * @param sa + * a {@link forge.card.spellability.SpellAbility} object. + * @return a boolean. + */ + public final boolean checkTimingRestrictions(final Card c, final SpellAbility sa) { + Player activator = sa.getActivatingPlayer(); + + if (this.isPlayerTurn() && !AllZone.getPhaseHandler().isPlayerTurn(activator)) { + return false; + } + + if (this.isOpponentTurn() && AllZone.getPhaseHandler().isPlayerTurn(activator)) { + return false; + } + + if (this.getPhases().size() > 0) { + boolean isPhase = false; + final String currPhase = AllZone.getPhaseHandler().getPhase(); + for (final String s : this.getPhases()) { + if (s.equals(currPhase)) { + isPhase = true; + break; + } + } + + if (!isPhase) { + return false; + } + } + + + return true; + } /** *

@@ -243,12 +283,8 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { if (this.isSorcerySpeed() && !PhaseHandler.canCastSorcery(activator)) { return false; } - - if (this.isPlayerTurn() && !AllZone.getPhaseHandler().isPlayerTurn(activator)) { - return false; - } - - if (this.isOpponentTurn() && AllZone.getPhaseHandler().isPlayerTurn(activator)) { + + if (!checkTimingRestrictions(c, sa)) { return false; } @@ -261,21 +297,6 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { return false; } - if (this.getPhases().size() > 0) { - boolean isPhase = false; - final String currPhase = AllZone.getPhaseHandler().getPhase(); - for (final String s : this.getPhases()) { - if (s.equals(currPhase)) { - isPhase = true; - break; - } - } - - if (!isPhase) { - return false; - } - } - if (this.getCardsInHand() != -1) { if (activator.getCardsIn(Zone.Hand).size() != this.getCardsInHand()) { return false;