Search in sources :

Example 6 with CardIdPredicate

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

the class JandorsRingWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    JandorsRingWatcher watcher = game.getState().getWatcher(JandorsRingWatcher.class);
    if (watcher != null) {
        UUID cardId = watcher.getLastDrewCard(source.getControllerId());
        Card card = game.getCard(cardId);
        if (card != null) {
            FilterCard filter = new FilterCard(card.getName());
            filter.add(new CardIdPredicate(card.getId()));
            DiscardCardYouChooseTargetEffect effect = new DiscardCardYouChooseTargetEffect(filter, TargetController.YOU);
            if (effect.apply(game, source)) {
                // Conditional was already checked, card should be in hand, but if for some weird reason it fails, the card won't be drawn, although the cost will already be paid
                Player controller = game.getPlayer(source.getControllerId());
                if (controller != null) {
                    controller.drawCards(1, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) DiscardCardYouChooseTargetEffect(mage.abilities.effects.common.discard.DiscardCardYouChooseTargetEffect) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 7 with CardIdPredicate

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

Example 8 with CardIdPredicate

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

the class ContinuousEffects method applySpliceEffects.

/**
 * Checks all available splice effects to be applied.
 *
 * @param abilityToModify
 * @param game
 */
public void applySpliceEffects(Ability abilityToModify, Game game) {
    // splice spell - spell can't be spliced again
    if (CardUtil.isSpliceAbility(abilityToModify, game)) {
        return;
    }
    // fused spell - can be spliced only to main fused ability, not to parts
    if (CardUtil.isFusedPartAbility(abilityToModify, game)) {
        return;
    }
    List<SpliceCardEffect> spliceEffects = getApplicableSpliceCardEffects(game, abilityToModify.getControllerId());
    // get the applyable splice abilities
    List<Ability> spliceAbilities = new ArrayList<>();
    for (SpliceCardEffect effect : spliceEffects) {
        Set<Ability> abilities = spliceCardEffects.getAbility(effect.getId());
        for (Ability ability : abilities) {
            if (effect.applies(abilityToModify, ability, game)) {
                spliceAbilities.add(ability);
            }
        }
    }
    if (!spliceAbilities.isEmpty()) {
        Player controller = game.getPlayer(abilityToModify.getControllerId());
        if (controller.chooseUse(Outcome.Benefit, "Splice a card?", abilityToModify, game)) {
            Cards cardsToReveal = new CardsImpl();
            do {
                FilterCard filter = new FilterCard("a card to splice");
                List<Predicate<MageObject>> idPredicates = new ArrayList<>();
                for (Ability ability : spliceAbilities) {
                    idPredicates.add(new CardIdPredicate((ability.getSourceId())));
                }
                filter.add(Predicates.or(idPredicates));
                TargetCardInHand target = new TargetCardInHand(filter);
                controller.chooseTarget(Outcome.Benefit, target, abilityToModify, game);
                UUID cardId = target.getFirstTarget();
                if (cardId != null) {
                    Ability selectedAbility = null;
                    for (Ability ability : spliceAbilities) {
                        if (ability.getSourceId().equals(cardId)) {
                            selectedAbility = ability;
                            break;
                        }
                    }
                    if (selectedAbility != null) {
                        SpliceCardEffect spliceEffect = (SpliceCardEffect) selectedAbility.getEffects().get(0);
                        spliceEffect.apply(game, selectedAbility, abilityToModify);
                        cardsToReveal.add(game.getCard(cardId));
                        spliceAbilities.remove(selectedAbility);
                    }
                }
            } while (!spliceAbilities.isEmpty() && controller.chooseUse(Outcome.Benefit, "Splice another card?", abilityToModify, game));
            controller.revealCards("Spliced cards", cardsToReveal, game);
        }
    }
}
Also used : StaticAbility(mage.abilities.StaticAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) Predicate(mage.filter.predicate.Predicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate) FilterCard(mage.filter.FilterCard) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 9 with CardIdPredicate

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

the class GuardianProjectEffect method checkCondition.

// This is needed as checkInterveningIfClause can't access trigger event information
static boolean checkCondition(Permanent permanent, UUID controllerId, Game game) {
    Player player = game.getPlayer(controllerId);
    if (player == null) {
        return false;
    }
    if (!permanent.getName().isEmpty()) {
        FilterCard filterCard = new FilterCard();
        filterCard.add(new NamePredicate(permanent.getName()));
        filterCard.add(new OwnerIdPredicate(controllerId));
        if (player.getGraveyard().count(filterCard, game) > 0) {
            return false;
        }
    }
    FilterPermanent filterPermanent = new FilterCreaturePermanent();
    filterPermanent.add(new NamePredicate(permanent.getName()));
    filterPermanent.add(Predicates.not(new CardIdPredicate(permanent.getId())));
    filterPermanent.add(new ControllerIdPredicate(controllerId));
    if (!game.getBattlefield().getActivePermanents(filterPermanent, controllerId, game).isEmpty()) {
        return false;
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 10 with CardIdPredicate

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

the class LilianaDreadhordeGeneralEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterPermanent keepFilter = new FilterPermanent();
    keepFilter.add(TargetController.OPPONENT.getControllerPredicate());
    for (UUID opponentId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player opponent = game.getPlayer(opponentId);
        if (opponent == null || !opponent.hasOpponent(source.getControllerId(), game)) {
            continue;
        }
        for (CardType cardType : CardType.values()) {
            if (!cardType.isPermanentType()) {
                continue;
            }
            FilterControlledPermanent filter = new FilterControlledPermanent("a " + cardType.toString() + " you control " + "(everything you don't choose will be sacrificed)");
            filter.add(cardType.getPredicate());
            Target target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (opponent.choose(outcome, target, source.getSourceId(), game)) {
                keepFilter.add(Predicates.not(new CardIdPredicate(target.getFirstTarget())));
            }
        }
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
        if (keepFilter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Aggregations

CardIdPredicate (mage.filter.predicate.mageobject.CardIdPredicate)18 Player (mage.players.Player)13 FilterCard (mage.filter.FilterCard)11 Permanent (mage.game.permanent.Permanent)10 UUID (java.util.UUID)7 FilterPermanent (mage.filter.FilterPermanent)6 Target (mage.target.Target)6 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)5 ArrayList (java.util.ArrayList)4 Card (mage.cards.Card)4 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)3 FilterCreatureCard (mage.filter.common.FilterCreatureCard)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 Predicate (mage.filter.predicate.Predicate)3 OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)3 TargetPermanent (mage.target.TargetPermanent)3 MageObject (mage.MageObject)2 Ability (mage.abilities.Ability)2 Cost (mage.abilities.costs.Cost)2 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)2