Search in sources :

Example 6 with FilterNonlandCard

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

the class MindleechMassEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (opponent != null && controller != null) {
        Cards cardsInHand = new CardsImpl();
        cardsInHand.addAll(opponent.getHand());
        opponent.revealCards("Opponents hand", cardsInHand, game);
        if (!cardsInHand.isEmpty() && !cardsInHand.getCards(new FilterNonlandCard(), game).isEmpty()) {
            TargetCard target = new TargetCard(1, Zone.HAND, new FilterNonlandCard());
            if (controller.chooseTarget(Outcome.PlayForFree, cardsInHand, 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 : Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) ApprovingObject(mage.ApprovingObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 7 with FilterNonlandCard

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

the class SvellaIceShaperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Set<Card> cardsSet = controller.getLibrary().getTopCards(game, 4);
    Cards cards = new CardsImpl(cardsSet);
    TargetCard target = new TargetCardInLibrary(0, 1, new FilterNonlandCard("card to cast without paying its mana cost"));
    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) FilterNonlandCard(mage.filter.common.FilterNonlandCard) ApprovingObject(mage.ApprovingObject) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard)

Example 8 with FilterNonlandCard

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

the class VillainousWealthEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller != null && mageObject != null) {
        Player player = game.getPlayer(targetPointer.getFirst(game, source));
        FilterCard filter = new FilterNonlandCard();
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
        UUID exileId = CardUtil.getCardExileZoneId(game, source);
        if (player != null) {
            Cards cardsToExile = new CardsImpl();
            cardsToExile.addAll(player.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
            controller.moveCards(cardsToExile, Zone.EXILED, source, game);
            if (controller.chooseUse(Outcome.PlayForFree, "Cast cards exiled with " + mageObject.getLogName() + "  without paying its mana cost?", source, game)) {
                OuterLoop: while (cardsToExile.count(filter, game) > 0) {
                    if (!controller.canRespond()) {
                        return false;
                    }
                    TargetCardInExile target = new TargetCardInExile(0, 1, filter, exileId, false);
                    target.setNotTarget(true);
                    while (controller.canRespond() && cardsToExile.count(filter, game) > 0 && controller.choose(Outcome.PlayForFree, cardsToExile, 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);
                            if (cardWasCast) {
                                cardsToExile.remove(card);
                            }
                        } else {
                            break OuterLoop;
                        }
                        target.clearChosen();
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterNonlandCard(mage.filter.common.FilterNonlandCard) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) TargetCardInExile(mage.target.common.TargetCardInExile) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard)

Example 9 with FilterNonlandCard

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

the class NightsnareDiscardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (player == null || controller == null) {
        return false;
    }
    if (player.getHand().isEmpty()) {
        return true;
    }
    Cards revealedCards = new CardsImpl();
    revealedCards.addAll(player.getHand());
    Card sourceCard = game.getCard(source.getSourceId());
    player.revealCards(sourceCard != null ? sourceCard.getIdName() : "Discard", revealedCards, game);
    // You may choose a nonland card from it.
    if (!controller.chooseUse(outcome, "Choose a card to discard? (Otherwise " + player.getLogName() + " has to discard 2 cards).", source, game)) {
        player.discard(2, false, false, source, game);
        return true;
    }
    TargetCard target = new TargetCard(1, Zone.HAND, new FilterNonlandCard());
    if (controller.choose(Outcome.Benefit, revealedCards, target, game)) {
        Card card = revealedCards.get(target.getFirstTarget(), game);
        player.discard(card, false, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard)

Example 10 with FilterNonlandCard

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

the class SpectersShriekEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(source.getFirstTarget());
    if (controller == null || player == null) {
        return false;
    }
    player.revealCards(source, player.getHand(), game);
    if (player.getHand().count(StaticFilters.FILTER_CARD_NON_LAND, game) == 0 || !controller.chooseUse(Outcome.Benefit, "Exile a card from " + player.getName() + "'s hand?", source, game)) {
        return false;
    }
    TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard());
    target.setNotTarget(true);
    target.setRequired(false);
    if (!controller.chooseTarget(Outcome.Benefit, player.getHand(), target, source, game)) {
        return false;
    }
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    boolean isBlack = card.getColor(game).isBlack();
    player.moveCards(card, Zone.EXILED, source, game);
    if (isBlack || controller.getHand().isEmpty()) {
        return true;
    }
    target = new TargetCardInHand(filter);
    target.setNotTarget(true);
    return controller.choose(Outcome.Detriment, controller.getHand(), target, game) && controller.moveCards(game.getCard(target.getFirstTarget()), Zone.EXILED, source, game);
}
Also used : Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Aggregations

FilterNonlandCard (mage.filter.common.FilterNonlandCard)21 Player (mage.players.Player)21 TargetCard (mage.target.TargetCard)15 Card (mage.cards.Card)14 FilterCard (mage.filter.FilterCard)9 UUID (java.util.UUID)7 ApprovingObject (mage.ApprovingObject)7 MageObject (mage.MageObject)6 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)6 Cards (mage.cards.Cards)5 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)4 CardsImpl (mage.cards.CardsImpl)3 Permanent (mage.game.permanent.Permanent)3 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)2 Spell (mage.game.stack.Spell)2 TargetPlayer (mage.target.TargetPlayer)2 TargetCardInHand (mage.target.common.TargetCardInHand)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Cost (mage.abilities.costs.Cost)1