- AF Play now works with modal spells and spells with timing restrictions (like "Cast CARDNAME only during combat.").

This commit is contained in:
Sloth
2012-02-18 10:25:49 +00:00
parent de20212f43
commit 212a3d16b7
2 changed files with 64 additions and 23 deletions

View File

@@ -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<SpellAbility> sas = tgtCard.getBasicSpells();
// get basic spells (no flashback, etc.)
ArrayList<SpellAbility> SpellAbilities = tgtCard.getBasicSpells();
ArrayList<SpellAbility> sas = new ArrayList<SpellAbility>();
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()) {

View File

@@ -207,6 +207,46 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
return true;
}
/**
* <p>
* checkZoneRestrictions.
* </p>
* @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;
}
/**
* <p>
@@ -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;