Search in sources :

Example 21 with Cards

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

the class RevealSourceFromYourHandCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    paid = false;
    Player player = game.getPlayer(controllerId);
    if (player != null) {
        Card card = player.getHand().get(ability.getSourceId(), game);
        if (card != null) {
            Cards cards = new CardsImpl(card);
            paid = true;
            player.revealCards("Reveal card cost", cards, game);
        }
    }
    return paid;
}
Also used : Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 22 with Cards

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

the class DiscardTargetCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    this.cards.clear();
    this.targets.clearChosen();
    Player player = game.getPlayer(controllerId);
    if (player == null) {
        return false;
    }
    int amount = this.getTargets().get(0).getNumberOfTargets();
    if (randomDiscard) {
        this.cards.addAll(player.discard(amount, true, true, source, game).getCards(game));
    } else if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), game)) {
        Cards toDiscard = new CardsImpl();
        toDiscard.addAll(targets.get(0).getTargets());
        Cards discarded = player.discard(toDiscard, true, source, game);
        if (!discarded.isEmpty()) {
            cards.addAll(discarded.getCards(game));
        }
    }
    paid = cards.size() >= amount;
    return paid;
}
Also used : Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 23 with Cards

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

the class ExileFromGraveCost 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) {
        if (targets.choose(Outcome.Exile, controllerId, source.getSourceId(), game)) {
            for (UUID targetId : targets.get(0).getTargets()) {
                Card card = game.getCard(targetId);
                if (card == null || game.getState().getZone(targetId) != Zone.GRAVEYARD) {
                    return false;
                }
                exiledCards.add(card);
            }
            Cards cardsToExile = new CardsImpl();
            cardsToExile.addAll(exiledCards);
            controller.moveCardsToExile(cardsToExile.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
            if (setTargetPointer) {
                source.getEffects().setTargetPointer(new FixedTargets(cardsToExile, game));
            }
            paid = true;
        }
    }
    return paid;
}
Also used : Player(mage.players.Player) FixedTargets(mage.target.targetpointer.FixedTargets) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 24 with Cards

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

the class ReturnToBattlefieldUnderYourControlTargetEffect 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)) {
                UUID mainCardId = CardUtil.getMainCardId(game, targetId);
                if (game.getExile().containsId(mainCardId, game)) {
                    cardsToBattlefield.add(mainCardId);
                } 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));
        }
        for (Card card : cardsToBattlefield.getCards(game)) {
            if (controller.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, false, null)) {
                if (attacking) {
                    game.getCombat().addAttackingCreature(card.getId(), game);
                }
            }
        }
        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 25 with Cards

use of mage.cards.Cards 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)

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