Search in sources :

Example 6 with FilterPermanentCard

use of mage.filter.common.FilterPermanentCard in project mage by magefree.

the class MatterReshaperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = controller.getLibrary().getFromTop(game);
        if (card == null) {
            return false;
        }
        controller.revealCards(source, new CardsImpl(card), game);
        FilterPermanentCard filter = new FilterPermanentCard("permanent card with mana value 3 or less");
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 4));
        if (filter.match(card, game)) {
            if (controller.chooseUse(Outcome.PutCardInPlay, "Put " + card.getName() + " onto the battlefield (otherwise put in hand)?", source, game)) {
                controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                return true;
            }
        }
        controller.moveCards(card, Zone.HAND, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) CardsImpl(mage.cards.CardsImpl) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Card(mage.cards.Card)

Example 7 with FilterPermanentCard

use of mage.filter.common.FilterPermanentCard in project mage by magefree.

the class MinnWilyIllusionistEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = (Permanent) getValue("creatureDied");
    if (player == null || permanent == null) {
        return false;
    }
    FilterCard filterCard = new FilterPermanentCard("permanent card with mana value " + permanent.getPower().getValue() + " or less");
    filterCard.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getPower().getValue() + 1));
    TargetCardInHand target = new TargetCardInHand(0, 1, filterCard);
    player.choose(Outcome.PutCardInPlay, player.getHand(), target, game);
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    return player.moveCards(card, Zone.BATTLEFIELD, source, game);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Card(mage.cards.Card)

Example 8 with FilterPermanentCard

use of mage.filter.common.FilterPermanentCard in project mage by magefree.

the class SisayWeatherlightCaptainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (permanent == null) {
        return false;
    }
    int power = permanent.getPower().getValue();
    FilterCard filter = new FilterPermanentCard("legendary permanent card with mana value less than " + power);
    filter.add(SuperType.LEGENDARY.getPredicate());
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, power));
    return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter)).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 9 with FilterPermanentCard

use of mage.filter.common.FilterPermanentCard in project mage by magefree.

the class InSearchOfGreatnessEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = 0;
    UUID permId = source.getSourceId();
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controller.getId())) {
        if (permanent != null && !permanent.getId().equals(permId)) {
            int permCmc = permanent.getManaValue();
            if (permCmc > cmc) {
                cmc = permCmc;
            }
        }
    }
    if (controller.chooseUse(outcome, "Cast a permanent spell from your hand with CMC equal to " + ++cmc + "?", source, game)) {
        FilterPermanentCard filter = new FilterPermanentCard("permanent spell from your hand");
        filter.add(Predicates.not(CardType.LAND.getPredicate()));
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, cmc));
        TargetCardInHand target = new TargetCardInHand(filter);
        if (controller.chooseTarget(outcome, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                if (cardWasCast) {
                    return true;
                }
            }
        }
    }
    return controller.scry(1, source, game);
}
Also used : Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Card(mage.cards.Card)

Example 10 with FilterPermanentCard

use of mage.filter.common.FilterPermanentCard in project mage by magefree.

the class LonisCryptozoologistEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && opponent != null) {
        int xValue = GetXValue.instance.calculate(game, source, this);
        Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, xValue));
        opponent.revealCards(source, cards, game);
        if (controller.chooseUse(outcome, "Put a nonland permanent card with mana value " + xValue + " or less from among revealed cards onto the battlefield under your control?", source, game)) {
            FilterPermanentCard filter = new FilterPermanentCard("nonland permanent card with mana value " + xValue + " or less");
            filter.add(Predicates.not(CardType.LAND.getPredicate()));
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
            TargetCard target = new TargetCard(Zone.LIBRARY, filter);
            if (controller.choose(outcome, cards, target, game)) {
                Card selectedCard = game.getCard(target.getFirstTarget());
                if (selectedCard != null) {
                    cards.remove(selectedCard);
                    controller.moveCards(selectedCard, Zone.BATTLEFIELD, source, game);
                }
            }
        }
        opponent.putCardsOnBottomOfLibrary(cards, game, source, false);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCard(mage.target.TargetCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) TargetCard(mage.target.TargetCard)

Aggregations

FilterPermanentCard (mage.filter.common.FilterPermanentCard)19 Player (mage.players.Player)16 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)12 FilterCard (mage.filter.FilterCard)11 Card (mage.cards.Card)9 Permanent (mage.game.permanent.Permanent)8 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)6 TargetCard (mage.target.TargetCard)5 CardsImpl (mage.cards.CardsImpl)4 TargetCardInHand (mage.target.common.TargetCardInHand)4 UUID (java.util.UUID)2 MageObject (mage.MageObject)2 SearchLibraryPutInPlayEffect (mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)2 Cards (mage.cards.Cards)2 FilterPermanent (mage.filter.FilterPermanent)2 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)2 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)2 ApprovingObject (mage.ApprovingObject)1 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)1 SpellAbility (mage.abilities.SpellAbility)1