From aa13b06af9ee71653715302334ae7ff7247a0416 Mon Sep 17 00:00:00 2001 From: jeffwadsworth Date: Fri, 5 Feb 2021 16:37:44 -0600 Subject: [PATCH] - refactored Ethereal Valkyrie to work with Split/MDFC/Adventure cards as per weirddan455 commit. --- .../src/mage/cards/e/EtherealValkyrie.java | 70 ++++++++--- ...etellSourceControllerTriggeredAbility.java | 111 +++++++++--------- 2 files changed, 110 insertions(+), 71 deletions(-) diff --git a/Mage.Sets/src/mage/cards/e/EtherealValkyrie.java b/Mage.Sets/src/mage/cards/e/EtherealValkyrie.java index 35b514066d..52bb5896af 100644 --- a/Mage.Sets/src/mage/cards/e/EtherealValkyrie.java +++ b/Mage.Sets/src/mage/cards/e/EtherealValkyrie.java @@ -10,9 +10,13 @@ import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.ForetellAbility; +import mage.cards.AdventureCard; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.cards.ModalDoubleFacesCard; +import mage.cards.ModalDoubleFacesCardHalf; +import mage.cards.SplitCard; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.SubType; @@ -125,22 +129,58 @@ class EtherealValkyrieEffect extends OneShotEffect { if (exileCard == null) { return false; } - String foretellCost = CardUtil.reduceCost(exileCard.getSpellAbility().getManaCostsToPay(), 2).getText(); - game.getState().setValue(exileCard.getId().toString() + "Foretell Cost", foretellCost); - game.getState().setValue(exileCard.getId().toString() + "Foretell Turn Number", game.getTurnNum()); - UUID exileId = CardUtil.getExileZoneId(exileCard.getId().toString() + "foretellAbility", game); - controller.moveCardsToExile(exileCard, source, game, true, exileId, " Foretell Turn Number: " + game.getTurnNum()); - exileCard.setFaceDown(true, game); - ForetellAbility foretellAbility = new ForetellAbility(exileCard, foretellCost); - foretellAbility.setSourceId(exileCard.getId()); - foretellAbility.setControllerId(exileCard.getOwnerId()); - game.getState().addOtherAbility(exileCard, foretellAbility); - foretellAbility.activate(game, true); - ContinuousEffect effect = foretellAbility.new ForetellAddCostEffect(new MageObjectReference(exileCard, game)); - game.addEffect(effect, source); - return true; + // process Split, MDFC, and Adventure cards first + // note that 'Foretell Cost' refers to the main card (left) and 'Foretell Split Cost' refers to the (right) card if it exists + ForetellAbility foretellAbility = null; + if (exileCard instanceof SplitCard) { + String leftHalfCost = CardUtil.reduceCost(((SplitCard) exileCard).getLeftHalfCard().getManaCost(), 2).getText(); + String rightHalfCost = CardUtil.reduceCost(((SplitCard) exileCard).getRightHalfCard().getManaCost(), 2).getText(); + game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Cost", leftHalfCost); + game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Split Cost", rightHalfCost); + foretellAbility = new ForetellAbility(exileCard, leftHalfCost, rightHalfCost); + } else if (exileCard instanceof ModalDoubleFacesCard) { + ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) exileCard).getLeftHalfCard(); + if (!leftHalfCard.isLand()) { + String leftHalfCost = CardUtil.reduceCost(leftHalfCard.getManaCost(), 2).getText(); + game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Cost", leftHalfCost); + ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) exileCard).getRightHalfCard(); + if (rightHalfCard.isLand()) { + foretellAbility = new ForetellAbility(exileCard, leftHalfCost); + } else { + String rightHalfCost = CardUtil.reduceCost(rightHalfCard.getManaCost(), 2).getText(); + game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Split Cost", rightHalfCost); + foretellAbility = new ForetellAbility(exileCard, leftHalfCost, rightHalfCost); + } + } + } else if (exileCard instanceof AdventureCard) { + String creatureCost = CardUtil.reduceCost(exileCard.getMainCard().getManaCost(), 2).getText(); + String spellCost = CardUtil.reduceCost(((AdventureCard) exileCard).getSpellCard().getManaCost(), 2).getText(); + game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Cost", creatureCost); + game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Split Cost", spellCost); + foretellAbility = new ForetellAbility(exileCard, creatureCost, spellCost); + } else { + // normal card + String costText = CardUtil.reduceCost(exileCard.getManaCost(), 2).getText(); + game.getState().setValue(exileCard.getId().toString() + "Foretell Cost", costText); + foretellAbility = new ForetellAbility(exileCard, costText); + } + // all done pre-processing so stick the foretell cost effect onto the main card + // note that the card is not foretell'd into exile, it is put into exile and made foretold + if (foretellAbility != null) { + game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Turn Number", game.getTurnNum()); + UUID exileId = CardUtil.getExileZoneId(exileCard.getMainCard().getId().toString() + "foretellAbility", game); + controller.moveCardsToExile(exileCard, source, game, true, exileId, " Foretell Turn Number: " + game.getTurnNum()); + exileCard.setFaceDown(true, game); + foretellAbility.setSourceId(exileCard.getId()); + foretellAbility.setControllerId(exileCard.getOwnerId()); + game.getState().addOtherAbility(exileCard, foretellAbility); + foretellAbility.activate(game, true); + ContinuousEffect effect = foretellAbility.new ForetellAddCostEffect(new MageObjectReference(exileCard, game)); + game.addEffect(effect, source); + return true; + } } } return false; } -} \ No newline at end of file +} diff --git a/Mage/src/main/java/mage/abilities/common/ForetellSourceControllerTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/ForetellSourceControllerTriggeredAbility.java index d4ae35ae4d..5250dfb92f 100644 --- a/Mage/src/main/java/mage/abilities/common/ForetellSourceControllerTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/ForetellSourceControllerTriggeredAbility.java @@ -1,56 +1,55 @@ -package mage.abilities.common; - -import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.Effect; -import mage.abilities.keyword.ForetellAbility; -import mage.cards.Card; -import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.players.Player; - -/** - * @author jeffwadsworth - */ -public class ForetellSourceControllerTriggeredAbility extends TriggeredAbilityImpl { - - public ForetellSourceControllerTriggeredAbility(Effect effect) { - super(Zone.BATTLEFIELD, effect, false); - } - - public ForetellSourceControllerTriggeredAbility(final ForetellSourceControllerTriggeredAbility ability) { - super(ability); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.TAKEN_SPECIAL_ACTION; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - //UUID specialAction = event.getTargetId(); - Card card = game.getCard(event.getSourceId()); - Player player = game.getPlayer(event.getPlayerId()); - if (card == null || player == null) { - return false; - } - - if (!isControlledBy(player.getId())) { - return false; - } - - return card.getAbilities(game).containsClass(ForetellAbility.class); - } - - @Override - public String getRule() { - return "Whenever you foretell a card, " + super.getRule(); - } - - @Override - public ForetellSourceControllerTriggeredAbility copy() { - return new ForetellSourceControllerTriggeredAbility(this); - } - -} +package mage.abilities.common; + +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.abilities.keyword.ForetellAbility; +import mage.cards.Card; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.players.Player; + +/** + * @author jeffwadsworth + */ +public class ForetellSourceControllerTriggeredAbility extends TriggeredAbilityImpl { + + public ForetellSourceControllerTriggeredAbility(Effect effect) { + super(Zone.BATTLEFIELD, effect, false); + } + + public ForetellSourceControllerTriggeredAbility(final ForetellSourceControllerTriggeredAbility ability) { + super(ability); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.TAKEN_SPECIAL_ACTION; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + Card card = game.getCard(event.getSourceId()); + Player player = game.getPlayer(event.getPlayerId()); + if (card == null || player == null) { + return false; + } + + if (!isControlledBy(player.getId())) { + return false; + } + + return card.getAbilities(game).containsClass(ForetellAbility.class); + } + + @Override + public String getRule() { + return "Whenever you foretell a card, " + super.getRule(); + } + + @Override + public ForetellSourceControllerTriggeredAbility copy() { + return new ForetellSourceControllerTriggeredAbility(this); + } + +}