Search in sources :

Example 11 with CardIdPredicate

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

the class ForgottenLoreEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (you != null && opponent != null) {
        FilterCard filter = new FilterCard();
        filter.add(new OwnerIdPredicate(you.getId()));
        Cost cost = new ManaCostsImpl("{G}");
        TargetCardInGraveyard chosenCard;
        Card card = null;
        boolean done = false;
        do {
            chosenCard = new TargetCardInGraveyard(filter);
            chosenCard.setNotTarget(true);
            if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
                opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
                card = game.getCard(chosenCard.getFirstTarget());
                if (card != null) {
                    filter.add(Predicates.not(new CardIdPredicate(card.getId())));
                    game.informPlayers("Forgotten Lore: " + opponent.getLogName() + " has chosen " + card.getLogName());
                }
            } else {
                done = true;
            }
            if (!done) {
                if (cost.canPay(source, source, you.getId(), game) && you.chooseUse(Outcome.Benefit, "Pay {G} to choose a different card ?", source, game)) {
                    cost.clearPaid();
                    if (!cost.pay(source, game, source, you.getId(), false, null)) {
                        done = true;
                    }
                } else {
                    done = true;
                }
            }
        } while (!done);
        if (card != null) {
            Cards cardsToHand = new CardsImpl();
            cardsToHand.add(card);
            you.moveCards(cardsToHand, Zone.HAND, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) FilterCard(mage.filter.FilterCard) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 12 with CardIdPredicate

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

the class OmnispellAdeptEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterCard realFilter = filter.copy();
    Target target = new TargetCardInHand(realFilter);
    // choose one card until it possible to cast
    if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery " + "card from your hand without paying its mana cost?", source, game)) {
        Card cardToCast;
        while (controller.canRespond() && controller.chooseTarget(Outcome.PlayForFree, target, source, game)) {
            cardToCast = game.getCard(target.getFirstTarget());
            if (cardToCast == null) {
                break;
            }
            // remove card from choose dialog (infinite fix)
            realFilter.add(Predicates.not(new CardIdPredicate(cardToCast.getId())));
            if (!cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
                continue;
            }
            game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
            Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
            if (cardWasCast) {
                break;
            } else {
                game.informPlayer(controller, "You're not able to cast " + cardToCast.getIdName() + " or you canceled the casting.");
            }
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 13 with CardIdPredicate

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

the class MarkForDeathEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent target = game.getPermanent(source.getFirstTarget());
    if (target == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new ControllerIdPredicate(target.getControllerId()));
    filter.add(Predicates.not(new CardIdPredicate(target.getId())));
    ContinuousEffect effect = new BlocksIfAbleTargetEffect(Duration.EndOfTurn);
    effect.setTargetPointer(new FixedTarget(target.getId()));
    game.addEffect(effect, source);
    target.untap(game);
    ContinuousEffect effect2 = new CantBlockAllEffect(filter, Duration.EndOfTurn);
    game.addEffect(effect2, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BlocksIfAbleTargetEffect(mage.abilities.effects.common.combat.BlocksIfAbleTargetEffect) CantBlockAllEffect(mage.abilities.effects.common.combat.CantBlockAllEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 14 with CardIdPredicate

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

the class SigilOfValorCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    Permanent equipment = game.getPermanent(sourceAbility.getSourceId());
    if (equipment != null && equipment.getAttachedTo() != null) {
        FilterPermanent filterPermanent = new FilterControlledCreaturePermanent();
        filterPermanent.add(Predicates.not(new CardIdPredicate(equipment.getAttachedTo())));
        return game.getBattlefield().count(filterPermanent, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
    }
    return 0;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 15 with CardIdPredicate

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

the class TheMimeoplasmEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (controller != null && permanent != null) {
        if (new CardsInAllGraveyardsCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this) >= 2) {
            if (controller.chooseUse(Outcome.Benefit, "Do you want to exile two creature cards from graveyards?", source, game)) {
                TargetCardInGraveyard targetCopy = new TargetCardInGraveyard(new FilterCreatureCard("creature card to become a copy of"));
                targetCopy.setNotTarget(true);
                if (controller.choose(Outcome.Copy, targetCopy, source.getSourceId(), game)) {
                    Card cardToCopy = game.getCard(targetCopy.getFirstTarget());
                    if (cardToCopy != null) {
                        FilterCreatureCard filter = new FilterCreatureCard("creature card to determine amount of additional +1/+1 counters");
                        filter.add(Predicates.not(new CardIdPredicate(cardToCopy.getId())));
                        TargetCardInGraveyard targetCounters = new TargetCardInGraveyard(filter);
                        targetCounters.setNotTarget(true);
                        if (controller.choose(Outcome.Copy, targetCounters, source.getSourceId(), game)) {
                            Card cardForCounters = game.getCard(targetCounters.getFirstTarget());
                            if (cardForCounters != null) {
                                Cards cardsToExile = new CardsImpl();
                                cardsToExile.add(cardToCopy);
                                cardsToExile.add(cardForCounters);
                                controller.moveCards(cardsToExile, Zone.EXILED, source, game);
                                CopyEffect copyEffect = new CopyEffect(Duration.Custom, cardToCopy, source.getSourceId());
                                game.addEffect(copyEffect, source);
                                permanent.addCounters(CounterType.P1P1.createInstance(cardForCounters.getPower().getValue()), source.getControllerId(), source, game);
                            }
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Permanent(mage.game.permanent.Permanent) CardsInAllGraveyardsCount(mage.abilities.dynamicvalue.common.CardsInAllGraveyardsCount) FilterCreatureCard(mage.filter.common.FilterCreatureCard) 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