Search in sources :

Example 61 with ManaValuePredicate

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

the class KahoMinamoHistorianCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        FilterCard filter = new FilterCard();
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
        TargetCardInExile target = new TargetCardInExile(filter, CardUtil.getCardExileZoneId(game, source));
        Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
        if (cards != null && !cards.isEmpty() && controller.choose(Outcome.PlayForFree, cards, target, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) TargetCardInExile(mage.target.common.TargetCardInExile) FilterCard(mage.filter.FilterCard)

Example 62 with ManaValuePredicate

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

the class TajNarSwordsmithEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null && player.chooseUse(Outcome.Benefit, "Do you want to pay {X} to search and put Equipment?", source, game)) {
        // can be zero
        int payCount = ManaUtil.playerPaysXGenericMana(true, "Taj-Nar Swordsmith", player, source, game);
        FilterCard filter = new FilterCard("Equipment card with mana value {" + payCount + "} or less");
        filter.add(SubType.EQUIPMENT.getPredicate());
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, payCount + 1));
        new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(0, 1, filter), false, true).apply(game, source);
        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) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 63 with ManaValuePredicate

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

the class UginTheSpiritDragonEffect3 method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof PayVariableLoyaltyCost) {
            cmc = ((PayVariableLoyaltyCost) cost).getAmount();
        }
    }
    FilterPermanent filter = new FilterPermanent("permanent with mana value X or less that's one or more colors");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
    filter.add(Predicates.not(ColorlessPredicate.instance));
    Set<Card> permanentsToExile = new HashSet<>();
    permanentsToExile.addAll(game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game));
    controller.moveCards(permanentsToExile, Zone.EXILED, source, game);
    return true;
}
Also used : Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) PayVariableLoyaltyCost(mage.abilities.costs.common.PayVariableLoyaltyCost) Cost(mage.abilities.costs.Cost) PayVariableLoyaltyCost(mage.abilities.costs.common.PayVariableLoyaltyCost) Card(mage.cards.Card) FilterPermanentCard(mage.filter.common.FilterPermanentCard) HashSet(java.util.HashSet)

Example 64 with ManaValuePredicate

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

the class EvershrikeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card evershrikeCard = game.getCard(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || evershrikeCard == null) {
        return false;
    }
    int xAmount = source.getManaCostsToPay().getX();
    controller.moveCards(evershrikeCard, Zone.BATTLEFIELD, source, game);
    Permanent evershrikePermanent = game.getPermanent(evershrikeCard.getId());
    if (evershrikePermanent == null) {
        if (game.getState().getZone(evershrikeCard.getId()) != Zone.EXILED) {
            controller.moveCards(evershrikeCard, Zone.EXILED, source, game);
        }
        return false;
    }
    boolean exileSource = true;
    FilterCard filterAuraCard = new FilterCard("Aura card with mana value X or less from your hand");
    filterAuraCard.add(CardType.ENCHANTMENT.getPredicate());
    filterAuraCard.add(SubType.AURA.getPredicate());
    filterAuraCard.add(new AuraCardCanAttachToPermanentId(evershrikePermanent.getId()));
    filterAuraCard.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xAmount + 1));
    int count = controller.getHand().count(filterAuraCard, game);
    if (count > 0 && controller.chooseUse(Outcome.Benefit, "Put an Aura card from your hand onto the battlefield attached to " + evershrikeCard.getIdName() + "?", source, game)) {
        TargetCard targetAura = new TargetCard(Zone.HAND, filterAuraCard);
        if (controller.choose(Outcome.Benefit, controller.getHand(), targetAura, game)) {
            Card aura = game.getCard(targetAura.getFirstTarget());
            if (aura != null) {
                game.getState().setValue("attachTo:" + aura.getId(), evershrikePermanent);
                if (controller.moveCards(aura, Zone.BATTLEFIELD, source, game)) {
                    evershrikePermanent.addAttachment(aura.getId(), source, game);
                }
                exileSource = false;
            }
        }
    }
    if (exileSource) {
        controller.moveCards(evershrikeCard, Zone.EXILED, source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 65 with ManaValuePredicate

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

the class GenesisHydraPutOntoBattlefieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Object obj = getValue(CastSourceTriggeredAbility.SOURCE_CAST_SPELL_ABILITY);
    if (controller != null && obj instanceof SpellAbility) {
        int count = ((SpellAbility) obj).getManaCostsToPay().getX();
        if (count > 0) {
            Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, count));
            controller.revealCards(source, cards, game);
            FilterCard filter = new FilterPermanentCard("a nonland permanent card with mana value " + count + " or less to put onto the battlefield");
            filter.add(Predicates.not(CardType.LAND.getPredicate()));
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, count + 1));
            TargetCard target1 = new TargetCard(Zone.LIBRARY, filter);
            target1.setRequired(false);
            if (cards.count(filter, controller.getId(), source.getSourceId(), game) > 0) {
                if (controller.choose(Outcome.PutCardInPlay, cards, target1, game)) {
                    Card card = cards.get(target1.getFirstTarget(), game);
                    if (card != null) {
                        cards.remove(card);
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                    }
                    target1.clearChosen();
                } else {
                    game.informPlayers(controller.getLogName() + " didn't choose anything");
                }
            } else {
                game.informPlayers("No nonland permanent card with mana value " + count + " or less to choose.");
            }
            if (!cards.isEmpty()) {
                controller.moveCards(cards, Zone.LIBRARY, source, game);
                controller.shuffleLibrary(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) SpellAbility(mage.abilities.SpellAbility) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) TargetCard(mage.target.TargetCard)

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