Search in sources :

Example 1 with FilterNonlandCard

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

the class DiscipleOfDeceitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (player != null && mageObject != null) {
        Cost cost = new DiscardTargetCost(new TargetCardInHand(new FilterNonlandCard()));
        String message = "Discard a nonland card to search your library?";
        if (cost.canPay(source, source, source.getControllerId(), game) && player.chooseUse(Outcome.Detriment, message, source, game)) {
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                Card card = game.getCard(cost.getTargets().getFirstTarget());
                if (card == null) {
                    return false;
                }
                String targetName = "card with mana value of " + card.getManaValue();
                FilterCard filter = new FilterCard(targetName);
                filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, card.getManaValue()));
                return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true).apply(game, source);
            }
        }
        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) TargetCardInHand(mage.target.common.TargetCardInHand) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) MageObject(mage.MageObject) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) Cost(mage.abilities.costs.Cost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 2 with FilterNonlandCard

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

the class MemoryLeakEffect 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 3 with FilterNonlandCard

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

the class AlhammarretHighArbiterCantCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards revealedCards = new CardsImpl();
        for (UUID playerId : game.getOpponents(controller.getId())) {
            Player opponent = game.getPlayer(playerId);
            if (opponent != null) {
                Cards cards = new CardsImpl(opponent.getHand());
                opponent.revealCards(opponent.getName() + "'s hand", cards, game);
                revealedCards.addAll(cards);
            }
        }
        TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard("nonland card from an opponents hand"));
        controller.chooseTarget(Outcome.Benefit, revealedCards, target, source, game);
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            game.informPlayers("The choosen card name is [" + GameLog.getColoredObjectName(card) + ']');
            Permanent sourcePermanent = game.getPermanentEntering(source.getSourceId());
            if (sourcePermanent == null) {
                sourcePermanent = game.getPermanentEntering(source.getSourceId());
            }
            if (sourcePermanent != null) {
                sourcePermanent.addInfo("chosen card name", CardUtil.addToolTipMarkTags("Chosen card name: " + card.getName()), game);
            }
            game.addEffect(new AlhammarretHighArbiterCantCastEffect(card.getName()), source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard)

Example 4 with FilterNonlandCard

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

the class DarkDecisionEffect 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) {
        TargetCardInLibrary target = new TargetCardInLibrary(new FilterNonlandCard());
        target.setCardLimit(10);
        if (controller.searchLibrary(target, source, game)) {
            UUID targetId = target.getFirstTarget();
            Card card = game.getCard(targetId);
            if (card != null) {
                controller.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
                ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfTurn);
                effect.setTargetPointer(new FixedTarget(card.getId(), game));
                game.addEffect(effect, source);
            }
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 5 with FilterNonlandCard

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

the class HellcarverDemonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourceObject != null) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
            if (!Objects.equals(permanent, sourceObject)) {
                permanent.sacrifice(source, game);
            }
        }
        if (!controller.getHand().isEmpty()) {
            int cardsInHand = controller.getHand().size();
            controller.discard(cardsInHand, false, false, source, game);
        }
        // move cards from library to exile
        Set<Card> currentExiledCards = new HashSet<>();
        currentExiledCards.addAll(controller.getLibrary().getTopCards(game, 6));
        controller.moveCardsToExile(currentExiledCards, source, game, true, source.getSourceId(), sourceObject.getIdName());
        // cast the possible cards without paying the mana
        Cards cardsToCast = new CardsImpl();
        cardsToCast.addAll(currentExiledCards);
        boolean alreadyCast = false;
        while (controller.canRespond() && !cardsToCast.isEmpty()) {
            if (!controller.chooseUse(outcome, "Cast a" + (alreadyCast ? "another" : "") + " card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
                break;
            }
            TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterNonlandCard("nonland card to cast for free"));
            if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
                alreadyCast = true;
                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);
                    cardsToCast.remove(card);
                    if (!cardWasCast) {
                        game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) HashSet(java.util.HashSet)

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