* Maelstrom Archangel - Fixed that more than one spell could be cast after the ability had triggered.

This commit is contained in:
LevelX2 2013-08-11 15:59:48 +02:00
parent 1a3d35ef30
commit c4d82655b5

View file

@ -30,23 +30,20 @@ package mage.sets.conflux;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
import mage.abilities.effects.CostModificationEffectImpl; import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.FlashbackAbility;
import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.FlyingAbility;
import mage.abilities.keyword.RetraceAbility;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.filter.FilterCard;
import mage.filter.common.FilterNonlandCard;
import mage.game.Game; import mage.game.Game;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.players.Player; import mage.players.Player;
import mage.target.Target;
import mage.target.common.TargetCardInHand;
/** /**
* *
@ -71,7 +68,7 @@ public class MaelstromArchangel extends CardImpl<MaelstromArchangel> {
this.addAbility(FlyingAbility.getInstance()); this.addAbility(FlyingAbility.getInstance());
// Whenever Maelstrom Archangel deals combat damage to a player, you may cast a nonland card from your hand without paying its mana cost. // Whenever Maelstrom Archangel deals combat damage to a player, you may cast a nonland card from your hand without paying its mana cost.
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new MaelstromArchangelEffect(), true)); this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new MaelstromArchangelCastEffect(), false));
} }
@ -85,48 +82,50 @@ public class MaelstromArchangel extends CardImpl<MaelstromArchangel> {
} }
} }
class MaelstromArchangelEffect extends CostModificationEffectImpl<MaelstromArchangelEffect> { class MaelstromArchangelCastEffect extends OneShotEffect<MaelstromArchangelCastEffect> {
public MaelstromArchangelEffect() { private static final FilterCard filter = new FilterNonlandCard("nonland card from your hand");
super(Duration.WhileOnBattlefield, Outcome.PlayForFree);
staticText = "You may cast nonland cards from your hand without paying their mana costs"; public MaelstromArchangelCastEffect() {
super(Outcome.PlayForFree);
this.staticText = "you may cast a nonland card from your hand without paying its mana cost";
} }
private MaelstromArchangelEffect(final MaelstromArchangelEffect effect) { public MaelstromArchangelCastEffect(final MaelstromArchangelCastEffect effect) {
super(effect); super(effect);
} }
@Override @Override
public boolean apply(Game game, Ability source, Ability abilityToModify) { public MaelstromArchangelCastEffect copy() {
SpellAbility spellAbility = (SpellAbility) abilityToModify; return new MaelstromArchangelCastEffect(this);
spellAbility.getManaCostsToPay().clear();
return true;
} }
@Override @Override
public boolean applies(Ability abilityToModify, Ability source, Game game) { public boolean apply(Game game, Ability source) {
if (abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility || abilityToModify instanceof RetraceAbility) { Player controller = game.getPlayer(source.getControllerId());
Card sourceCard = game.getCard(abilityToModify.getSourceId()); if (controller != null) {
StackObject stackObject = game.getStack().getStackObject(abilityToModify.getSourceId()); Target target = new TargetCardInHand(filter);
if (stackObject != null && stackObject instanceof Spell) { target.setRequired(true);
Zone zone = ((Spell)stackObject).getFromZone(); if (target.canChoose(source.getSourceId(), controller.getId(), game) &&
if (zone != null && zone.equals(Zone.HAND)) { controller.chooseUse(outcome, "Cast a nonland card from your hand without paying its mana cost?", game)) {
if (sourceCard != null && sourceCard.getOwnerId().equals(source.getControllerId()) Card cardToCast = null;
&& !sourceCard.getCardType().contains(CardType.LAND)) { boolean cancel = false;
Player you = game.getPlayer(source.getControllerId()); while (!cancel) {
String message = "Cast " + sourceCard.getName() + " without paying its mana costs?"; if (controller.chooseTarget(outcome, target, source, game)) {
if (you != null && you.chooseUse(Outcome.PlayForFree, message, game)) { cardToCast = game.getCard(target.getFirstTarget());
return true; if (cardToCast != null && cardToCast.getSpellAbility().canChooseTarget(game)) {
cancel = true;
} }
} else {
cancel = true;
} }
} }
if (cardToCast != null) {
controller.cast(cardToCast.getSpellAbility(), game, true);
}
} }
return true;
} }
return false; return false;
} }
@Override
public MaelstromArchangelEffect copy() {
return new MaelstromArchangelEffect(this);
}
} }