Search in sources :

Example 6 with FilterInstantOrSorceryCard

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

the class EpicExperimentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        // move cards from library to exile
        controller.moveCardsToExile(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()), source, game, true, source.getSourceId(), sourceObject.getIdName());
        // cast the possible cards without paying the mana
        ExileZone epicExperimentExileZone = game.getExile().getExileZone(source.getSourceId());
        FilterCard filter = new FilterInstantOrSorceryCard();
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
        filter.setMessage("instant and sorcery cards with mana value " + source.getManaCostsToPay().getX() + " or less");
        Cards cardsToCast = new CardsImpl();
        if (epicExperimentExileZone == null) {
            return true;
        }
        cardsToCast.addAll(epicExperimentExileZone.getCards(filter, source.getSourceId(), source.getControllerId(), game));
        while (controller.canRespond() && !cardsToCast.isEmpty()) {
            if (!controller.chooseUse(Outcome.PlayForFree, "Cast (another) a card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
                break;
            }
            TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("instant or sorcery card to cast for free"));
            if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
                Card card = game.getCard(targetCard.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);
                    if (!cardWasCast) {
                        game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
                    }
                    cardsToCast.remove(card);
                } else {
                    break;
                }
            } else {
                break;
            }
        }
        // move cards not cast to graveyard
        ExileZone exileZone = game.getExile().getExileZone(source.getSourceId());
        if (exileZone != null) {
            controller.moveCards(exileZone.getCards(game), Zone.GRAVEYARD, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard)

Example 7 with FilterInstantOrSorceryCard

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

the class KasminaEnigmaSageSearchEffect 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;
    }
    FilterCard filter = new FilterInstantOrSorceryCard("an instant, or sorcery card which shares a color with " + permanent.getLogName());
    filter.add(new SharesColorPredicate(permanent.getColor(game)));
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    controller.searchLibrary(target, source, game);
    Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
    if (card != null) {
        controller.moveCards(card, Zone.EXILED, source, game);
    }
    controller.shuffleLibrary(source, game);
    if (card == null || !controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
        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);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) SharesColorPredicate(mage.filter.predicate.mageobject.SharesColorPredicate) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 8 with FilterInstantOrSorceryCard

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

the class MissionBriefingReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.surveil(2, source, game);
    Target target = new TargetCardInYourGraveyard(new FilterInstantOrSorceryCard("instant or sorcery card from your graveyard"));
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return true;
    }
    Card card = game.getCard(target.getFirstTarget());
    if (card != null) {
        ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect();
        effect.setTargetPointer(new FixedTarget(card, game));
        game.addEffect(effect, source);
        effect = new MissionBriefingReplacementEffect(card.getId());
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 9 with FilterInstantOrSorceryCard

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

the class MuseVortexEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
    controller.moveCards(cards, Zone.EXILED, source, game);
    cards.retainZone(Zone.EXILED, game);
    FilterCard filter = new FilterInstantOrSorceryCard("an instant or sorcery card with mana value " + xValue + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCardInExile target = new TargetCardInExile(filter);
    target.setNotTarget(true);
    if (controller.choose(Outcome.Benefit, cards, target, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        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);
            cards.remove(card);
            if (cardWasCast) {
                cards.remove(card);
            } else {
                game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
            }
            controller.putCardsOnTopOfLibrary(cards, game, source, true);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCardInExile(mage.target.common.TargetCardInExile) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard)

Example 10 with FilterInstantOrSorceryCard

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

the class ReversalOfFortuneEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (controller != null && opponent != null) {
        // Target opponent reveals their hand
        Cards revealedCards = new CardsImpl();
        revealedCards.addAll(opponent.getHand());
        opponent.revealCards("Reveal", revealedCards, game);
        // You may copy an instant or sorcery card in it
        TargetCard target = new TargetCard(1, Zone.HAND, new FilterInstantOrSorceryCard());
        target.setRequired(false);
        if (controller.choose(Outcome.PlayForFree, revealedCards, target, game)) {
            Card card = revealedCards.get(target.getFirstTarget(), game);
            // If you do, you may cast the copy without paying its mana cost
            if (card != null) {
                Card copiedCard = game.copyCard(card, source, source.getControllerId());
                if (controller.chooseUse(Outcome.PlayForFree, "Cast the copied card without paying mana cost?", source, game)) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
                }
            } else {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) 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