Search in sources :

Example 86 with Cards

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

the class SearchLibraryPutOnLibraryEffect 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;
    }
    if (controller.searchLibrary(target, source, game)) {
        Cards foundCards = new CardsImpl(target.getTargets());
        if (reveal && !foundCards.isEmpty()) {
            controller.revealCards(sourceObject.getIdName(), foundCards, game);
        }
        if (forceShuffle) {
            controller.shuffleLibrary(source, game);
        }
        controller.putCardsOnTopOfLibrary(foundCards, game, source, reveal);
        return true;
    }
    // shuffle
    if (forceShuffle) {
        controller.shuffleLibrary(source, game);
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 87 with Cards

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

the class SearchLibraryPutInHandOrOnBattlefieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    target.clearChosen();
    if (controller.searchLibrary(target, source, game)) {
        if (!target.getTargets().isEmpty()) {
            Cards cards = new CardsImpl();
            boolean askToPutOntoBf = false;
            Card cardToPutOnBf = null;
            for (UUID cardId : target.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    if (card.getName().equals(nameToPutOnBattlefield)) {
                        askToPutOntoBf = true;
                        cardToPutOnBf = card;
                    }
                    cards.add(card);
                }
            }
            if (askToPutOntoBf && controller.chooseUse(Outcome.PutCardInPlay, "Put " + cardToPutOnBf.getLogName() + " onto the battlefield instead?", source, game)) {
                controller.moveCards(cards, Zone.BATTLEFIELD, source, game);
            } else {
                controller.moveCards(cards, Zone.HAND, source, game);
            }
            if (revealCards) {
                String name = "Reveal";
                Card sourceCard = game.getCard(source.getSourceId());
                if (sourceCard != null) {
                    name = sourceCard.getIdName();
                }
                controller.revealCards(name, cards, game);
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    if (forceShuffle) {
        controller.shuffleLibrary(source, game);
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 88 with Cards

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

the class DiscardEachPlayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    // Store for each player the cards to discard, that's important because all discard shall happen at the same time
    Map<UUID, Cards> cardsToDiscard = new HashMap<>();
    if (controller == null) {
        return true;
    }
    int toDiscard = amount.calculate(game, source, this);
    // choose cards to discard
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        switch(targetController) {
            case NOT_YOU:
                if (playerId.equals(source.getControllerId())) {
                    continue;
                }
                break;
            case OPPONENT:
                if (!game.getOpponents(source.getControllerId()).contains(playerId)) {
                    continue;
                }
                break;
        }
        if (randomDiscard) {
            player.discard(toDiscard, true, false, source, game);
            continue;
        }
        int numberOfCardsToDiscard = Math.min(toDiscard, player.getHand().size());
        Cards cards = new CardsImpl();
        if (numberOfCardsToDiscard > 0) {
            Target target = new TargetDiscard(numberOfCardsToDiscard, numberOfCardsToDiscard, StaticFilters.FILTER_CARD, playerId);
            player.chooseTarget(outcome, target, source, game);
            cards.addAll(target.getTargets());
        }
        cardsToDiscard.put(playerId, cards);
    }
    if (randomDiscard) {
        return true;
    }
    // discard all choosen cards
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        player.discard(cardsToDiscard.get(playerId), false, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 89 with Cards

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

the class AtrisOracleOfHalfTruthsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || targetOpponent == null || sourceObject == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
    TargetCard target = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, filter);
    targetOpponent.choose(outcome, cards, target, game);
    Cards faceDownPile = new CardsImpl(target.getTargets());
    cards.removeAll(target.getTargets());
    controller.revealCards(sourceObject.getIdName() + " - cards in face-up pile", cards, game);
    game.informPlayers(targetOpponent.getLogName() + " puts " + faceDownPile.size() + " card(s) into the face-down pile");
    if (controller.chooseUse(outcome, "Choose a pile to put in your hand.", null, "Face-down", "Face-up", source, game)) {
        controller.moveCards(faceDownPile, Zone.HAND, source, game);
        controller.moveCards(cards, Zone.GRAVEYARD, source, game);
    } else {
        controller.moveCards(faceDownPile, Zone.GRAVEYARD, source, game);
        controller.moveCards(cards, Zone.HAND, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 90 with Cards

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

the class AshnodsCylixEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 3));
    player.lookAtCards(source, null, cards, game);
    TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put on top of your library"));
    if (player.choose(Outcome.Benefit, cards, target, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        if (card != null) {
            cards.remove(card);
            game.informPlayers(source.getSourceObject(game).getIdName() + ": " + player.getLogName() + " puts a card back on top of their library");
        }
    }
    player.moveCards(cards, Zone.EXILED, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Aggregations

Cards (mage.cards.Cards)354 Player (mage.players.Player)342 CardsImpl (mage.cards.CardsImpl)328 Card (mage.cards.Card)157 UUID (java.util.UUID)104 FilterCard (mage.filter.FilterCard)86 TargetCard (mage.target.TargetCard)84 MageObject (mage.MageObject)73 Permanent (mage.game.permanent.Permanent)71 TargetPlayer (mage.target.TargetPlayer)35 OneShotEffect (mage.abilities.effects.OneShotEffect)27 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)27 Ability (mage.abilities.Ability)25 Target (mage.target.Target)24 TargetCardInHand (mage.target.common.TargetCardInHand)24 Game (mage.game.Game)23 CardSetInfo (mage.cards.CardSetInfo)22 CardImpl (mage.cards.CardImpl)21 CardType (mage.constants.CardType)21 FilterPermanent (mage.filter.FilterPermanent)19