Search in sources :

Example 6 with FilterLandCard

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

the class AnimistsAwakeningEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    int xValue = source.getManaCostsToPay().getX();
    cards.addAll(controller.getLibrary().getTopCards(game, xValue));
    if (!cards.isEmpty()) {
        controller.revealCards(sourceObject.getIdName(), cards, game);
        Set<Card> toBattlefield = new LinkedHashSet<>();
        for (Card card : cards.getCards(new FilterLandCard(), source.getSourceId(), source.getControllerId(), game)) {
            cards.remove(card);
            toBattlefield.add(card);
        }
        controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, true, false, true, null);
        controller.putCardsOnBottomOfLibrary(cards, game, source, true);
        if (SpellMasteryCondition.instance.apply(game, source)) {
            for (Card card : toBattlefield) {
                Permanent land = game.getPermanent(card.getId());
                if (land != null) {
                    land.untap(game);
                }
            }
        }
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterLandCard(mage.filter.common.FilterLandCard) MageObject(mage.MageObject) FilterLandCard(mage.filter.common.FilterLandCard)

Example 7 with FilterLandCard

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

the class OblivionSowerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    /*
        8/25/2015: Oblivion Sower's ability allows you to put any land cards the player owns from exile onto the battlefield, regardless of how those cards were exiled.
        8/25/2015: Cards that are face down in exile have no characteristics. Such cards can't be put onto the battlefield with Oblivion Sower's ability.
         */
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && targetPlayer != null) {
        FilterLandCard filter = new FilterLandCard();
        filter.add(new OwnerIdPredicate(targetPlayer.getId()));
        filter.add(Predicates.not(FaceDownPredicate.instance));
        Cards exiledCards = new CardsImpl();
        exiledCards.addAll(game.getExile().getAllCards(game));
        Cards exiledLands = new CardsImpl();
        exiledLands.addAll(exiledCards.getCards(filter, source.getSourceId(), controller.getId(), game));
        if (!exiledLands.isEmpty() && controller.chooseUse(outcome, "Put lands into play?", source, game)) {
            FilterCard filterToPlay = new FilterCard("land" + (exiledLands.size() > 1 ? "s" : "") + " from exile owned by " + targetPlayer.getName() + " to put into play under your control");
            TargetCard targetCards = new TargetCard(0, exiledLands.size(), Zone.EXILED, filterToPlay);
            if (controller.chooseTarget(outcome, exiledLands, targetCards, source, game)) {
                controller.moveCards(new CardsImpl(targetCards.getTargets()), Zone.BATTLEFIELD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterLandCard(mage.filter.common.FilterLandCard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 8 with FilterLandCard

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

the class TheGreatAuroraEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<UUID, List<Permanent>> permanentsOwned = new HashMap<>();
        Collection<Permanent> permanents = game.getBattlefield().getActivePermanents(source.getControllerId(), game);
        for (Permanent permanent : permanents) {
            List<Permanent> list = permanentsOwned.computeIfAbsent(permanent.getOwnerId(), k -> new ArrayList<>());
            list.add(permanent);
        }
        // shuffle permanents and hand cards into owner's library
        Map<UUID, Integer> permanentsCount = new HashMap<>();
        for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int handCards = player.getHand().size();
                player.moveCards(player.getHand(), Zone.LIBRARY, source, game);
                List<Permanent> list = permanentsOwned.remove(player.getId());
                permanentsCount.put(playerId, handCards + (list != null ? list.size() : 0));
                if (list != null) {
                    for (Permanent permanent : list) {
                        player.moveCardToLibraryWithInfo(permanent, source, game, Zone.BATTLEFIELD, true, true);
                    }
                    player.shuffleLibrary(source, game);
                }
            }
        }
        // so effects from creatures that were on the battlefield won't trigger from draw or put into play
        game.getState().processAction(game);
        // Draw cards
        for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int count = permanentsCount.get(playerId);
                if (count > 0) {
                    player.drawCards(count, source, game);
                }
            }
        }
        // put lands onto the battlefield
        Cards toBattlefield = new CardsImpl();
        for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetCard target = new TargetCardInHand(0, Integer.MAX_VALUE, new FilterLandCard("put any number of land cards from your hand onto the battlefield"));
                player.chooseTarget(Outcome.PutLandInPlay, player.getHand(), target, source, game);
                toBattlefield.addAll(target.getTargets());
            }
        }
        return controller.moveCards(toBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) FilterLandCard(mage.filter.common.FilterLandCard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 9 with FilterLandCard

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

the class GerrardsVerdictEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && targetPlayer != null) {
        controller.gainLife(targetPlayer.discard(2, false, false, source, game).count(new FilterLandCard(), game) * 3, game, source);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterLandCard(mage.filter.common.FilterLandCard)

Example 10 with FilterLandCard

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

the class OreskosExplorerEffect 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) {
        return false;
    }
    int controllerLands = game.getBattlefield().countAll(new FilterLandPermanent(), controller.getId(), game);
    int landsToSearch = 0;
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        if (!playerId.equals(controller.getId())) {
            if (controllerLands < game.getBattlefield().countAll(new FilterLandPermanent(), playerId, game)) {
                landsToSearch++;
            }
        }
    }
    if (landsToSearch > 0) {
        FilterLandCard filterPlains = new FilterLandCard("up to " + landsToSearch + " Plains cards");
        filterPlains.add(SubType.PLAINS.getPredicate());
        TargetCardInLibrary target = new TargetCardInLibrary(0, landsToSearch, filterPlains);
        if (controller.searchLibrary(target, source, game, controller.getId())) {
            Cards cards = new CardsImpl(target.getTargets());
            controller.revealCards(sourceObject.getIdName(), cards, game);
            controller.moveCards(cards.getCards(game), Zone.HAND, source, game);
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandCard(mage.filter.common.FilterLandCard) MageObject(mage.MageObject) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

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