Search in sources :

Example 1 with ForetellAbility

use of mage.abilities.keyword.ForetellAbility in project mage by magefree.

the class DreamDevourerAddAbilityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    for (Card card : controller.getHand().getCards(filter, game)) {
        ForetellAbility foretellAbility = null;
        if (card instanceof SplitCard) {
            String leftHalfCost = CardUtil.reduceCost(((SplitCard) card).getLeftHalfCard().getManaCost(), 2).getText();
            String rightHalfCost = CardUtil.reduceCost(((SplitCard) card).getRightHalfCard().getManaCost(), 2).getText();
            foretellAbility = new ForetellAbility(card, leftHalfCost, rightHalfCost);
        } else if (card instanceof ModalDoubleFacesCard) {
            ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
            // MDFC cards in hand are considered lands if front side is land
            if (!leftHalfCard.isLand(game)) {
                String leftHalfCost = CardUtil.reduceCost(leftHalfCard.getManaCost(), 2).getText();
                ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
                if (rightHalfCard.isLand(game)) {
                    foretellAbility = new ForetellAbility(card, leftHalfCost);
                } else {
                    String rightHalfCost = CardUtil.reduceCost(rightHalfCard.getManaCost(), 2).getText();
                    foretellAbility = new ForetellAbility(card, leftHalfCost, rightHalfCost);
                }
            }
        } else if (card instanceof AdventureCard) {
            String creatureCost = CardUtil.reduceCost(card.getMainCard().getManaCost(), 2).getText();
            String spellCost = CardUtil.reduceCost(((AdventureCard) card).getSpellCard().getManaCost(), 2).getText();
            foretellAbility = new ForetellAbility(card, creatureCost, spellCost);
        } else {
            String costText = CardUtil.reduceCost(card.getManaCost(), 2).getText();
            foretellAbility = new ForetellAbility(card, costText);
        }
        if (foretellAbility != null) {
            foretellAbility.setSourceId(card.getId());
            foretellAbility.setControllerId(card.getOwnerId());
            game.getState().addOtherAbility(card, foretellAbility);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) ForetellAbility(mage.abilities.keyword.ForetellAbility) FilterNonlandCard(mage.filter.common.FilterNonlandCard)

Example 2 with ForetellAbility

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

Aggregations

ForetellAbility (mage.abilities.keyword.ForetellAbility)2 Player (mage.players.Player)2 UUID (java.util.UUID)1 MageObjectReference (mage.MageObjectReference)1 Ability (mage.abilities.Ability)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 FlyingAbility (mage.abilities.keyword.FlyingAbility)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 FilterCard (mage.filter.FilterCard)1 FilterNonlandCard (mage.filter.common.FilterNonlandCard)1 TargetCardInHand (mage.target.common.TargetCardInHand)1