Search in sources :

Example 36 with ManaValuePredicate

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

the class HibernationsEndEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourcePermanent != null && player != null) {
        int newConvertedCost = sourcePermanent.getCounters(game).getCount("age");
        FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
        filter.add(CardType.CREATURE.getPredicate());
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        return new SearchLibraryPutInPlayEffect(target).apply(game, source);
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 37 with ManaValuePredicate

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

the class LightPawsEmperorsVoiceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent aura = (Permanent) getValue("permanentEnteringBattlefield");
    if (player == null || aura == null || !player.chooseUse(outcome, "Search for an Aura?", source, game)) {
        return false;
    }
    FilterCard filter = new FilterCard("Aura card with mana value less than or equal to " + aura.getManaValue());
    filter.add(SubType.AURA.getPredicate());
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, aura.getManaValue() + 1));
    filter.add(LightPawsEmperorsVoiceEffectPredicate.instance);
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    player.searchLibrary(target, source, game);
    Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (card != null && permanent != null && new AuraCardCanAttachToPermanentId(permanent.getId()).apply(card, game)) {
        game.getState().setValue("attachTo:" + card.getId(), permanent);
        player.moveCards(card, Zone.BATTLEFIELD, source, game);
        permanent.addAttachment(card.getId(), source, game);
    }
    player.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 38 with ManaValuePredicate

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

the class ScrapWelderCost method getFixedCostsFromAnnouncedValue.

@Override
public Cost getFixedCostsFromAnnouncedValue(int xValue) {
    FilterControlledArtifactPermanent filter = new FilterControlledArtifactPermanent("an artifact with mana value " + xValue);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, xValue));
    return new SacrificeTargetCost(filter);
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent)

Example 39 with ManaValuePredicate

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

the class VillainousWealthEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller != null && mageObject != null) {
        Player player = game.getPlayer(targetPointer.getFirst(game, source));
        FilterCard filter = new FilterNonlandCard();
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
        UUID exileId = CardUtil.getCardExileZoneId(game, source);
        if (player != null) {
            Cards cardsToExile = new CardsImpl();
            cardsToExile.addAll(player.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
            controller.moveCards(cardsToExile, Zone.EXILED, source, game);
            if (controller.chooseUse(Outcome.PlayForFree, "Cast cards exiled with " + mageObject.getLogName() + "  without paying its mana cost?", source, game)) {
                OuterLoop: while (cardsToExile.count(filter, game) > 0) {
                    if (!controller.canRespond()) {
                        return false;
                    }
                    TargetCardInExile target = new TargetCardInExile(0, 1, filter, exileId, false);
                    target.setNotTarget(true);
                    while (controller.canRespond() && cardsToExile.count(filter, game) > 0 && controller.choose(Outcome.PlayForFree, cardsToExile, target, 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) {
                                cardsToExile.remove(card);
                            }
                        } else {
                            break OuterLoop;
                        }
                        target.clearChosen();
                    }
                }
            }
        }
        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) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) TargetCardInExile(mage.target.common.TargetCardInExile) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard)

Example 40 with ManaValuePredicate

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

the class BirthingPodEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent == null || controller == null) {
        return false;
    }
    int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
    FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
    filter.add(CardType.CREATURE.getPredicate());
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) 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