Search in sources :

Example 1 with SplitCardHalf

use of mage.cards.SplitCardHalf 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 SplitCardHalf

use of mage.cards.SplitCardHalf 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 3 with SplitCardHalf

use of mage.cards.SplitCardHalf 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)3 ModalDoubleFacesCardHalf (mage.cards.ModalDoubleFacesCardHalf)3 SplitCardHalf (mage.cards.SplitCardHalf)3 UUID (java.util.UUID)2 AdventureCard (mage.cards.AdventureCard)2 ModalDoubleFacesCard (mage.cards.ModalDoubleFacesCard)2 SplitCard (mage.cards.SplitCard)2 Player (mage.players.Player)2 ApprovingObject (mage.ApprovingObject)1 Ability (mage.abilities.Ability)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 Costs (mage.abilities.costs.Costs)1 RetraceAbility (mage.abilities.keyword.RetraceAbility)1 CardsImpl (mage.cards.CardsImpl)1 ZoneChangeEvent (mage.game.events.ZoneChangeEvent)1 Spell (mage.game.stack.Spell)1