Search in sources :

Example 41 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class CephalidShrineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int count = 0;
    MageObject mageObject = game.getObject(source.getSourceId());
    if (mageObject != null) {
        Spell spell = (Spell) game.getState().getValue("cephalidShrine" + mageObject);
        if (spell != null) {
            Player controller = game.getPlayer(spell.getControllerId());
            if (controller != null) {
                String name = spell.getName();
                FilterCard filterCardName = new FilterCard();
                filterCardName.add(new NamePredicate(name));
                for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
                    Player player = game.getPlayer(playerId);
                    if (player != null) {
                        count += player.getGraveyard().count(filterCardName, game);
                    }
                }
                // even if the cost is 0, we still offer
                Cost cost = ManaUtil.createManaCost(count, true);
                if (game.getStack().contains(spell) && cost.canPay(source, source, controller.getId(), game) && controller.chooseUse(outcome, "Pay " + cost.getText() + " to prevent countering " + spell.getName() + "?", source, game) && cost.pay(source, game, source, controller.getId(), false) && cost.isPaid()) {
                    return false;
                } else {
                    game.getStack().counter(spell.getId(), source, game);
                    game.informPlayers(spell.getName() + " has been countered due to " + controller.getName() + " not paying " + cost.getText());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) MageObject(mage.MageObject) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) Spell(mage.game.stack.Spell)

Example 42 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class ColfenorTheLastYewTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!super.checkTrigger(event, game)) {
        return false;
    }
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Permanent permanent = zEvent.getTarget();
    if (permanent == null) {
        return false;
    }
    FilterCard filterCard = new FilterCreatureCard("creature card with toughness less than " + permanent.getToughness().getValue());
    filterCard.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, permanent.getToughness().getValue()));
    filterCard.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(permanent, game))));
    this.getTargets().clear();
    this.addTarget(new TargetCardInYourGraveyard(0, 1, filterCard));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) MageObjectReference(mage.MageObjectReference)

Example 43 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class CommuneWithTheGodsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
        if (!cards.isEmpty()) {
            FilterCard filterPutInHand = new FilterCard("creature or enchantment card to put in hand");
            filterPutInHand.add(Predicates.or(CardType.CREATURE.getPredicate(), CardType.ENCHANTMENT.getPredicate()));
            controller.revealCards(source, cards, game);
            if (cards.count(filterPutInHand, source.getSourceId(), source.getControllerId(), game) > 0) {
                TargetCard target = new TargetCard(0, 1, Zone.LIBRARY, filterPutInHand);
                if (controller.choose(Outcome.DrawCard, cards, target, game)) {
                    Card card = game.getCard(target.getFirstTarget());
                    if (card != null) {
                        cards.remove(card);
                        controller.moveCards(card, Zone.HAND, source, game);
                    }
                }
            }
            controller.moveCards(cards, Zone.GRAVEYARD, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 44 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class DarkIntimationsReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<UUID> perms = new ArrayList<>();
    filter.add(TargetController.YOU.getControllerPredicate());
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            TargetPermanent target = new TargetPermanent(1, 1, filter, true);
            if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Sacrifice, target, source, game);
                perms.addAll(target.getTargets());
            }
        }
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            permanent.sacrifice(source, game);
        }
    }
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            player.discardOne(false, false, source, game);
        }
    }
    TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filterCard);
    if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card == null) {
            return false;
        }
        controller.moveCards(card, Zone.HAND, source, game);
    }
    controller.drawCards(1, source, game);
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetPermanent(mage.target.TargetPermanent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 45 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class DoublingChantTarget method makeFilter.

private static FilterCard makeFilter(Set<String> names) {
    FilterCard filter = new FilterCreatureCard();
    filter.add(Predicates.or(names.stream().map(name -> new NamePredicate(name)).collect(Collectors.toSet())));
    return filter;
}
Also used : FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) StaticFilters(mage.filter.StaticFilters) java.util(java.util) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) mage.cards(mage.cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) CardUtil(mage.util.CardUtil) Collectors(java.util.stream.Collectors) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Game(mage.game.Game) CardType(mage.constants.CardType) MageObject(mage.MageObject) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Ability(mage.abilities.Ability) FilterCreatureCard(mage.filter.common.FilterCreatureCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate)

Aggregations

FilterCard (mage.filter.FilterCard)337 Player (mage.players.Player)287 Card (mage.cards.Card)148 TargetCard (mage.target.TargetCard)127 UUID (java.util.UUID)97 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)87 Permanent (mage.game.permanent.Permanent)79 MageObject (mage.MageObject)75 CardsImpl (mage.cards.CardsImpl)75 Cards (mage.cards.Cards)60 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)56 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)54 Target (mage.target.Target)41 TargetCardInHand (mage.target.common.TargetCardInHand)41 TargetPlayer (mage.target.TargetPlayer)35 ApprovingObject (mage.ApprovingObject)29 FilterCreatureCard (mage.filter.common.FilterCreatureCard)25 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)24 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)22 ArrayList (java.util.ArrayList)21