Search in sources :

Example 66 with ManaValuePredicate

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

the class GenesisWaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
    if (!cards.isEmpty()) {
        controller.revealCards(source, cards, game);
        FilterCard filter = new FilterPermanentCard("cards with mana value " + xValue + " or less to put onto the battlefield");
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
        TargetCard target1 = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, filter);
        target1.setNotTarget(true);
        controller.choose(Outcome.PutCardInPlay, cards, target1, game);
        Cards toBattlefield = new CardsImpl(target1.getTargets());
        cards.removeAll(toBattlefield);
        controller.moveCards(toBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, false, null);
        controller.moveCards(cards, Zone.GRAVEYARD, source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCard(mage.target.TargetCard)

Example 67 with ManaValuePredicate

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

the class KodamaOfTheEastTreeWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Object obj = this.getValue("permanentEnteringBattlefield");
    if (!(obj instanceof Permanent)) {
        return false;
    }
    Permanent permanent = (Permanent) obj;
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    FilterCard filter = new FilterPermanentCard("a permanent card with mana value " + permanent.getManaValue() + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getManaValue() + 1));
    TargetCardInHand target = new TargetCardInHand(filter);
    if (!target.canChoose(source.getSourceId(), source.getControllerId(), game) || !player.chooseUse(outcome, "Put a permanent card onto the battlefield?", source, game)) {
        return false;
    }
    player.choose(outcome, target, source.getSourceId(), game);
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    Permanent otherPermanent = game.getPermanent(card.getId());
    if (otherPermanent == null) {
        return false;
    }
    KodamaOfTheEastTreeWatcher watcher = game.getState().getWatcher(KodamaOfTheEastTreeWatcher.class);
    if (watcher != null) {
        watcher.addPermanent(otherPermanent, source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

Example 68 with ManaValuePredicate

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

the class RelentlessDeadEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.chooseUse(Outcome.Benefit, "Do you want to pay {X} to return zombie?", source, game)) {
            int payCount = ManaUtil.playerPaysXGenericMana(true, "Relentless Dead", controller, source, game);
            // can be 0
            FilterCard filter = new FilterCard("Another target Zombie card with mana value {" + payCount + "}");
            filter.add(SubType.ZOMBIE.getPredicate());
            filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, payCount));
            filter.add(new AnotherCardPredicate());
            TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
            if (controller.chooseTarget(outcome, target, source, game)) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) AnotherCardPredicate(mage.filter.predicate.mageobject.AnotherCardPredicate) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 69 with ManaValuePredicate

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

the class ScrapTrawlerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
        Permanent permanent = ((ZoneChangeEvent) event).getTarget();
        if (permanent != null && permanent.isControlledBy(this.getControllerId()) && permanent.isArtifact(game)) {
            FilterCard filter = new FilterArtifactCard("artifact card in your graveyard with mana value less than " + permanent.getManaCost().manaValue());
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getManaCost().manaValue()));
            TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
            getTargets().clear();
            addTarget(target);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) FilterArtifactCard(mage.filter.common.FilterArtifactCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard)

Example 70 with ManaValuePredicate

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

the class SunbirdsInvocationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
    if (spell == null) {
        return false;
    }
    int xValue = spell.getManaValue();
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
    if (!cards.isEmpty()) {
        controller.revealCards(sourceObject.getIdName(), cards, game);
        FilterCard filter = new FilterNonlandCard("card revealed this way with mana value " + xValue + " or less");
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
        TargetCard target = new TargetCard(1, Zone.LIBRARY, filter);
        if (controller.chooseTarget(Outcome.PlayForFree, cards, target, source, game)) {
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                if (controller.chooseUse(Outcome.Benefit, "Cast " + card.getLogName() + " without paying its mana cost?", source, game)) {
                    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) {
                        cards.remove(card);
                    }
                }
            }
        }
        controller.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Spell(mage.game.stack.Spell) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

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