Search in sources :

Example 1 with ManaValuePredicate

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

the class DiscipleOfDeceitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (player != null && mageObject != null) {
        Cost cost = new DiscardTargetCost(new TargetCardInHand(new FilterNonlandCard()));
        String message = "Discard a nonland card to search your library?";
        if (cost.canPay(source, source, source.getControllerId(), game) && player.chooseUse(Outcome.Detriment, message, source, game)) {
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                Card card = game.getCard(cost.getTargets().getFirstTarget());
                if (card == null) {
                    return false;
                }
                String targetName = "card with mana value of " + card.getManaValue();
                FilterCard filter = new FilterCard(targetName);
                filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, card.getManaValue()));
                return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true).apply(game, source);
            }
        }
        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) TargetCardInHand(mage.target.common.TargetCardInHand) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) MageObject(mage.MageObject) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) Cost(mage.abilities.costs.Cost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 2 with ManaValuePredicate

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

the class DispersalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Set<PermanentIdPredicate> permsToReturn = new HashSet<>();
    for (UUID opponentId : game.getOpponents(player.getId())) {
        Player opponent = game.getPlayer(opponentId);
        if (opponent == null) {
            continue;
        }
        int highestCMC = 0;
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) {
            if (permanent != null) {
                highestCMC = Math.max(highestCMC, permanent.getManaValue());
            }
        }
        FilterPermanent filter = new FilterNonlandPermanent("permanent you control with mana value " + highestCMC);
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, highestCMC));
        filter.add(new ControllerIdPredicate(opponentId));
        Target target = new TargetPermanent(1, 1, filter, true);
        if (opponent.choose(outcome, target, source.getSourceId(), game)) {
            if (target.getFirstTarget() == null) {
                continue;
            }
            permsToReturn.add(new PermanentIdPredicate(target.getFirstTarget()));
        }
    }
    FilterPermanent filter = new FilterPermanent();
    filter.add(Predicates.or(permsToReturn));
    new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
    new DiscardEachPlayerEffect(StaticValue.get(1), false, TargetController.OPPONENT).apply(game, source);
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ReturnToHandFromBattlefieldAllEffect(mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect) DiscardEachPlayerEffect(mage.abilities.effects.common.discard.DiscardEachPlayerEffect) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Target(mage.target.Target) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) HashSet(java.util.HashSet)

Example 3 with ManaValuePredicate

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

the class FiendArtisanEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int xValue = source.getManaCostsToPay().getX();
    FilterCard filter = new FilterCreatureCard("creature card with mana value " + xValue + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter)).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 4 with ManaValuePredicate

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

the class HatcherySpiderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this);
    FilterCard filter = new FilterPermanentCard("green permanent card with mana value " + xValue + " or less");
    filter.add(new ColorPredicate(ObjectColor.GREEN));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCard target = new TargetCardInLibrary(filter);
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
    if (player.chooseUse(outcome, "Put a card onto the battlefield?", source, game) && player.choose(outcome, cards, target, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
            cards.remove(card);
        }
    }
    while (!cards.isEmpty()) {
        Card card = cards.getRandom(game);
        player.getLibrary().putOnBottom(card, game);
        cards.remove(card);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCard(mage.target.TargetCard) CardsInControllerGraveyardCount(mage.abilities.dynamicvalue.common.CardsInControllerGraveyardCount) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

Example 5 with ManaValuePredicate

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

the class KozilekDiscardCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Spell targetSpell = game.getStack().getSpell(ability.getFirstTarget());
    if (targetSpell == null) {
        return false;
    }
    Player player = game.getPlayer(controllerId);
    if (player == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card with mana value of " + targetSpell.getManaValue());
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, targetSpell.getManaValue()));
    TargetCardInHand target = new TargetCardInHand(filter);
    this.getTargets().clear();
    this.getTargets().add(target);
    if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), game)) {
        for (UUID targetId : targets.get(0).getTargets()) {
            Card card = player.getHand().get(targetId, game);
            if (card == null) {
                return false;
            }
            player.discard(card, true, source, game);
            paid = true;
        }
    }
    return paid;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterSpell(mage.filter.FilterSpell) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

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