Search in sources :

Example 26 with FilterCreatureCard

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

the class InstrumentOfTheBardsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller == null || permanent == null) {
        return false;
    }
    int counters = permanent.getCounters(game).getCount(CounterType.HARMONY);
    FilterCreatureCard filter = new FilterCreatureCard("creature card with mana value " + counters);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, counters));
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            controller.revealCards(permanent.getIdName(), new CardsImpl(card), game);
            controller.moveCards(card, Zone.HAND, source, game);
            if (card.isLegendary()) {
                new TreasureToken().putOntoBattlefield(1, game, source, source.getControllerId());
            }
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TreasureToken(mage.game.permanent.token.TreasureToken) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 27 with FilterCreatureCard

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

the class KindredSummonsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
        if (subType == null) {
            return false;
        }
        FilterControlledCreaturePermanent filterPermanent = new FilterControlledCreaturePermanent("creature you control of the chosen type");
        filterPermanent.add(subType.getPredicate());
        int numberOfCards = game.getBattlefield().countAll(filterPermanent, source.getControllerId(), game);
        Cards revealed = new CardsImpl();
        Set<Card> chosenSubtypeCreatureCards = new LinkedHashSet<>();
        Cards otherCards = new CardsImpl();
        FilterCreatureCard filterCard = new FilterCreatureCard("creature card of the chosen type");
        filterCard.add(subType.getPredicate());
        if (numberOfCards == 0) {
            // no matches so nothing is revealed
            game.informPlayers("There are 0 creature cards of the chosen type in " + controller.getName() + "'s library.");
            return true;
        }
        for (Card card : controller.getLibrary().getCards(game)) {
            revealed.add(card);
            if (card != null && filterCard.match(card, game)) {
                chosenSubtypeCreatureCards.add(card);
                if (chosenSubtypeCreatureCards.size() == numberOfCards) {
                    break;
                }
            } else {
                otherCards.add(card);
            }
        }
        controller.revealCards(source, revealed, game);
        controller.moveCards(chosenSubtypeCreatureCards, Zone.BATTLEFIELD, source, game);
        if (!otherCards.isEmpty()) {
            controller.putCardsOnTopOfLibrary(otherCards, game, source, false);
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) SubType(mage.constants.SubType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 28 with FilterCreatureCard

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

the class MarchOfBurgeoningLifeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (player == null || permanent == null) {
        return false;
    }
    FilterCard filter = new FilterCreatureCard("creature card with the same name as " + permanent.getName());
    filter.add(new MarchOfBurgeoningLifePredicate(permanent));
    TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
    player.searchLibrary(target, source, game);
    Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
    if (card != null) {
        player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
    }
    player.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 29 with FilterCreatureCard

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

the class BodyDoubleCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Target target = new TargetCardInGraveyard(new FilterCreatureCard("creature card in a graveyard"));
        target.setNotTarget(true);
        if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            player.choose(outcome, target, source.getSourceId(), game);
            Card copyFromCard = game.getCard(target.getFirstTarget());
            if (copyFromCard != null) {
                CopyEffect copyEffect = new CopyEffect(Duration.Custom, copyFromCard, source.getSourceId());
                game.addEffect(copyEffect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) Player(mage.players.Player) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 30 with FilterCreatureCard

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

the class CongregationAtDawnEffect 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) {
        TargetCardInLibrary target = new TargetCardInLibrary(0, 3, new FilterCreatureCard("creature cards"));
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                Cards revealed = new CardsImpl();
                for (UUID cardId : target.getTargets()) {
                    Card card = controller.getLibrary().remove(cardId, game);
                    revealed.add(card);
                }
                controller.revealCards(sourceObject.getName(), revealed, game);
                controller.shuffleLibrary(source, game);
                TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop));
                while (revealed.size() > 1 && controller.canRespond()) {
                    controller.choose(Outcome.Neutral, revealed, targetToLib, game);
                    Card card = revealed.get(targetToLib.getFirstTarget(), game);
                    if (card != null) {
                        revealed.remove(card);
                        controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
                    }
                    targetToLib.clearChosen();
                }
                if (revealed.size() == 1) {
                    Card card = revealed.get(revealed.iterator().next(), game);
                    controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard)

Aggregations

FilterCreatureCard (mage.filter.common.FilterCreatureCard)69 Player (mage.players.Player)58 Card (mage.cards.Card)31 FilterCard (mage.filter.FilterCard)26 Permanent (mage.game.permanent.Permanent)22 UUID (java.util.UUID)17 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)17 TargetCard (mage.target.TargetCard)16 CardsImpl (mage.cards.CardsImpl)15 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)15 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)14 MageObject (mage.MageObject)13 OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)10 Target (mage.target.Target)10 HashSet (java.util.HashSet)8 Cards (mage.cards.Cards)8 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)7 Ability (mage.abilities.Ability)6 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)6 OneShotEffect (mage.abilities.effects.OneShotEffect)4