Search in sources :

Example 71 with Card

use of mage.cards.Card in project mage by magefree.

the class SuddenReclamationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cardsToHand = new CardsImpl();
        Target target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD);
        target.setNotTarget(true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                cardsToHand.add(card);
            }
        }
        target = new TargetCardInYourGraveyard(new FilterLandCard("land card from your graveyard"));
        target.setNotTarget(true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                cardsToHand.add(card);
            }
        }
        controller.moveCards(cardsToHand, Zone.HAND, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterLandCard(mage.filter.common.FilterLandCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterLandCard(mage.filter.common.FilterLandCard) Card(mage.cards.Card)

Example 72 with Card

use of mage.cards.Card 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 73 with Card

use of mage.cards.Card 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 74 with Card

use of mage.cards.Card in project mage by magefree.

the class TezzeretTheSeekerEffect3 method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof PayVariableLoyaltyCost) {
            cmc = ((PayVariableLoyaltyCost) cost).getAmount();
        }
    }
    FilterArtifactCard filter = new FilterArtifactCard("artifact card with mana value " + cmc + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
    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);
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) PayVariableLoyaltyCost(mage.abilities.costs.common.PayVariableLoyaltyCost) FilterArtifactCard(mage.filter.common.FilterArtifactCard) Cost(mage.abilities.costs.Cost) PayVariableLoyaltyCost(mage.abilities.costs.common.PayVariableLoyaltyCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 75 with Card

use of mage.cards.Card in project mage by magefree.

the class TestOfTalentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    if (stackObject == null) {
        return false;
    }
    MageObject targetObject = game.getObject(stackObject.getSourceId());
    String cardName;
    if (targetObject instanceof Card) {
        cardName = targetObject.getName();
    } else {
        cardName = "";
    }
    UUID searchPlayerId = stackObject.getControllerId();
    Player player = game.getPlayer(searchPlayerId);
    if (player == null) {
        return false;
    }
    int previousCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
    game.getStack().counter(source.getFirstTarget(), source, game);
    this.applySearchAndExile(game, source, cardName, searchPlayerId);
    int newCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
    if (previousCount > newCount) {
        player.drawCards(previousCount - newCount, source, game);
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) SearchTargetGraveyardHandLibraryForCardNameAndExileEffect(mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) Card(mage.cards.Card) Ability(mage.abilities.Ability) TargetSpell(mage.target.TargetSpell) Player(mage.players.Player) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) Objects(java.util.Objects) UUID(java.util.UUID) Card(mage.cards.Card)

Aggregations

Card (mage.cards.Card)1448 Player (mage.players.Player)1096 Permanent (mage.game.permanent.Permanent)423 FilterCard (mage.filter.FilterCard)381 UUID (java.util.UUID)340 CardsImpl (mage.cards.CardsImpl)253 MageObject (mage.MageObject)212 FixedTarget (mage.target.targetpointer.FixedTarget)173 TargetCard (mage.target.TargetCard)165 Cards (mage.cards.Cards)159 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)111 ContinuousEffect (mage.abilities.effects.ContinuousEffect)99 TargetCardInHand (mage.target.common.TargetCardInHand)98 Target (mage.target.Target)86 HashSet (java.util.HashSet)85 FilterCreatureCard (mage.filter.common.FilterCreatureCard)84 ApprovingObject (mage.ApprovingObject)77 Ability (mage.abilities.Ability)71 TargetPlayer (mage.target.TargetPlayer)67 TargetPermanent (mage.target.TargetPermanent)64