Search in sources :

Example 11 with FilterNonlandCard

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

the class TidehollowScullerLeaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    // Then its first ability will resolve and exile the chosen card forever.
    if (controller != null && opponent != null) {
        opponent.revealCards("Tidehollow Sculler", opponent.getHand(), game);
        TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard("nonland card to exile"));
        if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) {
            Card card = opponent.getHand().get(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCardsToExile(card, source, game, true, CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()), "Tidehollow Sculler");
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 12 with FilterNonlandCard

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

the class VenarianGlimmerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player != null) {
        FilterCard filter = new FilterNonlandCard();
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
        Effect effect = new DiscardCardYouChooseTargetEffect(filter, TargetController.ANY);
        effect.setTargetPointer(targetPointer);
        effect.apply(game, source);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterNonlandCard(mage.filter.common.FilterNonlandCard) DiscardCardYouChooseTargetEffect(mage.abilities.effects.common.discard.DiscardCardYouChooseTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) DiscardCardYouChooseTargetEffect(mage.abilities.effects.common.discard.DiscardCardYouChooseTargetEffect)

Example 13 with FilterNonlandCard

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

the class VendilionCliqueEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player != null && controller != null && sourceObject != null) {
        TargetCard targetCard = new TargetCard(Zone.ALL, new FilterNonlandCard());
        targetCard.setRequired(false);
        if (controller.choose(Outcome.Discard, player.getHand(), targetCard, game)) {
            Card card = game.getCard(targetCard.getFirstTarget());
            if (card != null) {
                CardsImpl cards = new CardsImpl();
                cards.add(card);
                player.revealCards(sourceObject.getIdName(), cards, game);
                player.putCardsOnBottomOfLibrary(cards, game, source, true);
                player.drawCards(1, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) CardsImpl(mage.cards.CardsImpl) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 14 with FilterNonlandCard

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

the class ShimianSpecterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (targetPlayer != null && sourceObject != null && controller != null) {
        // reveal hand of target player
        targetPlayer.revealCards(sourceObject.getName(), targetPlayer.getHand(), game);
        // You choose a nonland card from it
        TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard());
        target.setNotTarget(true);
        Card chosenCard = null;
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(Outcome.Benefit, targetPlayer.getHand(), target, source, game)) {
            chosenCard = game.getCard(target.getFirstTarget());
        }
        // Exile all cards with the same name
        // Building a card filter with the name
        FilterCard filterNamedCards = new FilterCard();
        // so no card matches
        String nameToSearch = "---";
        if (chosenCard != null) {
            nameToSearch = CardUtil.getCardNameForSameNameSearch(chosenCard);
        }
        filterNamedCards.add(new NamePredicate(nameToSearch));
        // search cards in graveyard
        if (chosenCard != null) {
            for (Card checkCard : targetPlayer.getGraveyard().getCards(game)) {
                if (checkCard.getName().equals(chosenCard.getName())) {
                    controller.moveCardToExileWithInfo(checkCard, null, "", source, game, Zone.GRAVEYARD, true);
                }
            }
            // search cards in hand
            TargetCard targetHandCards = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCards);
            controller.chooseTarget(Outcome.Benefit, targetPlayer.getHand(), targetHandCards, source, game);
            for (UUID cardId : targetHandCards.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.HAND, true);
                }
            }
        }
        // that player's library and have that player shuffle it.
        if (chosenCard != null || controller.chooseUse(outcome, "Search library anyway?", source, game)) {
            TargetCardInLibrary targetCardsLibrary = new TargetCardInLibrary(0, Integer.MAX_VALUE, filterNamedCards);
            controller.searchLibrary(targetCardsLibrary, source, game, targetPlayer.getId());
            for (UUID cardId : targetCardsLibrary.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.LIBRARY, true);
                }
            }
            targetPlayer.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterNonlandCard(mage.filter.common.FilterNonlandCard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 15 with FilterNonlandCard

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

the class TwinningGlassEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Spell> spells = new ArrayList<>();
    Permanent twinningGlass = game.getPermanent(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
    if (twinningGlass == null) {
        twinningGlass = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    }
    if (twinningGlass != null && controller != null && watcher != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (watcher.getSpellsCastThisTurn(playerId) != null) {
                for (Spell spell : watcher.getSpellsCastThisTurn(playerId)) {
                    spells.add(spell);
                }
            }
        }
        if (spells.isEmpty()) {
            return false;
        }
        List<NamePredicate> predicates = spells.stream().map(Spell::getName).filter(Objects::nonNull).filter(s -> !s.isEmpty()).map(NamePredicate::new).collect(Collectors.toList());
        FilterNonlandCard filterCard = new FilterNonlandCard("nonland card that was cast this turn");
        filterCard.add(Predicates.or(predicates));
        TargetCard target = new TargetCard(0, 1, Zone.HAND, filterCard);
        target.withChooseHint("free cast");
        if (controller.choose(Outcome.PlayForFree, controller.getHand(), target, game)) {
            Card chosenCard = game.getCard(target.getFirstTarget());
            if (chosenCard != null) {
                game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), Boolean.TRUE);
                Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(chosenCard, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), null);
                return cardWasCast;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) Spell(mage.game.stack.Spell) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterNonlandCard(mage.filter.common.FilterNonlandCard) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) UUID(java.util.UUID)

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