Search in sources :

Example 76 with ManaValuePredicate

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

the class SarulfRealmEaterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (player == null || permanent == null) {
        return false;
    }
    int counterCount = permanent.getCounters(game).getCount(CounterType.P1P1);
    permanent.removeCounters(CounterType.P1P1.createInstance(counterCount), source, game);
    FilterPermanent filter = new FilterNonlandPermanent();
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, counterCount + 1));
    filter.add(AnotherPredicate.instance);
    Cards cards = new CardsImpl();
    game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(MageItem::getId).forEach(cards::add);
    return player.moveCards(cards, Zone.EXILED, source, game);
}
Also used : Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) Objects(java.util.Objects) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 77 with ManaValuePredicate

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

the class VenerableWarsingerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player player = game.getPlayer(event.getPlayerId());
    if (player == null || !event.getSourceId().equals(getSourceId()) || !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    FilterCard filter = new FilterCreatureCard("creature card with mana value " + event.getAmount() + " less from your graveyard");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, event.getAmount() + 1));
    this.getTargets().clear();
    this.addTarget(new TargetCardInYourGraveyard(filter));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) DamagedEvent(mage.game.events.DamagedEvent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard)

Example 78 with ManaValuePredicate

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

the class CovertTechnicianEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int damage = (Integer) getValue("damage");
    FilterCard filter = new FilterArtifactCard("artifact card with mana value " + damage + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, damage + 1));
    return new PutCardFromHandOntoBattlefieldEffect(filter).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterArtifactCard(mage.filter.common.FilterArtifactCard) PutCardFromHandOntoBattlefieldEffect(mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect)

Example 79 with ManaValuePredicate

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

the class AetherVialEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
    if (permanent == null) {
        permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
        if (permanent == null) {
            return false;
        }
    }
    int count = permanent.getCounters(game).getCount(CounterType.CHARGE);
    FilterCreatureCard filter = new FilterCreatureCard("creature card with mana value equal to " + count);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, count));
    String choiceText = "Put a " + filter.getMessage() + " from your hand onto the battlefield?";
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    if (controller.getHand().count(filter, game) == 0 || !controller.chooseUse(this.outcome, choiceText, source, game)) {
        return true;
    }
    TargetCardInHand target = new TargetCardInHand(filter);
    if (controller.choose(this.outcome, target, source.getSourceId(), game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
    }
    return false;
}
Also used : FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 80 with ManaValuePredicate

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

the class BrainInAJarScryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourceObject != null) {
        int counters = sourceObject.getCounters(game).getCount(CounterType.CHARGE);
        FilterCard filter = new FilterInstantOrSorceryCard();
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, counters));
        int cardsToCast = controller.getHand().count(filter, source.getControllerId(), source.getSourceId(), game);
        if (cardsToCast > 0 && controller.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery card with mana values of " + counters + " from your hand without paying its mana cost?", source, game)) {
            TargetCardInHand target = new TargetCardInHand(filter);
            controller.chooseTarget(outcome, target, source, 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) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) 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