Search in sources :

Example 1 with FilterInstantOrSorceryCard

use of mage.filter.common.FilterInstantOrSorceryCard in project mage by magefree.

the class JelevaNephaliasWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
        if (exileZone != null && exileZone.count(new FilterInstantOrSorceryCard(), game) > 0) {
            if (controller.chooseUse(outcome, "Cast an instant or sorcery card from " + "exile without paying its mana cost?", source, game)) {
                TargetCardInExile target = new TargetCardInExile(new FilterInstantOrSorceryCard(), CardUtil.getCardExileZoneId(game, source));
                if (controller.choose(Outcome.PlayForFree, exileZone, target, game)) {
                    Card card = game.getCard(target.getFirstTarget());
                    if (card != null) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                        Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                        return cardWasCast;
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCardInExile(mage.target.common.TargetCardInExile) ExileZone(mage.game.ExileZone) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 2 with FilterInstantOrSorceryCard

use of mage.filter.common.FilterInstantOrSorceryCard in project mage by magefree.

the class GoblinTutorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int amount = controller.rollDice(outcome, source, game, 6);
        Effect effect = null;
        // 6 - An instant or sorcery card
        if (amount == 2) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, filter), true);
        } else if (amount == 3) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_ENTCHANTMENT), true);
        } else if (amount == 4) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_ARTIFACT), true);
        } else if (amount == 5) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_CREATURE), true);
        } else if (amount == 6) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, new FilterInstantOrSorceryCard()), true);
        }
        if (effect != null) {
            effect.apply(game, source);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 3 with FilterInstantOrSorceryCard

use of mage.filter.common.FilterInstantOrSorceryCard in project mage by magefree.

the class AugurOfBolasEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        Cards topCards = new CardsImpl();
        topCards.addAll(controller.getLibrary().getTopCards(game, 3));
        if (!topCards.isEmpty()) {
            controller.lookAtCards(sourceObject.getIdName(), topCards, game);
            int number = topCards.count(new FilterInstantOrSorceryCard(), source.getSourceId(), source.getControllerId(), game);
            if (number > 0) {
                if (controller.chooseUse(outcome, "Reveal an instant or sorcery card from the looked at cards and put it into your hand?", source, game)) {
                    Card card = null;
                    if (number == 1) {
                        Set<Card> cards = topCards.getCards(new FilterInstantOrSorceryCard(), source.getSourceId(), source.getControllerId(), game);
                        if (!cards.isEmpty()) {
                            card = cards.iterator().next();
                        }
                    } else {
                        TargetCard target = new TargetCard(Zone.LIBRARY, new FilterInstantOrSorceryCard());
                        controller.chooseTarget(outcome, topCards, target, source, game);
                        card = topCards.get(target.getFirstTarget(), game);
                    }
                    if (card != null) {
                        controller.moveCards(card, Zone.HAND, source, game);
                        controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
                        topCards.remove(card);
                    }
                }
            }
            controller.putCardsOnBottomOfLibrary(topCards, game, source, true);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard)

Example 4 with FilterInstantOrSorceryCard

use of mage.filter.common.FilterInstantOrSorceryCard in project mage by magefree.

the class VelomachusLoreholdEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentOrLKI(game);
    if (controller == null || permanent == null) {
        return false;
    }
    Set<Card> cardsSet = controller.getLibrary().getTopCards(game, 7);
    Cards cards = new CardsImpl(cardsSet);
    FilterCard filter = new FilterInstantOrSorceryCard("instant or sorcery card with mana value " + permanent.getPower().getValue() + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getPower().getValue() + 1));
    TargetCard target = new TargetCardInLibrary(0, 1, filter);
    controller.choose(Outcome.PlayForFree, cards, target, game);
    Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
    if (card == null) {
        controller.putCardsOnBottomOfLibrary(cards, game, source, false);
        return true;
    }
    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
    Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
    if (cardWasCast) {
        cards.remove(card);
    }
    controller.putCardsOnBottomOfLibrary(cards, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) FilterCard(mage.filter.FilterCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate)

Example 5 with FilterInstantOrSorceryCard

use of mage.filter.common.FilterInstantOrSorceryCard in project mage by magefree.

the class WildfireEternalCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        FilterCard filter = new FilterInstantOrSorceryCard();
        int cardsToCast = controller.getHand().count(filter, source.getControllerId(), source.getSourceId(), game);
        if (cardsToCast > 0 && controller.chooseUse(outcome, "Cast an instant or sorcery card from your " + "hand without paying its mana cost?", source, game)) {
            TargetCardInHand target = new TargetCardInHand(filter);
            controller.chooseTarget(outcome, target, source, game);
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Aggregations

FilterInstantOrSorceryCard (mage.filter.common.FilterInstantOrSorceryCard)11 Player (mage.players.Player)11 ApprovingObject (mage.ApprovingObject)8 FilterCard (mage.filter.FilterCard)7 Card (mage.cards.Card)6 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)4 TargetCard (mage.target.TargetCard)4 Permanent (mage.game.permanent.Permanent)3 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)3 MageObject (mage.MageObject)2 ExileZone (mage.game.ExileZone)2 TargetCardInExile (mage.target.common.TargetCardInExile)2 TargetCardInHand (mage.target.common.TargetCardInHand)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 PlayFromNotOwnHandZoneTargetEffect (mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect)1 SearchLibraryPutInHandEffect (mage.abilities.effects.common.search.SearchLibraryPutInHandEffect)1 Cards (mage.cards.Cards)1 CardsImpl (mage.cards.CardsImpl)1