Search in sources :

Example 1 with Predicate

use of mage.filter.predicate.Predicate in project mage by magefree.

the class CounterlashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (stackObject != null && controller != null) {
        game.getStack().counter(source.getFirstTarget(), source, game);
        if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
            FilterCard filter = new FilterCard();
            List<Predicate<MageObject>> types = new ArrayList<>();
            for (CardType type : stackObject.getCardType(game)) {
                if (type != CardType.LAND) {
                    types.add(type.getPredicate());
                }
            }
            filter.add(Predicates.or(types));
            TargetCardInHand target = new TargetCardInHand(filter);
            if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
                Card card = controller.getHand().get(target.getFirstTarget(), game);
                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) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) ArrayList(java.util.ArrayList) Predicate(mage.filter.predicate.Predicate) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 2 with Predicate

use of mage.filter.predicate.Predicate in project mage by magefree.

the class ElementalAppealEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    CreateTokenEffect effect = new CreateTokenEffect(new RedElementalWithTrampleAndHaste());
    if (effect.apply(game, source)) {
        effect.exileTokensCreatedAtNextEndStep(game, source);
        if (KickedCondition.instance.apply(game, source)) {
            List<Predicate<MageObject>> predList = new ArrayList<>();
            for (UUID tokenId : effect.getLastAddedTokenIds()) {
                predList.add(new CardIdPredicate(tokenId));
            }
            if (!predList.isEmpty()) {
                FilterCreaturePermanent filter = new FilterCreaturePermanent();
                filter.add(Predicates.or(predList));
                game.addEffect(new BoostAllEffect(7, 0, Duration.EndOfTurn, filter, false), source);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) ArrayList(java.util.ArrayList) RedElementalWithTrampleAndHaste(mage.game.permanent.token.RedElementalWithTrampleAndHaste) UUID(java.util.UUID) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect) Predicate(mage.filter.predicate.Predicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 3 with Predicate

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

Example 4 with Predicate

use of mage.filter.predicate.Predicate in project mage by magefree.

the class CrypticGatewayPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (source.getCosts() == null) {
        return false;
    }
    FilterCard filter = new FilterCreatureCard("creature card from your hand that shares a creature type with each creature tapped this way");
    for (Cost cost : source.getCosts()) {
        if (cost instanceof CrypticGatewayCost) {
            Predicate predicate = ((CrypticGatewayCost) cost).getPredicate();
            filter.add(predicate);
            return new PutCardFromHandOntoBattlefieldEffect(filter).apply(game, source);
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) PutCardFromHandOntoBattlefieldEffect(mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect) Cost(mage.abilities.costs.Cost) Predicate(mage.filter.predicate.Predicate) TappedPredicate(mage.filter.predicate.permanent.TappedPredicate)

Example 5 with Predicate

use of mage.filter.predicate.Predicate in project mage by magefree.

the class NecromanticSelectionEffect 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) {
        Cards cards = new CardsImpl();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), source.getSourceId(), game)) {
            permanent.destroy(source, game, false);
            // Meren of the Clan Nel Toth bug #8515
            game.checkStateAndTriggered();
            if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) {
                cards.add(permanent);
            }
        }
        FilterCard filter = new FilterCreatureCard("creature card put into a graveyard with " + sourceObject.getLogName());
        List<Predicate<MageObject>> cardIdPredicates = new ArrayList<>();
        for (UUID cardId : cards) {
            cardIdPredicates.add(new CardIdPredicate(cardId));
        }
        filter.add(Predicates.or(cardIdPredicates));
        Target target = new TargetCardInGraveyard(filter);
        target.setNotTarget(true);
        if (controller.chooseTarget(Outcome.Benefit, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                ContinuousEffect effect = new BecomesBlackZombieAdditionEffect();
                effect.setText("It's a black Zombie in addition to its other colors and types");
                effect.setTargetPointer(new FixedTarget(card.getId(), game));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ArrayList(java.util.ArrayList) BecomesBlackZombieAdditionEffect(mage.abilities.effects.common.continuous.BecomesBlackZombieAdditionEffect) Predicate(mage.filter.predicate.Predicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate) FilterCreatureCard(mage.filter.common.FilterCreatureCard) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Aggregations

Predicate (mage.filter.predicate.Predicate)13 UUID (java.util.UUID)5 FilterCard (mage.filter.FilterCard)5 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)5 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)5 Player (mage.players.Player)5 Target (mage.target.Target)5 ArrayList (java.util.ArrayList)4 AbilityPredicate (mage.filter.predicate.mageobject.AbilityPredicate)4 BecomesFaceDownCreatureAllEffect (mage.abilities.effects.common.continuous.BecomesFaceDownCreatureAllEffect)3 CardIdPredicate (mage.filter.predicate.mageobject.CardIdPredicate)3 Permanent (mage.game.permanent.Permanent)3 MageObject (mage.MageObject)2 Ability (mage.abilities.Ability)2 FilterPermanent (mage.filter.FilterPermanent)2 FilterCreatureCard (mage.filter.common.FilterCreatureCard)2 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)2 TargetCardInHand (mage.target.common.TargetCardInHand)2 ApprovingObject (mage.ApprovingObject)1 MageItem (mage.MageItem)1