Search in sources :

Example 1 with SearchLibraryPutInHandEffect

use of mage.abilities.effects.common.search.SearchLibraryPutInHandEffect in project mage by magefree.

the class DiscipleOfDeceitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (player != null && mageObject != null) {
        Cost cost = new DiscardTargetCost(new TargetCardInHand(new FilterNonlandCard()));
        String message = "Discard a nonland card to search your library?";
        if (cost.canPay(source, source, source.getControllerId(), game) && player.chooseUse(Outcome.Detriment, message, source, game)) {
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                Card card = game.getCard(cost.getTargets().getFirstTarget());
                if (card == null) {
                    return false;
                }
                String targetName = "card with mana value of " + card.getManaValue();
                FilterCard filter = new FilterCard(targetName);
                filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, card.getManaValue()));
                return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true).apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCardInHand(mage.target.common.TargetCardInHand) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) MageObject(mage.MageObject) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) Cost(mage.abilities.costs.Cost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 2 with SearchLibraryPutInHandEffect

use of mage.abilities.effects.common.search.SearchLibraryPutInHandEffect in project mage by magefree.

the class MausoleumSecretsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int critterCount = player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game);
    FilterCard filter = new FilterCard("a black card with mana value less than or equal to " + critterCount);
    filter.add(new ColorPredicate(ObjectColor.BLACK));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, critterCount + 1));
    return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 3 with SearchLibraryPutInHandEffect

use of mage.abilities.effects.common.search.SearchLibraryPutInHandEffect in project mage by magefree.

the class RemembranceTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!((ZoneChangeEvent) event).isDiesEvent()) {
        return false;
    }
    Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
    if (permanent != null && filter.match(permanent, game)) {
        FilterCard filterCard = new FilterCard("card named " + permanent.getName());
        filterCard.add(new NamePredicate(permanent.getName()));
        this.getEffects().clear();
        this.addEffect(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true));
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 4 with SearchLibraryPutInHandEffect

use of mage.abilities.effects.common.search.SearchLibraryPutInHandEffect in project mage by magefree.

the class GoblinTutorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int amount = controller.rollDice(outcome, source, game, 6);
        Effect effect = null;
        // 6 - An instant or sorcery card
        if (amount == 2) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, filter), true);
        } else if (amount == 3) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_ENTCHANTMENT), true);
        } else if (amount == 4) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_ARTIFACT), true);
        } else if (amount == 5) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_CREATURE), true);
        } else if (amount == 6) {
            effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, new FilterInstantOrSorceryCard()), true);
        }
        if (effect != null) {
            effect.apply(game, source);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 5 with SearchLibraryPutInHandEffect

use of mage.abilities.effects.common.search.SearchLibraryPutInHandEffect 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)

Aggregations

SearchLibraryPutInHandEffect (mage.abilities.effects.common.search.SearchLibraryPutInHandEffect)13 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)13 FilterCard (mage.filter.FilterCard)10 Player (mage.players.Player)7 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)5 Card (mage.cards.Card)4 MageObject (mage.MageObject)3 Cost (mage.abilities.costs.Cost)3 DiscardTargetCost (mage.abilities.costs.common.DiscardTargetCost)3 Permanent (mage.game.permanent.Permanent)3 TargetCardInHand (mage.target.common.TargetCardInHand)3 CardsImpl (mage.cards.CardsImpl)2 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)2 Target (mage.target.Target)2 Ability (mage.abilities.Ability)1 SpellAbility (mage.abilities.SpellAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)1