Search in sources :

Example 76 with Card

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

the class TheBiblioplexEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Card card = player.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    player.lookAtCards("Top of library", card, game);
    if (card.isInstantOrSorcery(game) && player.chooseUse(Outcome.DrawCard, "Reveal that card and put it into your hand?", source, game)) {
        player.revealCards(source, new CardsImpl(card), game);
        player.moveCards(card, Zone.HAND, source, game);
    } else if (player.chooseUse(Outcome.Discard, "Put that card into your graveyard?", source, game)) {
        player.moveCards(card, Zone.GRAVEYARD, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 77 with Card

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

the class TransmuteArtifactEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    // Sacrifice an artifact.
    int manaValue = 0;
    boolean sacrifice = false;
    TargetControlledPermanent targetArtifact = new TargetControlledPermanent(new FilterControlledArtifactPermanent());
    if (controller.chooseTarget(Outcome.Sacrifice, targetArtifact, source, game)) {
        Permanent permanent = game.getPermanent(targetArtifact.getFirstTarget());
        if (permanent != null) {
            manaValue = permanent.getManaValue();
            sacrifice = permanent.sacrifice(source, game);
        }
    } else {
        return true;
    }
    // If you do, search your library for an artifact card.
    if (sacrifice && controller.searchLibrary(target, source, game)) {
        if (!target.getTargets().isEmpty()) {
            for (UUID cardId : target.getTargets()) {
                Card card = controller.getLibrary().getCard(cardId, game);
                if (card != null) {
                    // If that card's converted mana cost is less than or equal to the sacrificed artifact's converted mana cost, put it onto the battlefield.
                    if (card.getManaValue() <= manaValue) {
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                    } else {
                        // If it's greater, you may pay {X}, where X is the difference. If you do, put it onto the battlefield.
                        Cost cost = ManaUtil.createManaCost(card.getManaValue() - manaValue, true);
                        boolean payed = false;
                        if (controller.chooseUse(Outcome.Benefit, "Do you want to pay " + cost.getText() + " to put it onto the battlefield?", source, game) && cost.pay(source, game, source, source.getControllerId(), false)) {
                            payed = true;
                        }
                        if (payed) {
                            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                        } else {
                            // If you don't, put it into its owner's graveyard. Then shuffle your library
                            controller.moveCards(card, Zone.GRAVEYARD, source, game);
                        }
                    }
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 78 with Card

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

the class TrackDownEffect 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) {
        return false;
    }
    if (!controller.getLibrary().hasCards()) {
        return false;
    }
    Card card = controller.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    CardsImpl cards = new CardsImpl();
    cards.add(card);
    controller.revealCards(sourceObject.getName(), cards, game);
    if (card.isLand(game) || card.isCreature(game)) {
        controller.drawCards(1, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 79 with Card

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

the class VaevictisAsmadiTheDireEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Player> playersToFlip = new ArrayList<>();
    for (Target target : source.getTargets()) {
        for (UUID permId : target.getTargets()) {
            Permanent permanent = game.getPermanent(permId);
            if (permanent == null || !permanent.sacrifice(source, game)) {
                continue;
            }
            Player player = game.getPlayer(permanent.getControllerId());
            if (player != null) {
                playersToFlip.add(player);
            }
        }
    }
    for (Player player : playersToFlip) {
        if (player == null) {
            return false;
        }
        Card card = player.getLibrary().getFromTop(game);
        if (card == null) {
            continue;
        }
        player.revealCards(source, new CardsImpl(card), game);
        if (card.isPermanent(game)) {
            player.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 80 with Card

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

the class ExileAllCardsFromAllGraveyards method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject Valki = game.getObject(source.getSourceId());
    Set<Card> cardsToExile = new LinkedHashSet<>();
    if (controller != null && Valki != null) {
        UUID exileId = CardUtil.getExileZoneId(source.getSourceId().toString() + Valki.getZoneChangeCounter(game), game);
        for (UUID opponentId : game.getOpponents(controller.getId())) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                opponent.revealCards(source, opponent.getHand(), game);
                TargetCard targetToExile = new TargetCard(Zone.HAND, StaticFilters.FILTER_CARD_CREATURE);
                targetToExile.withChooseHint("card to exile");
                targetToExile.setNotTarget(true);
                if (controller.choose(Outcome.Exile, opponent.getHand(), targetToExile, game)) {
                    Card targetedCardToExile = game.getCard(targetToExile.getFirstTarget());
                    if (targetedCardToExile != null && game.getState().getZone(source.getSourceId()) == Zone.BATTLEFIELD) {
                        cardsToExile.add(targetedCardToExile);
                    }
                }
            }
        }
        // exile all cards at one time
        controller.moveCardsToExile(cardsToExile, source, game, true, exileId, Valki.getName());
        game.addDelayedTriggeredAbility(new ValkiGodOfLiesReturnExiledCardAbility(), source);
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard)

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