Search in sources :

Example 1 with ModalDoubleFacesCardHalf

use of mage.cards.ModalDoubleFacesCardHalf in project mage by magefree.

the class JourneyToTheOracleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = controller.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    controller.revealCards(source, new CardsImpl(card), game);
    if (card.isLand(game)) {
        // note that MDFC land cards are handled differently: they can't be moved
        return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    // query player
    if (!controller.chooseUse(outcome, "Cast " + card.getName() + " by paying {1}?", source, game)) {
        return false;
    }
    // handle split-cards
    if (card instanceof SplitCard) {
        SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
        SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
        // get additional cost if any
        Costs additionalCostsLeft = leftHalfCard.getSpellAbility().getCosts();
        Costs additionalCostsRight = rightHalfCard.getSpellAbility().getCosts();
        // set alternative cost and any additional cost
        controller.setCastSourceIdWithAlternateMana(leftHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsLeft);
        controller.setCastSourceIdWithAlternateMana(rightHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsRight);
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), Boolean.TRUE);
    }
    // handle MDFC
    if (card instanceof ModalDoubleFacesCard) {
        ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
        ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
        // some MDFC cards are lands.  IE: sea gate restoration
        if (!leftHalfCard.isLand(game)) {
            // get additional cost if any
            Costs additionalCostsMDFCLeft = leftHalfCard.getSpellAbility().getCosts();
            // set alternative cost and any additional cost
            controller.setCastSourceIdWithAlternateMana(leftHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsMDFCLeft);
        }
        if (!rightHalfCard.isLand(game)) {
            // get additional cost if any
            Costs additionalCostsMDFCRight = rightHalfCard.getSpellAbility().getCosts();
            // set alternative cost and any additional cost
            controller.setCastSourceIdWithAlternateMana(rightHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsMDFCRight);
        }
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), Boolean.TRUE);
    }
    // handle adventure cards
    if (card instanceof AdventureCard) {
        Card creatureCard = card.getMainCard();
        Card spellCard = ((AdventureCard) card).getSpellCard();
        // get additional cost if any
        Costs additionalCostsCreature = creatureCard.getSpellAbility().getCosts();
        Costs additionalCostsSpellCard = spellCard.getSpellAbility().getCosts();
        // set alternative cost and any additional cost
        controller.setCastSourceIdWithAlternateMana(creatureCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsCreature);
        controller.setCastSourceIdWithAlternateMana(spellCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsSpellCard);
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + creatureCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + spellCard.getId(), Boolean.TRUE);
    }
    // normal card
    if (!(card instanceof SplitCard) || !(card instanceof ModalDoubleFacesCard) || !(card instanceof AdventureCard)) {
        // get additional cost if any
        Costs additionalCostsNormalCard = card.getSpellAbility().getCosts();
        controller.setCastSourceIdWithAlternateMana(card.getMainCard().getId(), new ManaCostsImpl<>("{1}"), additionalCostsNormalCard);
    }
    // cast it
    controller.cast(controller.chooseAbilityForCast(card.getMainCard(), game, false), game, false, new ApprovingObject(source, game));
    // turn off effect after cast on every possible card-face
    if (card instanceof SplitCard) {
        SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
        SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), null);
    }
    if (card instanceof ModalDoubleFacesCard) {
        ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
        ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), null);
    }
    if (card instanceof AdventureCard) {
        Card creatureCard = card.getMainCard();
        Card spellCard = ((AdventureCard) card).getSpellCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + creatureCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + spellCard.getId(), null);
    }
    // turn off effect on a normal card
    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
    return true;
}
Also used : Player(mage.players.Player) Costs(mage.abilities.costs.Costs) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) ApprovingObject(mage.ApprovingObject) ModalDoubleFacesCardHalf(mage.cards.ModalDoubleFacesCardHalf) SplitCardHalf(mage.cards.SplitCardHalf) CardsImpl(mage.cards.CardsImpl) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) AdventureCard(mage.cards.AdventureCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard)

Example 2 with ModalDoubleFacesCardHalf

use of mage.cards.ModalDoubleFacesCardHalf in project mage by magefree.

the class EtherealValkyrieEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        controller.drawCards(1, source, game);
        TargetCardInHand targetCard = new TargetCardInHand(new FilterCard("card to exile face down. It becomes foretold."));
        if (controller.chooseTarget(Outcome.Benefit, targetCard, source, game)) {
            Card exileCard = game.getCard(targetCard.getFirstTarget());
            if (exileCard == null) {
                return false;
            }
            // 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(game)) {
                    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(game)) {
                        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);
            }
            // note that the card is not foretell'd into exile, it is put into exile and made foretold
            if (foretellAbility != null) {
                // copy source and use it for the foretold effect on the exiled card
                // bug #8673
                Ability copiedSource = source.copy();
                copiedSource.newId();
                copiedSource.setSourceId(exileCard.getId());
                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, copiedSource);
                game.fireEvent(GameEvent.getEvent(GameEvent.EventType.FORETOLD, exileCard.getId(), null, null));
                return true;
            }
        }
    }
    return false;
}
Also used : FlyingAbility(mage.abilities.keyword.FlyingAbility) ForetellAbility(mage.abilities.keyword.ForetellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) ForetellAbility(mage.abilities.keyword.ForetellAbility) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) AdventureCard(mage.cards.AdventureCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) FilterCard(mage.filter.FilterCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) ModalDoubleFacesCardHalf(mage.cards.ModalDoubleFacesCardHalf) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Example 3 with ModalDoubleFacesCardHalf

use of mage.cards.ModalDoubleFacesCardHalf in project mage by magefree.

the class AftermathExileAsResolvesFromGraveyard method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.getFromZone() == Zone.STACK && zEvent.getToZone() != Zone.EXILED) {
        // Moving something from stack to somewhere else
        // Get the source id, getting the whole split card's ID, because
        // that's the card that is changing zones in the event, but
        // source.getSourceId is only the split card half.
        // If branch so that we also support putting Aftermath on
        // non-split cards for... whatever reason, in case somebody
        // wants to do that in the future.
        UUID sourceId = source.getSourceId();
        Card sourceCard = game.getCard(source.getSourceId());
        if (sourceCard instanceof SplitCardHalf) {
            sourceCard = ((SplitCardHalf) sourceCard).getParentCard();
            sourceId = sourceCard.getId();
        }
        if (sourceCard instanceof ModalDoubleFacesCardHalf) {
            sourceCard = ((ModalDoubleFacesCardHalf) sourceCard).getParentCard();
            sourceId = sourceCard.getId();
        }
        if (zEvent.getTargetId().equals(sourceId)) {
            // Moving this spell from stack to yard
            Spell spell = game.getStack().getSpell(source.getSourceId());
            // And this spell was cast from the graveyard, so we need to exile it
            return spell != null && spell.getFromZone() == Zone.GRAVEYARD;
        }
    }
    return false;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) ModalDoubleFacesCardHalf(mage.cards.ModalDoubleFacesCardHalf) SplitCardHalf(mage.cards.SplitCardHalf) UUID(java.util.UUID) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 4 with ModalDoubleFacesCardHalf

use of mage.cards.ModalDoubleFacesCardHalf in project mage by magefree.

the class WrennAndSixEmblemEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    for (UUID cardId : controller.getGraveyard()) {
        Card card = game.getCard(cardId);
        if (card == null) {
            continue;
        }
        if (card instanceof SplitCard) {
            SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
            SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
            if (leftHalfCard.isInstantOrSorcery(game)) {
                Ability ability = new RetraceAbility(leftHalfCard);
                ability.setSourceId(cardId);
                ability.setControllerId(leftHalfCard.getOwnerId());
                game.getState().addOtherAbility(leftHalfCard, ability);
            }
            if (rightHalfCard.isInstantOrSorcery(game)) {
                Ability ability = new RetraceAbility(rightHalfCard);
                ability.setSourceId(cardId);
                ability.setControllerId(rightHalfCard.getOwnerId());
                game.getState().addOtherAbility(rightHalfCard, ability);
            }
        }
        if (card instanceof ModalDoubleFacesCard) {
            ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
            ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
            if (leftHalfCard.isInstantOrSorcery(game)) {
                Ability ability = new RetraceAbility(leftHalfCard);
                ability.setSourceId(cardId);
                ability.setControllerId(leftHalfCard.getOwnerId());
                game.getState().addOtherAbility(leftHalfCard, ability);
            }
            if (rightHalfCard.isInstantOrSorcery(game)) {
                Ability ability = new RetraceAbility(rightHalfCard);
                ability.setSourceId(cardId);
                ability.setControllerId(rightHalfCard.getOwnerId());
                game.getState().addOtherAbility(rightHalfCard, ability);
            }
        }
        if (card instanceof AdventureCard) {
            // Adventure cards are castable per https://twitter.com/elishffrn/status/1179047911729946624
            card = ((AdventureCard) card).getSpellCard();
        }
        if (!card.isInstantOrSorcery(game)) {
            continue;
        }
        Ability ability = new RetraceAbility(card);
        ability.setSourceId(cardId);
        ability.setControllerId(card.getOwnerId());
        game.getState().addOtherAbility(card, ability);
    }
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) RetraceAbility(mage.abilities.keyword.RetraceAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) RetraceAbility(mage.abilities.keyword.RetraceAbility) ModalDoubleFacesCardHalf(mage.cards.ModalDoubleFacesCardHalf) SplitCardHalf(mage.cards.SplitCardHalf) UUID(java.util.UUID) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) AdventureCard(mage.cards.AdventureCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card)

Aggregations

Card (mage.cards.Card)4 ModalDoubleFacesCardHalf (mage.cards.ModalDoubleFacesCardHalf)4 UUID (java.util.UUID)3 AdventureCard (mage.cards.AdventureCard)3 ModalDoubleFacesCard (mage.cards.ModalDoubleFacesCard)3 SplitCard (mage.cards.SplitCard)3 SplitCardHalf (mage.cards.SplitCardHalf)3 Player (mage.players.Player)3 Ability (mage.abilities.Ability)2 ApprovingObject (mage.ApprovingObject)1 MageObjectReference (mage.MageObjectReference)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 Costs (mage.abilities.costs.Costs)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 FlyingAbility (mage.abilities.keyword.FlyingAbility)1 ForetellAbility (mage.abilities.keyword.ForetellAbility)1 RetraceAbility (mage.abilities.keyword.RetraceAbility)1 CardsImpl (mage.cards.CardsImpl)1 FilterCard (mage.filter.FilterCard)1 ZoneChangeEvent (mage.game.events.ZoneChangeEvent)1