Search in sources :

Example 61 with TargetCardInLibrary

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

the class SearchLibraryWithLessCMCPutInPlayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // never change static objects so copy the object here before
        FilterCard advancedFilter = filter.copy();
        advancedFilter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
        TargetCardInLibrary target = new TargetCardInLibrary(advancedFilter);
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
                if (card != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                }
            }
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 62 with TargetCardInLibrary

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

the class AssemblyHallEffect 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 || controller.getHand().isEmpty() || sourceObject == null) {
        return false;
    }
    Card cardToReveal = null;
    Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
    target.setNotTarget(true);
    if (controller.chooseTarget(outcome, target, source, game)) {
        cardToReveal = game.getCard(target.getFirstTarget());
    }
    if (cardToReveal == null) {
        return false;
    }
    controller.revealCards("from hand :" + sourceObject.getName(), new CardsImpl(cardToReveal), game);
    String nameToSearch = CardUtil.getCardNameForSameNameSearch(cardToReveal);
    FilterCard filterCard = new FilterCard("card named " + nameToSearch);
    filterCard.add(new NamePredicate(nameToSearch));
    return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) MageObject(mage.MageObject) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) CardsImpl(mage.cards.CardsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 63 with TargetCardInLibrary

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

the class AssassinsTrophyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (permanent != null) {
        Player controller = game.getPlayer(permanent.getControllerId());
        if (controller != null) {
            if (controller.chooseUse(Outcome.PutLandInPlay, "Search for a basic land, put it onto the battlefield and then shuffle?", source, game)) {
                TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND);
                if (controller.searchLibrary(target, source, game)) {
                    Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
                    if (card != null) {
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                    }
                }
                controller.shuffleLibrary(source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 64 with TargetCardInLibrary

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

the class BoundlessRealmsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterLandPermanent filter = new FilterLandPermanent();
    filter.add(TargetController.YOU.getControllerPredicate());
    int amount = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
    TargetCardInLibrary target = new TargetCardInLibrary(0, amount, StaticFilters.FILTER_CARD_BASIC_LAND);
    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;
}
Also used : Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl)

Example 65 with TargetCardInLibrary

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

the class BountyOfSkemfarEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6));
    player.revealCards(source, cards, game);
    TargetCard target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_LAND);
    player.choose(outcome, cards, target, game);
    Card land = cards.get(target.getFirstTarget(), game);
    if (land != null) {
        player.moveCards(land, Zone.BATTLEFIELD, source, game, true, false, false, null);
    }
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.LIBRARY);
    target = new TargetCardInLibrary(0, 1, filter);
    player.choose(outcome, cards, target, game);
    Card elf = cards.get(target.getFirstTarget(), game);
    if (elf != null) {
        player.moveCards(elf, Zone.HAND, source, game);
    }
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.LIBRARY);
    player.putCardsOnBottomOfLibrary(cards, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) 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