Search in sources :

Example 51 with ManaValuePredicate

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

the class TransmuteEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        FilterCard filter = new FilterCard("card with mana value " + sourceObject.getManaValue());
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, sourceObject.getManaValue()));
        TargetCardInLibrary target = new TargetCardInLibrary(1, filter);
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                Cards revealed = new CardsImpl(target.getTargets());
                controller.revealCards(sourceObject.getIdName(), revealed, game);
                controller.moveCards(revealed, Zone.HAND, 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) MageObject(mage.MageObject) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 52 with ManaValuePredicate

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

the class SoulshiftAbility method trigger.

@Override
public void trigger(Game game, UUID controllerId, GameEvent triggeringEvent) {
    this.getTargets().clear();
    int intValue = amount.calculate(game, this, null);
    FilterCard filter = new FilterCard("Spirit card with mana value " + intValue + " or less from your graveyard");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, intValue + 1));
    filter.add(SubType.SPIRIT.getPredicate());
    this.addTarget(new TargetCardInYourGraveyard(filter));
    // To change body of generated methods, choose Tools | Templates.
    super.trigger(game, controllerId, triggeringEvent);
}
Also used : FilterCard(mage.filter.FilterCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard)

Example 53 with ManaValuePredicate

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

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

Example 55 with ManaValuePredicate

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

the class MercadianLiftEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int numberOfCounters = 0;
        for (Cost cost : source.getCosts()) {
            if (cost instanceof RemoveVariableCountersSourceCost) {
                numberOfCounters = ((RemoveVariableCountersSourceCost) cost).getAmount();
            }
        }
        System.out.println("The number is " + numberOfCounters);
        FilterCreatureCard filter = new FilterCreatureCard();
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, numberOfCounters));
        filter.setMessage("creature card with mana value " + numberOfCounters);
        TargetCardInHand target = new TargetCardInHand(filter);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(Outcome.PutCardInPlay, "Put " + filter.getMessage() + " from your hand onto the battlefield?", source, game) && controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
            target.setRequired(false);
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) RemoveVariableCountersSourceCost(mage.abilities.costs.common.RemoveVariableCountersSourceCost) RemoveVariableCountersSourceCost(mage.abilities.costs.common.RemoveVariableCountersSourceCost) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) FilterCreatureCard(mage.filter.common.FilterCreatureCard) 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