Search in sources :

Example 81 with Cards

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

the class SpinningDarknessCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Player controller = game.getPlayer(controllerId);
    if (controller != null) {
        Set<Card> blackCardsInGraveyard = controller.getGraveyard().getCards(filter, game);
        int size = blackCardsInGraveyard.size();
        if (size >= 3) {
            Iterator<Card> it = blackCardsInGraveyard.iterator();
            Cards cardsToExile = new CardsImpl();
            int i = 1;
            while (cardsToExile.size() < 3) {
                Card card = it.next();
                if (i > size - 3) {
                    cardsToExile.add(card);
                }
                i++;
            }
            paid = controller.moveCards(cardsToExile, Zone.EXILED, ability, game);
        }
    }
    return paid;
}
Also used : Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 82 with Cards

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

the class StormOfSoulsChangeCreatureEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game));
    if (cards.isEmpty()) {
        return false;
    }
    player.moveCards(cards, Zone.BATTLEFIELD, source, game);
    // Figure out which cards were successfuly moved so that they can be turned into 1/1 Spirits
    cards.retainZone(Zone.BATTLEFIELD, game);
    // Change the creatures
    game.addEffect(new StormOfSoulsChangeCreatureEffect().setTargetPointer(new FixedTargets(cards, game)), source);
    return true;
}
Also used : Player(mage.players.Player) FixedTargets(mage.target.targetpointer.FixedTargets) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 83 with Cards

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

the class VoidMawCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Player controller = game.getPlayer(controllerId);
    if (controller != null) {
        TargetCardInExile target = new TargetCardInExile(new FilterCard(), CardUtil.getCardExileZoneId(game, ability));
        target.setNotTarget(true);
        Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, ability));
        if (cards != null && !cards.isEmpty() && controller.choose(Outcome.Benefit, cards, target, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                if (controller.moveCardToGraveyardWithInfo(card, source, game, Zone.EXILED)) {
                    paid = true;
                }
            }
        }
    }
    return paid;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile) Cards(mage.cards.Cards) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 84 with Cards

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

the class ExploreSourceEffect method explorePermanent.

public static boolean explorePermanent(Game game, UUID permanentId, Ability source) {
    Boolean cardWasRevealed = false;
    Permanent permanent = game.getPermanentOrLKIBattlefield(permanentId);
    if (permanent == null) {
        return false;
    }
    Player permanentController = game.getPlayer(source.getControllerId());
    if (permanentController == null) {
        return false;
    }
    game.fireEvent(GameEvent.getEvent(GameEvent.EventType.EXPLORED, permanentId, source, permanent.getControllerId()));
    if (permanentController.getLibrary().hasCards()) {
        Card card = permanentController.getLibrary().getFromTop(game);
        Cards cards = new CardsImpl();
        cards.add(card);
        permanentController.revealCards("Explored card", cards, game);
        cardWasRevealed = true;
        if (card != null) {
            if (card.isLand(game)) {
                permanentController.moveCards(card, Zone.HAND, source, game);
            } else {
                if (game.getState().getZone(permanentId) == Zone.BATTLEFIELD) {
                    // needed in case LKI object is used
                    permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
                }
                if (permanentController.chooseUse(Outcome.Neutral, "Put " + card.getLogName() + " in your graveyard?", source, game)) {
                    permanentController.moveCards(card, Zone.GRAVEYARD, source, game);
                } else {
                    game.informPlayers(permanentController.getLogName() + " leaves " + card.getLogName() + " on top of their library.");
                }
            }
        }
    }
    if (!cardWasRevealed && game.getState().getZone(permanentId) == Zone.BATTLEFIELD) {
        // If no card is revealed, most likely because that player's library is empty,
        // the exploring creature receives a +1/+1 counter.
        permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 85 with Cards

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

the class FatesealEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetOpponent(true);
        if (controller.choose(outcome, target, source.getSourceId(), game)) {
            Player opponent = game.getPlayer(target.getFirstTarget());
            if (opponent == null) {
                return false;
            }
            // by looking at the cards with fateseal you have not to reveal the next card
            boolean revealed = opponent.isTopCardRevealed();
            opponent.setTopCardRevealed(false);
            Cards cards = new CardsImpl();
            int count = Math.min(fatesealNumber, opponent.getLibrary().size());
            if (count == 0) {
                return true;
            }
            for (int i = 0; i < count; i++) {
                Card card = opponent.getLibrary().removeFromTop(game);
                cards.add(card);
            }
            TargetCard target1 = new TargetCard(Zone.LIBRARY, filter1);
            target1.setRequired(false);
            // move cards to the bottom of the library
            while (!cards.isEmpty() && controller.choose(Outcome.Detriment, cards, target1, game)) {
                if (!controller.canRespond() || !opponent.canRespond()) {
                    return false;
                }
                Card card = cards.get(target1.getFirstTarget(), game);
                if (card != null) {
                    cards.remove(card);
                    controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, false, false);
                }
                target1.clearChosen();
            }
            // move cards to the top of the library
            controller.putCardsOnTopOfLibrary(cards, game, source, true);
            game.fireEvent(new GameEvent(GameEvent.EventType.FATESEALED, opponent.getId(), source, source.getControllerId()));
            controller.setTopCardRevealed(revealed);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) GameEvent(mage.game.events.GameEvent) 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