Search in sources :

Example 31 with FilterCard

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

the class SufferThePastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterCard filter = new FilterCard("card in target player's graveyard");
    int numberExiled = 0;
    Player you = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (targetPlayer != null) {
        int numberToTarget = Math.min(targetPlayer.getGraveyard().size(), source.getManaCostsToPay().getX());
        TargetCardInOpponentsGraveyard target = new TargetCardInOpponentsGraveyard(numberToTarget, numberToTarget, filter);
        if (you != null) {
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
                if (!target.getTargets().isEmpty()) {
                    List<UUID> targets = target.getTargets();
                    for (UUID targetId : targets) {
                        Card card = game.getCard(targetId);
                        if (card != null) {
                            card.moveToExile(id, "Suffer the Past", source, game);
                            numberExiled++;
                        }
                    }
                    you.gainLife(numberExiled, game, source);
                    targetPlayer.loseLife(numberExiled, game, source, false);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 32 with FilterCard

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

the class CardCanBeCastPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.getLibrary().hasCards()) {
            /**
             * 10/1/2005 Any card you find must be legally cast-able (for
             * example, you have to be able to choose a legal target for
             * it). If you can't find a cast-able card (or choose not to),
             * nothing happens and you shuffle your library.
             */
            FilterCard filter = new FilterCard("red or white instant card with mana value 4 or less");
            TargetCardInLibrary target = new TargetCardInLibrary(filter);
            filter.add(Predicates.or(new ColorPredicate(ObjectColor.RED), new ColorPredicate(ObjectColor.WHITE)));
            filter.add(CardType.INSTANT.getPredicate());
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 5));
            filter.add(new CardCanBeCastPredicate(source.getControllerId()));
            if (controller.searchLibrary(target, source, game, controller.getId())) {
                UUID targetId = target.getFirstTarget();
                Card card = game.getCard(targetId);
                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);
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 33 with FilterCard

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

the class ZarethSanTheTricksterTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player opponent = game.getPlayer(event.getPlayerId());
    if (opponent == null || !event.getSourceId().equals(this.sourceId) || !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    FilterCard filter = new FilterPermanentCard("permanent card in " + opponent.getLogName() + "'s graveyard");
    filter.add(new OwnerIdPredicate(opponent.getId()));
    this.getTargets().clear();
    this.addTarget(new TargetCardInGraveyard(filter));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) DamagedEvent(mage.game.events.DamagedEvent)

Example 34 with FilterCard

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

the class ReplaceOpponentCardsInHandWithSelectedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && targetOpponent != null) {
        int originalHandSize = targetOpponent.getHand().size();
        if (originalHandSize > 0) {
            targetOpponent.putCardsOnTopOfLibrary(targetOpponent.getHand(), game, source, false);
            int librarySize = targetOpponent.getLibrary().size();
            int searchLibraryForNum = min(originalHandSize, librarySize);
            TargetCardInLibrary target = new TargetCardInLibrary(searchLibraryForNum, searchLibraryForNum, new FilterCard());
            controller.searchLibrary(target, source, game, targetOpponent.getId());
            for (UUID cardId : target.getTargets()) {
                Card targetCard = game.getCard(cardId);
                targetOpponent.moveCards(targetCard, Zone.HAND, source, game);
            }
            targetOpponent.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 35 with FilterCard

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

the class CardSelector method buildFilter.

private FilterCard buildFilter() {
    FilterCard filter = new FilterCard();
    String name = jTextFieldSearch.getText().trim();
    filter.add(new CardTextPredicate(name, chkNames.isSelected(), chkTypes.isSelected(), chkRules.isSelected(), chkUnique.isSelected()));
    if (limited) {
        List<Predicate<MageObject>> predicates = new ArrayList<>();
        if (this.tbGreen.isSelected()) {
            predicates.add(new ColorPredicate(ObjectColor.GREEN));
        }
        if (this.tbRed.isSelected()) {
            predicates.add(new ColorPredicate(ObjectColor.RED));
        }
        if (this.tbBlack.isSelected()) {
            predicates.add(new ColorPredicate(ObjectColor.BLACK));
        }
        if (this.tbBlue.isSelected()) {
            predicates.add(new ColorPredicate(ObjectColor.BLUE));
        }
        if (this.tbWhite.isSelected()) {
            predicates.add(new ColorPredicate(ObjectColor.WHITE));
        }
        if (this.tbColorless.isSelected()) {
            predicates.add(ColorlessPredicate.instance);
        }
        filter.add(Predicates.or(predicates));
        predicates.clear();
        if (this.tbLand.isSelected()) {
            predicates.add(CardType.LAND.getPredicate());
        }
        if (this.tbArifiacts.isSelected()) {
            predicates.add(CardType.ARTIFACT.getPredicate());
        }
        if (this.tbCreatures.isSelected()) {
            predicates.add(CardType.CREATURE.getPredicate());
        }
        if (this.tbEnchantments.isSelected()) {
            predicates.add(CardType.ENCHANTMENT.getPredicate());
        }
        if (this.tbInstants.isSelected()) {
            predicates.add(CardType.INSTANT.getPredicate());
        }
        if (this.tbSorceries.isSelected()) {
            predicates.add(CardType.SORCERY.getPredicate());
        }
        if (this.tbPlaneswalkers.isSelected()) {
            predicates.add(CardType.PLANESWALKER.getPredicate());
        }
        filter.add(Predicates.or(predicates));
        List<String> filteredSets = getFilteredSets();
        if (!filteredSets.isEmpty()) {
            List<Predicate<Card>> expansionPredicates = new ArrayList<>();
            for (String setCode : filteredSets) {
                expansionPredicates.add(new ExpansionSetPredicate(setCode));
            }
            filter.add(Predicates.or(expansionPredicates));
        }
    }
    return filter;
}
Also used : FilterCard(mage.filter.FilterCard) CardTextPredicate(mage.filter.predicate.card.CardTextPredicate) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ExpansionSetPredicate(mage.filter.predicate.card.ExpansionSetPredicate) Predicate(mage.filter.predicate.Predicate) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ColorlessPredicate(mage.filter.predicate.mageobject.ColorlessPredicate) CardTextPredicate(mage.filter.predicate.card.CardTextPredicate) ExpansionSetPredicate(mage.filter.predicate.card.ExpansionSetPredicate)

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