Search in sources :

Example 21 with ManaValuePredicate

use of mage.filter.predicate.mageobject.ManaValuePredicate 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 22 with ManaValuePredicate

use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.

the class NecroplasmEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (player != null && sourcePermanent != null) {
        int numCounters = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, numCounters));
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            if (permanent != null) {
                permanent.destroy(source, game, false);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Example 23 with ManaValuePredicate

use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.

the class RallyTheAncestorsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        int xValue = source.getManaCostsToPay().getX();
        FilterCreatureCard filter = new FilterCreatureCard();
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
        Set<Card> cards = player.getGraveyard().getCards(filter, game);
        player.moveCards(cards, Zone.BATTLEFIELD, source, game);
        List<Permanent> toExile = new ArrayList<>(cards.size());
        for (Card card : cards) {
            if (card != null) {
                Permanent permanent = game.getPermanent(card.getId());
                if (permanent != null) {
                    toExile.add(permanent);
                }
            }
        }
        Effect exileEffect = new ExileTargetEffect("Exile those creatures at the beginning of your next upkeep");
        exileEffect.setTargetPointer(new FixedTargets(toExile, game));
        DelayedTriggeredAbility delayedAbility = new AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(exileEffect);
        game.addDelayedTriggeredAbility(delayedAbility, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FixedTargets(mage.target.targetpointer.FixedTargets) ArrayList(java.util.ArrayList) AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ExileSpellEffect(mage.abilities.effects.common.ExileSpellEffect) Effect(mage.abilities.effects.Effect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 24 with ManaValuePredicate

use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.

the class VoidEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int number = controller.announceXMana(0, Integer.MAX_VALUE, this.staticText, game, source);
    game.informPlayers(controller.getLogName() + " chooses " + number + '.');
    for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
        if ((permanent.isArtifact(game) || permanent.isCreature(game)) && permanent.getManaValue() == number) {
            permanent.destroy(source, game, false);
        }
    }
    FilterCard filterCard = new FilterCard();
    filterCard.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, number));
    filterCard.add(Predicates.not(CardType.LAND.getPredicate()));
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (targetPlayer == null) {
        return true;
    }
    targetPlayer.revealCards(source, targetPlayer.getHand(), game);
    targetPlayer.discard(new CardsImpl(targetPlayer.getHand().getCards(filterCard, game)), false, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) CardsImpl(mage.cards.CardsImpl)

Example 25 with ManaValuePredicate

use of mage.filter.predicate.mageobject.ManaValuePredicate 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)

Aggregations

ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)84 Player (mage.players.Player)64 FilterCard (mage.filter.FilterCard)57 Card (mage.cards.Card)37 Permanent (mage.game.permanent.Permanent)33 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)31 FilterCreatureCard (mage.filter.common.FilterCreatureCard)16 FilterPermanent (mage.filter.FilterPermanent)15 CardsImpl (mage.cards.CardsImpl)14 FilterPermanentCard (mage.filter.common.FilterPermanentCard)13 TargetCard (mage.target.TargetCard)13 ApprovingObject (mage.ApprovingObject)11 Cost (mage.abilities.costs.Cost)10 TargetCardInHand (mage.target.common.TargetCardInHand)9 UUID (java.util.UUID)8 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)8 Cards (mage.cards.Cards)7 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)7 MageObject (mage.MageObject)6 SearchLibraryPutInPlayEffect (mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)6