mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
- AF Play now works with modal spells and spells with timing restrictions (like "Cast CARDNAME only during combat.").
This commit is contained in:
@@ -39,6 +39,7 @@ import forge.card.spellability.AbilityActivated;
|
|||||||
import forge.card.spellability.AbilitySub;
|
import forge.card.spellability.AbilitySub;
|
||||||
import forge.card.spellability.Spell;
|
import forge.card.spellability.Spell;
|
||||||
import forge.card.spellability.SpellAbility;
|
import forge.card.spellability.SpellAbility;
|
||||||
|
import forge.card.spellability.SpellAbilityRestriction;
|
||||||
import forge.card.spellability.Target;
|
import forge.card.spellability.Target;
|
||||||
import forge.gui.GuiUtils;
|
import forge.gui.GuiUtils;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
@@ -365,16 +366,35 @@ public final class AbilityFactoryPlay {
|
|||||||
&& !GameActionUtil.showYesNoDialog(source, sb.toString())) {
|
&& !GameActionUtil.showYesNoDialog(source, sb.toString())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// lands will be played
|
||||||
if (tgtCard.isLand()) {
|
if (tgtCard.isLand()) {
|
||||||
controller.playLand(tgtCard);
|
controller.playLand(tgtCard);
|
||||||
return;
|
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()) {
|
if (sas.isEmpty()) {
|
||||||
return;
|
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 (params.containsKey("WithoutManaCost")) {
|
||||||
if (controller.isHuman()) {
|
if (controller.isHuman()) {
|
||||||
|
|||||||
@@ -208,6 +208,46 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
|
|||||||
return true;
|
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>
|
* <p>
|
||||||
* canPlay.
|
* canPlay.
|
||||||
@@ -244,11 +284,7 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isPlayerTurn() && !AllZone.getPhaseHandler().isPlayerTurn(activator)) {
|
if (!checkTimingRestrictions(c, sa)) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isOpponentTurn() && AllZone.getPhaseHandler().isPlayerTurn(activator)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,21 +297,6 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
|
|||||||
return false;
|
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 (this.getCardsInHand() != -1) {
|
||||||
if (activator.getCardsIn(Zone.Hand).size() != this.getCardsInHand()) {
|
if (activator.getCardsIn(Zone.Hand).size() != this.getCardsInHand()) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user