Search in sources :

Example 11 with FilterLandCard

use of mage.filter.common.FilterLandCard in project mage by magefree.

the class ElvishRejuvenatorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    cards.addAll(controller.getLibrary().getTopCards(game, 5));
    if (!cards.isEmpty()) {
        TargetCard target = new TargetCard(0, 1, Zone.LIBRARY, new FilterLandCard("land card to put on the battlefield"));
        if (controller.choose(Outcome.PutCardInPlay, cards, target, game)) {
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                cards.remove(card);
                controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, true, null);
            }
        }
        if (!cards.isEmpty()) {
            controller.putCardsOnBottomOfLibrary(cards, game, source, false);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterLandCard(mage.filter.common.FilterLandCard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterLandCard(mage.filter.common.FilterLandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 12 with FilterLandCard

use of mage.filter.common.FilterLandCard in project mage by magefree.

the class HiredGiantEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Player> playersThatSearched = new HashSet<>(1);
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (!playerId.equals(controller.getId())) {
                Player player = game.getPlayer(playerId);
                if (player != null && player.chooseUse(Outcome.PutCreatureInPlay, "Search your library for a land card and put it onto the battlefield?", source, game)) {
                    TargetCardInLibrary target = new TargetCardInLibrary(new FilterLandCard());
                    if (player.searchLibrary(target, source, game)) {
                        Card targetCard = player.getLibrary().getCard(target.getFirstTarget(), game);
                        if (targetCard != null) {
                            player.moveCards(targetCard, Zone.BATTLEFIELD, source, game);
                            playersThatSearched.add(player);
                        }
                    }
                }
            }
        }
        for (Player player : playersThatSearched) {
            player.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterLandCard(mage.filter.common.FilterLandCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) HashSet(java.util.HashSet) FilterLandCard(mage.filter.common.FilterLandCard) Card(mage.cards.Card)

Example 13 with FilterLandCard

use of mage.filter.common.FilterLandCard in project mage by magefree.

the class RoilingTerrainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetedLand = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (targetedLand != null) {
        targetedLand.destroy(source, game, true);
        Player targetController = game.getPlayer(targetedLand.getControllerId());
        if (targetController != null) {
            int landsInGraveyard = targetController.getGraveyard().count(new FilterLandCard(), game);
            targetController.damage(landsInGraveyard, source.getSourceId(), source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterLandCard(mage.filter.common.FilterLandCard)

Example 14 with FilterLandCard

use of mage.filter.common.FilterLandCard in project mage by magefree.

the class TemptWithDiscoveryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<UUID> playersShuffle = new LinkedHashSet<>();
        playersShuffle.add(controller.getId());
        TargetCardInLibrary target = new TargetCardInLibrary(new FilterLandCard());
        if (controller.searchLibrary(target, source, game)) {
            for (UUID cardId : target.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                }
            }
        }
        int opponentsUsedSearch = 0;
        for (UUID playerId : game.getOpponents(controller.getId())) {
            Player opponent = game.getPlayer(playerId);
            if (opponent != null) {
                if (opponent.chooseUse(outcome, "Search your library for a land card and put it onto the battlefield?", source, game)) {
                    target.clearChosen();
                    opponentsUsedSearch++;
                    playersShuffle.add(playerId);
                    if (opponent.searchLibrary(target, source, game)) {
                        for (UUID cardId : target.getTargets()) {
                            Card card = game.getCard(cardId);
                            if (card != null) {
                                opponent.moveCards(card, Zone.BATTLEFIELD, source, game);
                            }
                        }
                    }
                }
            }
        }
        if (opponentsUsedSearch > 0) {
            target = new TargetCardInLibrary(0, opponentsUsedSearch, new FilterLandCard());
            if (controller.searchLibrary(target, source, game)) {
                for (UUID cardId : target.getTargets()) {
                    Card card = game.getCard(cardId);
                    if (card != null) {
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                    }
                }
            }
        }
        for (UUID playerId : playersShuffle) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                player.shuffleLibrary(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) FilterLandCard(mage.filter.common.FilterLandCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterLandCard(mage.filter.common.FilterLandCard) Card(mage.cards.Card)

Example 15 with FilterLandCard

use of mage.filter.common.FilterLandCard in project mage by magefree.

the class MoxDiamondReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        TargetCardInHand target = new TargetCardInHand(new FilterLandCard());
        Cost cost = new DiscardTargetCost(target);
        if (cost.canPay(source, source, source.getControllerId(), game) && player.chooseUse(outcome, "Discard land? (Otherwise Mox Diamond goes to graveyard)", source, game) && player.chooseTarget(Outcome.Discard, target, source, game)) {
            player.discard(game.getCard(target.getFirstTarget()), false, source, game);
            return false;
        } else {
            Permanent permanent = game.getPermanentEntering(event.getTargetId());
            if (permanent != null) {
                player.moveCards(permanent, Zone.GRAVEYARD, source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) FilterLandCard(mage.filter.common.FilterLandCard) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) Cost(mage.abilities.costs.Cost)

Aggregations

FilterLandCard (mage.filter.common.FilterLandCard)17 Player (mage.players.Player)17 Card (mage.cards.Card)7 CardsImpl (mage.cards.CardsImpl)7 UUID (java.util.UUID)6 Permanent (mage.game.permanent.Permanent)6 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)6 Cards (mage.cards.Cards)5 TargetCard (mage.target.TargetCard)4 LinkedHashSet (java.util.LinkedHashSet)3 MageObject (mage.MageObject)3 TargetCardInHand (mage.target.common.TargetCardInHand)3 HashSet (java.util.HashSet)1 Cost (mage.abilities.costs.Cost)1 DiscardTargetCost (mage.abilities.costs.common.DiscardTargetCost)1 SetPowerToughnessSourceEffect (mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect)1 FilterCard (mage.filter.FilterCard)1 FilterPermanent (mage.filter.FilterPermanent)1 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)1 FilterLandPermanent (mage.filter.common.FilterLandPermanent)1