Search in sources :

Example 76 with TargetCardInLibrary

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

the class MangarasTomeReplacementEffect 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) {
        TargetCardInLibrary target = new TargetCardInLibrary(5, new FilterCard());
        if (controller.searchLibrary(target, source, game)) {
            for (UUID targetId : target.getTargets()) {
                Card card = controller.getLibrary().getCard(targetId, game);
                if (card != null) {
                    controller.moveCardsToExile(card, source, game, false, CardUtil.getCardExileZoneId(game, source), permanent.getName());
                    card.setFaceDown(true, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 77 with TargetCardInLibrary

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

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

the class MimeofactureEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (controller == null || permanent == null) {
        return false;
    }
    Player opponent = game.getPlayer(permanent.getControllerId());
    if (opponent == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card named " + permanent.getName());
    filter.add(new NamePredicate(permanent.getName()));
    TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
    if (controller.searchLibrary(target, source, game, opponent.getId())) {
        Card card = opponent.getLibrary().getCard(target.getFirstTarget(), game);
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    opponent.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 79 with TargetCardInLibrary

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

the class NightmareIncursionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (controller == null || targetPlayer == null) {
        return false;
    }
    int amount = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
    TargetCardInLibrary target = new TargetCardInLibrary(0, amount, StaticFilters.FILTER_CARD);
    if (controller.searchLibrary(target, source, game, targetPlayer.getId())) {
        Cards cards = new CardsImpl(target.getTargets());
        controller.moveCards(cards, Zone.EXILED, source, game);
    }
    targetPlayer.shuffleLibrary(source, game);
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 80 with TargetCardInLibrary

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

the class NeoformReplacementEffect 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) {
        return false;
    }
    int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
    FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
    filter.add(CardType.CREATURE.getPredicate());
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        if (card != null) {
            ContinuousEffectImpl effect = new NeoformReplacementEffect();
            effect.setTargetPointer(new FixedTarget(card, game));
            game.addEffect(effect, source);
            if (!controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                effect.discard();
            }
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) FixedTarget(mage.target.targetpointer.FixedTarget) 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) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

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