Search in sources :

Example 51 with TargetCardInLibrary

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

the class FinalPartingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Unlike Jarad's Orders, which this mostly copies, you can't fail to find
        TargetCardInLibrary target = new TargetCardInLibrary(2, 2, new FilterCard());
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                Cards searched = new CardsImpl();
                for (UUID cardId : target.getTargets()) {
                    Card card = controller.getLibrary().getCard(cardId, game);
                    searched.add(card);
                }
                if (target.getTargets().size() == 2) {
                    TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
                    controller.choose(Outcome.Benefit, searched, target2, game);
                    Card card = searched.get(target2.getFirstTarget(), game);
                    controller.moveCards(card, Zone.HAND, source, game);
                    searched.remove(card);
                    Set<Card> cards = searched.getCards(game);
                    card = cards.isEmpty() ? null : cards.iterator().next();
                    controller.moveCards(card, Zone.GRAVEYARD, source, game);
                } else if (target.getTargets().size() == 1) {
                    Set<Card> cards = searched.getCards(game);
                    Card card = cards.isEmpty() ? null : cards.iterator().next();
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
            controller.shuffleLibrary(source, game);
            return true;
        }
        controller.shuffleLibrary(source, game);
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Set(java.util.Set) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 52 with TargetCardInLibrary

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

the class GoblinTutorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int amount = controller.rollDice(outcome, source, game, 6);
        Effect effect = null;
        // 6 - An instant or sorcery card
        if (amount == 2) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, filter), true);
        } else if (amount == 3) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_ENTCHANTMENT), true);
        } else if (amount == 4) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_ARTIFACT), true);
        } else if (amount == 5) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_CREATURE), true);
        } else if (amount == 6) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, new FilterInstantOrSorceryCard()), true);
        }
        if (effect != null) {
            effect.apply(game, source);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 53 with TargetCardInLibrary

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

the class LifesFinaleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game);
    for (Permanent permanent : permanents) {
        permanent.destroy(source, game, false);
    }
    Player opponent = game.getPlayer(source.getFirstTarget());
    Player player = game.getPlayer(source.getControllerId());
    if (player != null && opponent != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(0, 3, new FilterCreatureCard("creature cards from their library to put in their graveyard"));
        if (player.searchLibrary(target, source, game, opponent.getId())) {
            player.moveCards(new CardsImpl(target.getTargets()), Zone.GRAVEYARD, source, game);
        }
        opponent.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl)

Example 54 with TargetCardInLibrary

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

the class NecromentiaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    Player controller = game.getPlayer(source.getControllerId());
    if (cardName != null && controller != null) {
        FilterCard filter = new FilterCard("card named " + cardName);
        filter.add(new NamePredicate(cardName));
        Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
        // cards in Graveyard
        int cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getGraveyard().count(filter, game));
        if (cardsCount > 0) {
            filter.setMessage("card named " + cardName + " in the graveyard of " + targetPlayer.getName());
            TargetCard target = new TargetCard(0, cardsCount, Zone.GRAVEYARD, filter);
            if (controller.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
                controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
            }
        }
        // cards in Hand
        int numberOfCardsExiledFromHand = 0;
        cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getHand().count(filter, game));
        if (cardsCount > 0) {
            filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
            TargetCard target = new TargetCard(0, cardsCount, Zone.HAND, filter);
            if (controller.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
                numberOfCardsExiledFromHand = target.getTargets().size();
                controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
            }
        } else {
            targetPlayer.revealCards(targetPlayer.getName() + "'s Hand", targetPlayer.getHand(), game);
        }
        // cards in Library
        Cards cardsInLibrary = new CardsImpl();
        cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
        cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
        if (cardsCount > 0) {
            filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getLogName());
            TargetCardInLibrary targetLib = new TargetCardInLibrary(0, cardsCount, filter);
            if (controller.choose(Outcome.Exile, cardsInLibrary, targetLib, game)) {
                controller.moveCards(new CardsImpl(targetLib.getTargets()), Zone.EXILED, source, game);
            }
        } else {
            targetPlayer.revealCards(targetPlayer.getName() + "'s Library", new CardsImpl(new HashSet<>(targetPlayer.getLibrary().getCards(game))), game);
        }
        targetPlayer.shuffleLibrary(source, game);
        if (numberOfCardsExiledFromHand > 0) {
            game.getState().applyEffects(game);
            Token zombieToken = new ZombieToken();
            zombieToken.putOntoBattlefield(numberOfCardsExiledFromHand, game, source, targetPlayer.getId());
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ZombieToken(mage.game.permanent.token.ZombieToken) TargetCard(mage.target.TargetCard) Token(mage.game.permanent.token.Token) ZombieToken(mage.game.permanent.token.ZombieToken) CardsImpl(mage.cards.CardsImpl) Cards(mage.cards.Cards) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) HashSet(java.util.HashSet)

Example 55 with TargetCardInLibrary

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

the class SettleTheWreckageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || player == null) {
        return false;
    }
    int attackers = 0;
    Set<Card> toExile = new HashSet<>();
    Iterator<UUID> creatureIds = game.getCombat().getAttackers().iterator();
    while (creatureIds.hasNext()) {
        Permanent creature = game.getPermanent(creatureIds.next());
        if (creature != null && creature.isControlledBy(player.getId())) {
            toExile.add(creature);
            attackers++;
        }
    }
    controller.moveCards(toExile, Zone.EXILED, source, game);
    TargetCardInLibrary target = new TargetCardInLibrary(0, attackers, StaticFilters.FILTER_CARD_BASIC_LAND);
    if (player.chooseUse(Outcome.Benefit, "Search for up to " + attackers + " basic land" + ((attackers == 1) ? "" : "s") + "?", source, game) && player.searchLibrary(target, source, game)) {
        player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
        player.shuffleLibrary(source, game);
    }
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card) HashSet(java.util.HashSet)

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