Search in sources :

Example 6 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class FiendArtisanEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int xValue = source.getManaCostsToPay().getX();
    FilterCard filter = new FilterCreatureCard("creature card with mana value " + xValue + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter)).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 7 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class HarvestSeasonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int tappedCreatures = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
        if (tappedCreatures > 0) {
            TargetCardInLibrary target = new TargetCardInLibrary(0, tappedCreatures, StaticFilters.FILTER_CARD_BASIC_LAND);
            if (controller.searchLibrary(target, source, game)) {
                controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl)

Example 8 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class HatcherySpiderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this);
    FilterCard filter = new FilterPermanentCard("green permanent card with mana value " + xValue + " or less");
    filter.add(new ColorPredicate(ObjectColor.GREEN));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCard target = new TargetCardInLibrary(filter);
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
    if (player.chooseUse(outcome, "Put a card onto the battlefield?", source, game) && player.choose(outcome, cards, target, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
            cards.remove(card);
        }
    }
    while (!cards.isEmpty()) {
        Card card = cards.getRandom(game);
        player.getLibrary().putOnBottom(card, game);
        cards.remove(card);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCard(mage.target.TargetCard) CardsInControllerGraveyardCount(mage.abilities.dynamicvalue.common.CardsInControllerGraveyardCount) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

Example 9 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class HauntingEchoesPredicate 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;
    }
    Cards cards = new CardsImpl();
    player.getGraveyard().getCards(game).stream().filter(Objects::nonNull).filter(card -> !card.isBasic() || !card.isLand(game)).forEach(cards::add);
    controller.moveCards(cards, Zone.EXILED, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
    FilterCard filter = new FilterCard("cards with the same name as a card exiled this way");
    filter.add(new HauntingEchoesPredicate(cards));
    TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
    controller.searchLibrary(target, source, game, player.getId());
    cards.clear();
    cards.addAll(target.getTargets());
    controller.moveCards(cards, Zone.EXILED, source, game);
    player.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) Predicate(mage.filter.predicate.Predicate) mage.cards(mage.cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) Player(mage.players.Player) Objects(java.util.Objects) Game(mage.game.Game) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) mage.cards(mage.cards) Objects(java.util.Objects) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 10 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class IncomingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
                if (player.searchLibrary(target, source, game)) {
                    player.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game);
                    player.shuffleLibrary(source, game);
                }
            }
        }
        // prevent undo
        controller.resetStoredBookmark(game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl)

Aggregations

TargetCardInLibrary (mage.target.common.TargetCardInLibrary)225 Player (mage.players.Player)207 FilterCard (mage.filter.FilterCard)120 Card (mage.cards.Card)110 Permanent (mage.game.permanent.Permanent)68 UUID (java.util.UUID)65 CardsImpl (mage.cards.CardsImpl)53 TargetCard (mage.target.TargetCard)53 MageObject (mage.MageObject)37 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)31 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)28 Cards (mage.cards.Cards)26 TargetPlayer (mage.target.TargetPlayer)19 FilterCreatureCard (mage.filter.common.FilterCreatureCard)18 FilterPermanent (mage.filter.FilterPermanent)14 TargetPermanent (mage.target.TargetPermanent)14 FixedTarget (mage.target.targetpointer.FixedTarget)14 Cost (mage.abilities.costs.Cost)13 SearchLibraryPutInHandEffect (mage.abilities.effects.common.search.SearchLibraryPutInHandEffect)13 SearchLibraryPutInPlayEffect (mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)12