Search in sources :

Example 16 with TargetCardInLibrary

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

the class PeregrinationEffect 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;
    }
    TargetCardInLibrary target = new TargetCardInLibrary(0, 2, StaticFilters.FILTER_CARD_BASIC_LAND);
    if (controller.searchLibrary(target, source, game)) {
        if (!target.getTargets().isEmpty()) {
            Cards revealed = new CardsImpl();
            for (UUID cardId : target.getTargets()) {
                Card card = controller.getLibrary().getCard(cardId, game);
                revealed.add(card);
            }
            controller.revealCards(sourceObject.getIdName(), revealed, game);
            if (target.getTargets().size() == 2) {
                TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
                controller.choose(Outcome.Benefit, revealed, target2, game);
                Card card = revealed.get(target2.getFirstTarget(), game);
                controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
                revealed.remove(card);
                Set<Card> cards = revealed.getCards(game);
                card = cards.isEmpty() ? null : cards.iterator().next();
                controller.moveCards(card, Zone.HAND, source, game);
            } else if (target.getTargets().size() == 1) {
                Set<Card> cards = revealed.getCards(game);
                Card card = cards.isEmpty() ? null : cards.iterator().next();
                controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : Player(mage.players.Player) Set(java.util.Set) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 17 with TargetCardInLibrary

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

the class RemembranceTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!((ZoneChangeEvent) event).isDiesEvent()) {
        return false;
    }
    Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
    if (permanent != null && filter.match(permanent, game)) {
        FilterCard filterCard = new FilterCard("card named " + permanent.getName());
        filterCard.add(new NamePredicate(permanent.getName()));
        this.getEffects().clear();
        this.addEffect(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true));
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 18 with TargetCardInLibrary

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

the class RenownedWeaponsmithEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                Cards revealed = new CardsImpl();
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    revealed.add(card);
                    controller.revealCards(sourceObject.getIdName(), revealed, game);
                    controller.moveCards(revealed, Zone.HAND, source, game);
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Example 19 with TargetCardInLibrary

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

the class SadisticSacramentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    Player player = game.getPlayer(source.getControllerId());
    if (player != null && targetPlayer != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard("cards to exile"));
        if (player.searchLibrary(target, source, game, targetPlayer.getId())) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
                Card card = targetPlayer.getLibrary().remove(targetId, game);
                if (card != null) {
                    card.moveToExile(null, "", source, game);
                }
            }
        }
        targetPlayer.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 20 with TargetCardInLibrary

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

the class RushedRebirthDelayedTriggeredAbility method makeEffect.

private static Effect makeEffect(Permanent permanent) {
    FilterCard filter = new FilterCreatureCard("creature card with lesser mana value than " + permanent.getIdName());
    filter.add(new RushedRebirthPredicate(permanent));
    return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter), true);
}
Also used : FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

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