Search in sources :

Example 41 with CardsImpl

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

the class ReturnToBattlefieldUnderOwnerControlTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cardsToBattlefield = new CardsImpl();
        if (returnFromExileZoneOnly) {
            for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
                if (game.getExile().containsId(targetId, game)) {
                    cardsToBattlefield.add(targetId);
                } else {
                    Card card = game.getCard(targetId);
                    if (card instanceof MeldCard) {
                        MeldCard meldCard = (MeldCard) card;
                        Card topCard = meldCard.getTopHalfCard();
                        Card bottomCard = meldCard.getBottomHalfCard();
                        if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter() && game.getExile().containsId(topCard.getId(), game)) {
                            cardsToBattlefield.add(topCard);
                        }
                        if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter() && game.getExile().containsId(bottomCard.getId(), game)) {
                            cardsToBattlefield.add(bottomCard);
                        }
                    }
                }
            }
        } else {
            cardsToBattlefield.addAll(getTargetPointer().getTargets(game, source));
        }
        if (!cardsToBattlefield.isEmpty()) {
            controller.moveCards(cardsToBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, tapped, false, true, null);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) MeldCard(mage.cards.MeldCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) MeldCard(mage.cards.MeldCard) Card(mage.cards.Card)

Example 42 with CardsImpl

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

the class PutOnLibraryTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Card> cards = new ArrayList<>();
        List<Permanent> permanents = new ArrayList<>();
        for (UUID targetId : targetPointer.getTargets(game, source)) {
            switch(game.getState().getZone(targetId)) {
                case BATTLEFIELD:
                    Permanent permanent = game.getPermanent(targetId);
                    if (permanent != null) {
                        permanents.add(permanent);
                    }
                    break;
                case GRAVEYARD:
                    Card graveyardCard = game.getCard(targetId);
                    if (graveyardCard != null) {
                        cards.add(graveyardCard);
                    }
                    break;
                case STACK:
                    Card stackSpellCard = game.getSpell(targetId).getCard();
                    if (stackSpellCard != null) {
                        cards.add(stackSpellCard);
                    }
                    break;
            }
        }
        // 10/4/2004 	The owner decides the order the two lands are stacked there.
        while (!cards.isEmpty()) {
            Card card = cards.iterator().next();
            if (card != null) {
                Player owner = game.getPlayer(card.getOwnerId());
                Cards cardsPlayer = new CardsImpl();
                for (Iterator<Card> iterator = cards.iterator(); iterator.hasNext(); ) {
                    Card next = iterator.next();
                    if (next.isOwnedBy(owner.getId())) {
                        cardsPlayer.add(next);
                        iterator.remove();
                    }
                }
                if (onTop) {
                    owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
                } else {
                    owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true);
                }
            }
        }
        while (!permanents.isEmpty()) {
            Permanent permanent = permanents.iterator().next();
            if (permanent != null) {
                Player owner = game.getPlayer(permanent.getOwnerId());
                Cards cardsPlayer = new CardsImpl();
                for (Iterator<Permanent> iterator = permanents.iterator(); iterator.hasNext(); ) {
                    Permanent next = iterator.next();
                    if (next.isOwnedBy(owner.getId())) {
                        cardsPlayer.add(next);
                        iterator.remove();
                    }
                }
                if (onTop) {
                    owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
                } else {
                    owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 43 with CardsImpl

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

the class LookLibraryControllerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    // take cards from library and look at them
    boolean topCardRevealed = controller.isTopCardRevealed();
    controller.setTopCardRevealed(false);
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, this.numberOfCards.calculate(game, source, this)));
    controller.lookAtCards(source, null, cards, game);
    this.actionWithSelectedCards(cards, game, source);
    this.putCardsBack(source, controller, cards, game);
    controller.setTopCardRevealed(topCardRevealed);
    this.mayShuffle(controller, source, game);
    return true;
}
Also used : Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 44 with CardsImpl

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

the class HideawayLookAtFaceDownCardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    // LKI is required for this ruling
    /*
        If Watcher for Tomorrow leaves the battlefield before its 
        triggered ability from hideaway resolves, its leaves-the-battlefield 
        ability resolves and does nothing. Then its enters-the-battlefield 
        ability resolves and you exile a card with no way to return it to your hand.
        */
    Permanent hideawaySource = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (hideawaySource == null || controller == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    cards.addAll(controller.getLibrary().getTopCards(game, 4));
    if (!cards.isEmpty()) {
        TargetCard target1 = new TargetCard(Zone.LIBRARY, filter1);
        target1.setNotTarget(true);
        if (controller.choose(Outcome.Detriment, cards, target1, game)) {
            Card card = cards.get(target1.getFirstTarget(), game);
            if (card != null) {
                cards.remove(card);
                UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
                controller.moveCardToExileWithInfo(card, exileId, "Hideaway (" + hideawaySource.getIdName() + ')', source, game, Zone.LIBRARY, false);
                card.setFaceDown(true, game);
            }
        }
        controller.putCardsOnBottomOfLibrary(cards, game, source, true);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 45 with CardsImpl

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

the class AlrundGodOfTheCosmosEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    String chosenCardType = (String) game.getState().getValue(source.getSourceId() + "_type");
    Cards cardsToHand = new CardsImpl();
    Cards cardsToBottomOfLibrary = new CardsImpl();
    if (controller != null) {
        Set<Card> twoCardsFromTop = controller.getLibrary().getTopCards(game, 2);
        Cards cards = new CardsImpl();
        cards.addAll(twoCardsFromTop);
        controller.revealCards(source, cards, game);
        for (Card card : cards.getCards(game)) {
            if (card.getCardType(game).toString().contains(chosenCardType)) {
                cardsToHand.add(card);
            } else {
                cardsToBottomOfLibrary.add(card);
            }
        }
        controller.moveCards(cardsToHand, Zone.HAND, source, game);
        controller.putCardsOnBottomOfLibrary(cardsToBottomOfLibrary, game, source, true);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard)

Aggregations

CardsImpl (mage.cards.CardsImpl)507 Player (mage.players.Player)497 Cards (mage.cards.Cards)328 Card (mage.cards.Card)253 UUID (java.util.UUID)135 Permanent (mage.game.permanent.Permanent)114 FilterCard (mage.filter.FilterCard)108 MageObject (mage.MageObject)106 TargetCard (mage.target.TargetCard)99 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)53 TargetPlayer (mage.target.TargetPlayer)47 TargetCardInHand (mage.target.common.TargetCardInHand)41 OneShotEffect (mage.abilities.effects.OneShotEffect)37 Target (mage.target.Target)32 Ability (mage.abilities.Ability)27 FilterPermanent (mage.filter.FilterPermanent)27 CardSetInfo (mage.cards.CardSetInfo)25 Game (mage.game.Game)25 CardImpl (mage.cards.CardImpl)24 FilterCreatureCard (mage.filter.common.FilterCreatureCard)23