Search in sources :

Example 6 with SearchLibraryPutInHandEffect

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

the class CustomTestCard method addCustomEffect_ReturnFromAnyToHand.

/**
 * Return target card to hand that can be called by text "return from ..."
 *
 * @param controller
 */
protected void addCustomEffect_ReturnFromAnyToHand(TestPlayer controller) {
    // graveyard
    Ability ability = new SimpleActivatedAbility(new ReturnFromGraveyardToHandTargetEffect().setText("return from graveyard"), new ManaCostsImpl(""));
    ability.addTarget(new TargetCardInGraveyard(StaticFilters.FILTER_CARD));
    addCustomCardWithAbility("return from graveyard for " + controller.getName(), controller, ability);
    // exile
    ability = new SimpleActivatedAbility(new ReturnFromExileEffect(Zone.HAND).setText("return from exile"), new ManaCostsImpl(""));
    ability.addTarget(new TargetCardInExile(StaticFilters.FILTER_CARD));
    addCustomCardWithAbility("return from exile for " + controller.getName(), controller, ability);
    // library
    ability = new SimpleActivatedAbility(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD)).setText("return from library"), new ManaCostsImpl(""));
    addCustomCardWithAbility("return from library for " + controller.getName(), controller, ability);
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SpellAbility(mage.abilities.SpellAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetCardInExile(mage.target.common.TargetCardInExile) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) ReturnFromGraveyardToHandTargetEffect(mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 7 with SearchLibraryPutInHandEffect

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

the class RegularExpression method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    List<NamePredicate> predicates = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().map(Permanent::getName).filter(Objects::nonNull).filter(s -> !s.isEmpty()).map(NamePredicate::new).collect(Collectors.toList());
    FilterCard filter = new FilterCard("a creature card with the same name as another creature you control");
    filter.add(Predicates.or(predicates));
    return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 8 with SearchLibraryPutInHandEffect

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

the class TitheEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int numYourLands = game.getBattlefield().countAll(new FilterLandPermanent(), source.getControllerId(), game);
    int numOpponentLands = game.getBattlefield().countAll(new FilterLandPermanent(), this.getTargetPointer().getFirst(game, source), game);
    new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, (numOpponentLands > numYourLands ? 2 : 1), filter), true).apply(game, source);
    return true;
}
Also used : FilterLandPermanent(mage.filter.common.FilterLandPermanent) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 9 with SearchLibraryPutInHandEffect

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

the class InfernalTutorEffect 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 && sourceObject != null) {
        if (!controller.getHand().isEmpty()) {
            Card cardToReveal = null;
            if (controller.getHand().size() > 1) {
                Target target = new TargetCardInHand(StaticFilters.FILTER_CARD);
                target.setNotTarget(true);
                if (controller.chooseTarget(outcome, target, source, game)) {
                    cardToReveal = game.getCard(target.getFirstTarget());
                }
            } else {
                cardToReveal = controller.getHand().getRandom(game);
            }
            FilterCard filterCard;
            if (cardToReveal != null) {
                controller.revealCards("from hand :" + sourceObject.getName(), new CardsImpl(cardToReveal), game);
                String nameToSearch = CardUtil.getCardNameForSameNameSearch(cardToReveal);
                filterCard = new FilterCard("card named " + nameToSearch);
                filterCard.add(new NamePredicate(nameToSearch));
            } else {
                filterCard = new FilterCard();
            }
            return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true).apply(game, source);
        }
        return true;
    }
    return false;
}
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 10 with SearchLibraryPutInHandEffect

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

the class PackHuntEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    FilterCard filter = new FilterPermanentCard();
    filter.add(new NamePredicate(permanent.getName()));
    return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 3, filter), true).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

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