Search in sources :

Example 71 with TargetCardInLibrary

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

the class EldritchEvolutionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent != null && controller != null) {
        int newConvertedCost = sacrificedPermanent.getManaValue() + 2;
        FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost + " or less");
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, newConvertedCost + 1));
        filter.add(CardType.CREATURE.getPredicate());
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 72 with TargetCardInLibrary

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

the class EarwigSquadEffect method apply.

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

Example 73 with TargetCardInLibrary

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

the class ExtractEffect 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(1, 1, filter);
        if (player.searchLibrary(target, source, game, targetPlayer.getId())) {
            Card card = targetPlayer.getLibrary().remove(target.getFirstTarget(), game);
            if (card != null) {
                player.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true);
            }
        }
        targetPlayer.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 74 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary 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 75 with TargetCardInLibrary

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

the class InsidiousDreamsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    int amount = GetXValue.instance.calculate(game, source, this);
    if (controller != null && sourceObject != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard());
        if (controller.searchLibrary(target, source, game)) {
            Cards chosen = new CardsImpl();
            for (UUID cardId : target.getTargets()) {
                Card card = controller.getLibrary().remove(cardId, game);
                chosen.add(card);
            }
            controller.shuffleLibrary(source, game);
            TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop));
            while (chosen.size() > 1 && controller.canRespond()) {
                controller.choose(Outcome.Neutral, chosen, targetToLib, game);
                Card card = chosen.get(targetToLib.getFirstTarget(), game);
                if (card != null) {
                    chosen.remove(card);
                    controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
                }
                targetToLib.clearChosen();
            }
            if (chosen.size() == 1) {
                Card card = chosen.get(chosen.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) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

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