Search in sources :

Example 86 with FilterCard

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

the class SkullwinderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        TargetOpponent targetOpponent = new TargetOpponent(true);
        if (controller.choose(Outcome.Detriment, targetOpponent, source.getSourceId(), game)) {
            Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
            if (opponent != null) {
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName());
                // That player returns a card from their graveyard to their hand
                TargetCardInYourGraveyard targetCard = new TargetCardInYourGraveyard(new FilterCard("a card from your graveyard to return to your hand"));
                targetCard.setNotTarget(true);
                if (opponent.choose(outcome, targetCard, source.getSourceId(), game)) {
                    Card card = game.getCard(targetCard.getFirstTarget());
                    if (card != null) {
                        opponent.moveCards(card, Zone.HAND, source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) MageObject(mage.MageObject) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 87 with FilterCard

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

the class StormHeraldAttachableToPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        FilterCard filter = new FilterCard("aura cards to attach to creatures you control");
        filter.add(SubType.AURA.getPredicate());
        filter.add(new StormHeraldAttachablePredicate(controller.getId()));
        Set<Card> possibleTargets = controller.getGraveyard().getCards(filter, source.getSourceId(), controller.getId(), game);
        if (!possibleTargets.isEmpty()) {
            TargetCard targetAuras = new TargetCard(0, Integer.MAX_VALUE, Zone.GRAVEYARD, filter);
            targetAuras.setNotTarget(true);
            controller.chooseTarget(outcome, new CardsImpl(possibleTargets), targetAuras, source, game);
            // Move the cards to the battlefield to a creature you control
            List<Permanent> toExile = new ArrayList<>();
            for (UUID auraId : targetAuras.getTargets()) {
                Card auraCard = game.getCard(auraId);
                if (auraCard != null) {
                    FilterPermanent filterAttachTo = new FilterControlledCreaturePermanent("creature you control to attach " + auraCard.getIdName() + " to");
                    filterAttachTo.add(new StormHeraldAttachableToPredicate(auraCard));
                    TargetPermanent targetCreature = new TargetPermanent(filterAttachTo);
                    targetCreature.setNotTarget(true);
                    if (controller.choose(Outcome.PutCardInPlay, targetCreature, source.getSourceId(), game)) {
                        Permanent targetPermanent = game.getPermanent(targetCreature.getFirstTarget());
                        if (!targetPermanent.cantBeAttachedBy(auraCard, source, game, true)) {
                            game.getState().setValue("attachTo:" + auraCard.getId(), targetPermanent);
                            controller.moveCards(auraCard, Zone.BATTLEFIELD, source, game);
                            targetPermanent.addAttachment(auraCard.getId(), source, game);
                            Permanent permanent = game.getPermanent(auraId);
                            if (permanent != null) {
                                toExile.add(permanent);
                            }
                        }
                    }
                }
            }
            ContinuousEffect continuousEffect = new StormHeraldReplacementEffect();
            continuousEffect.setTargetPointer(new FixedTargets(toExile, game));
            game.addEffect(continuousEffect, source);
            Effect exileEffect = new ExileTargetEffect("exile those Auras");
            exileEffect.setTargetPointer(new FixedTargets(toExile, game));
            game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect), source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FixedTargets(mage.target.targetpointer.FixedTargets) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 88 with FilterCard

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

the class StonehewerGiantEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterCard filter = new FilterCard("Equipment");
    filter.add(SubType.EQUIPMENT.getPredicate());
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        if (card != null) {
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            Permanent equipment = game.getPermanent(card.getId());
            Target targetCreature = new TargetControlledCreaturePermanent();
            targetCreature.setNotTarget(true);
            if (equipment != null && controller.choose(Outcome.BoostCreature, targetCreature, source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(targetCreature.getFirstTarget());
                permanent.addAttachment(equipment.getId(), source, game);
            }
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 89 with FilterCard

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

the class VoidEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int number = controller.announceXMana(0, Integer.MAX_VALUE, this.staticText, game, source);
    game.informPlayers(controller.getLogName() + " chooses " + number + '.');
    for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
        if ((permanent.isArtifact(game) || permanent.isCreature(game)) && permanent.getManaValue() == number) {
            permanent.destroy(source, game, false);
        }
    }
    FilterCard filterCard = new FilterCard();
    filterCard.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, number));
    filterCard.add(Predicates.not(CardType.LAND.getPredicate()));
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (targetPlayer == null) {
        return true;
    }
    targetPlayer.revealCards(source, targetPlayer.getHand(), game);
    targetPlayer.discard(new CardsImpl(targetPlayer.getHand().getCards(filterCard, game)), false, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) CardsImpl(mage.cards.CardsImpl)

Example 90 with FilterCard

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

the class VoidMawCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Player controller = game.getPlayer(controllerId);
    if (controller != null) {
        TargetCardInExile target = new TargetCardInExile(new FilterCard(), CardUtil.getCardExileZoneId(game, ability));
        target.setNotTarget(true);
        Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, ability));
        if (cards != null && !cards.isEmpty() && controller.choose(Outcome.Benefit, cards, target, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                if (controller.moveCardToGraveyardWithInfo(card, source, game, Zone.EXILED)) {
                    paid = true;
                }
            }
        }
    }
    return paid;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile) Cards(mage.cards.Cards) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

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