Search in sources :

Example 16 with FilterNonlandCard

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

the class NeverHappenedEffect 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) {
        return false;
    }
    opponent.revealCards(source, opponent.getHand(), game);
    TargetCard target;
    Cards cards;
    if (controller.chooseUse(outcome, "Exile a card from hand or graveyard?", null, "Hand", "Graveyard", source, game)) {
        FilterCard filter = new FilterNonlandCard("nonland card in " + opponent.getName() + "'s hand");
        target = new TargetCard(Zone.HAND, filter);
        target.setNotTarget(true);
        cards = opponent.getHand();
    } else {
        FilterCard filter = new FilterNonlandCard("nonland card in " + opponent.getName() + "'s graveyard");
        target = new TargetCard(Zone.GRAVEYARD, filter);
        target.setNotTarget(true);
        cards = opponent.getGraveyard();
    }
    if (controller.choose(outcome, cards, target, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            controller.moveCards(card, Zone.EXILED, source, game);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 17 with FilterNonlandCard

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

the class SunbirdsInvocationEffect 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) {
        return false;
    }
    Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
    if (spell == null) {
        return false;
    }
    int xValue = spell.getManaValue();
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
    if (!cards.isEmpty()) {
        controller.revealCards(sourceObject.getIdName(), cards, game);
        FilterCard filter = new FilterNonlandCard("card revealed this way with mana value " + xValue + " or less");
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
        TargetCard target = new TargetCard(1, Zone.LIBRARY, filter);
        if (controller.chooseTarget(Outcome.PlayForFree, cards, target, source, game)) {
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                if (controller.chooseUse(Outcome.Benefit, "Cast " + card.getLogName() + " without paying its mana cost?", source, game)) {
                    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) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Spell(mage.game.stack.Spell) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 18 with FilterNonlandCard

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

the class SelectiveMemoryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, new FilterNonlandCard());
        if (player.searchLibrary(target, source, game)) {
            for (UUID targetId : target.getTargets()) {
                Card card = player.getLibrary().remove(targetId, game);
                if (card != null) {
                    card.moveToExile(null, "", source, game);
                }
            }
        }
        player.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 19 with FilterNonlandCard

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

the class TasigurTheGoldenFangEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID opponentId = null;
        if (game.getOpponents(controller.getId()).size() > 1) {
            Target target = new TargetOpponent(true);
            if (controller.chooseTarget(outcome, target, source, game)) {
                opponentId = target.getFirstTarget();
            }
        } else {
            opponentId = game.getOpponents(controller.getId()).iterator().next();
        }
        if (opponentId != null) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                FilterNonlandCard filter = new FilterNonlandCard("nonland card from " + controller.getLogName() + " graveyard");
                filter.add(new OwnerIdPredicate(controller.getId()));
                Target target = new TargetCardInGraveyard(filter);
                target.setNotTarget(true);
                opponent.chooseTarget(outcome, target, source, game);
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) UUID(java.util.UUID) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 20 with FilterNonlandCard

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

the class AetherworksMarvelEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Card> cardsSet = controller.getLibrary().getTopCards(game, 6);
        Cards cards = new CardsImpl(cardsSet);
        TargetCard target = new TargetCardInLibrary(0, 1, new FilterNonlandCard("card to cast without paying its mana cost"));
        if (controller.choose(Outcome.PlayForFree, cards, target, game)) {
            Card card = controller.getLibrary().getCard(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);
                if (cardWasCast) {
                    cards.remove(card);
                }
            }
        }
        controller.putCardsOnBottomOfLibrary(cards, game, source, false);
        return true;
    }
    return false;
}
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)

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