Search in sources :

Example 36 with TargetCardInLibrary

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

the class OathOfLiegesPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player activePlayer = game.getPlayer(game.getActivePlayerId());
    if (activePlayer != null) {
        if (activePlayer.chooseUse(outcome, "Search your library for a basic land card, put that card onto the battlefield, then shuffle?", source, game)) {
            Effect effect = new SearchLibraryPutInPlayTargetPlayerEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND), false, false, Outcome.PutLandInPlay, true);
            effect.setTargetPointer(new FixedTarget(game.getActivePlayerId()));
            return effect.apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPlayer(mage.filter.FilterPlayer) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) SearchLibraryPutInPlayTargetPlayerEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayTargetPlayerEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) SearchLibraryPutInPlayTargetPlayerEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayTargetPlayerEffect) Effect(mage.abilities.effects.Effect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 37 with TargetCardInLibrary

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

the class PathToExileEffect 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) {
        Player player = game.getPlayer(permanent.getControllerId());
        // if the zone change to exile gets replaced does not prevent the target controller to be able to search
        controller.moveCardToExileWithInfo(permanent, null, "", source, game, Zone.BATTLEFIELD, true);
        if (player.chooseUse(Outcome.PutCardInPlay, "Search your library for a basic land card?", source, game)) {
            TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND);
            if (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;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 38 with TargetCardInLibrary

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

the class PrimeSpeakerVannifarEffect 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);
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    controller.shuffleLibrary(source, game);
    return true;
}
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) TapSourceCost(mage.abilities.costs.common.TapSourceCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 39 with TargetCardInLibrary

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

the class SchemingSymmetryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    source.getTargets().get(0).getTargets().stream().map(playerId -> game.getPlayer(playerId)).filter(player -> player != null).forEach(player -> {
        TargetCardInLibrary targetCard = new TargetCardInLibrary();
        if (player.searchLibrary(targetCard, source, game)) {
            Cards cards = new CardsImpl();
            cards.add(targetCard.getFirstTarget());
            player.shuffleLibrary(source, game);
            player.putCardsOnTopOfLibrary(cards, game, source, false);
        }
    });
    return true;
}
Also used : CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Ability(mage.abilities.Ability) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 40 with TargetCardInLibrary

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

the class ScapeshiftEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int amount = 0;
    TargetControlledPermanent sacrificeLand = new TargetControlledPermanent(0, Integer.MAX_VALUE, new FilterControlledLandPermanent("lands you control"), true);
    if (controller.chooseTarget(Outcome.Sacrifice, sacrificeLand, source, game)) {
        for (UUID uuid : sacrificeLand.getTargets()) {
            Permanent land = game.getPermanent(uuid);
            if (land != null) {
                land.sacrifice(source, game);
                amount++;
            }
        }
    }
    TargetCardInLibrary target = new TargetCardInLibrary(amount, new FilterLandCard("lands"));
    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;
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) FilterLandCard(mage.filter.common.FilterLandCard) UUID(java.util.UUID) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) 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