Search in sources :

Example 31 with TargetCardInLibrary

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

the class CelebrateTheHarvestEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int powerCount = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(MageObject::getPower).mapToInt(MageInt::getValue).distinct().map(x -> 1).sum();
    TargetCardInLibrary target = new TargetCardInLibrary(0, powerCount, StaticFilters.FILTER_CARD_BASIC_LAND);
    player.searchLibrary(target, source, game);
    Cards cards = new CardsImpl();
    target.getTargets().stream().map(cardId -> player.getLibrary().getCard(cardId, game)).forEach(cards::add);
    player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, true, null);
    player.shuffleLibrary(source, game);
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) MageObject(mage.MageObject) CovenHint(mage.abilities.hint.common.CovenHint) Ability(mage.abilities.Ability) Player(mage.players.Player) MageObject(mage.MageObject) CovenHint(mage.abilities.hint.common.CovenHint) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 32 with TargetCardInLibrary

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

the class DarkDecisionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(new FilterNonlandCard());
        target.setCardLimit(10);
        if (controller.searchLibrary(target, source, game)) {
            UUID targetId = target.getFirstTarget();
            Card card = game.getCard(targetId);
            if (card != null) {
                controller.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
                ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfTurn);
                effect.setTargetPointer(new FixedTarget(card.getId(), game));
                game.addEffect(effect, source);
            }
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 33 with TargetCardInLibrary

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

the class EnigmaticIncarnationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0 || !player.chooseUse(outcome, "Sacrifice an enchantment?", source, game)) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(0, 1, filter, true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    game.getState().processAction(game);
    int cmc = permanent.getManaValue();
    if (!permanent.sacrifice(source, game)) {
        return false;
    }
    FilterCard filterCard = new FilterCreatureCard("creature card with mana value " + (cmc + 1));
    filterCard.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, cmc + 1));
    return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filterCard)).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterControlledEnchantmentPermanent(mage.filter.common.FilterControlledEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 34 with TargetCardInLibrary

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

the class GigantiformEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller != null && 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) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 35 with TargetCardInLibrary

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

the class GrimReminderWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_NON_LAND);
        if (controller.searchLibrary(target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                Cards cardsToReveal = new CardsImpl(card);
                controller.revealCards(sourceObject.getIdName(), cardsToReveal, game);
                String cardName = card.getName();
                GrimReminderWatcher watcher = game.getState().getWatcher(GrimReminderWatcher.class);
                if (watcher != null) {
                    for (UUID playerId : watcher.getPlayersCastSpell(cardName)) {
                        Player player = game.getPlayer(playerId);
                        if (player != null) {
                            player.loseLife(6, game, source, false);
                        }
                    }
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) 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