Search in sources :

Example 1 with RetraceAbility

use of mage.abilities.keyword.RetraceAbility 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

UUID (java.util.UUID)1 Ability (mage.abilities.Ability)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 RetraceAbility (mage.abilities.keyword.RetraceAbility)1 AdventureCard (mage.cards.AdventureCard)1 Card (mage.cards.Card)1 ModalDoubleFacesCard (mage.cards.ModalDoubleFacesCard)1 ModalDoubleFacesCardHalf (mage.cards.ModalDoubleFacesCardHalf)1 SplitCard (mage.cards.SplitCard)1 SplitCardHalf (mage.cards.SplitCardHalf)1 Player (mage.players.Player)1