Search in sources :

Example 36 with CardsImpl

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

the class ExileFromHandCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    if (targets.choose(Outcome.Exile, controllerId, source.getSourceId(), game)) {
        Player player = game.getPlayer(controllerId);
        int cmc = 0;
        for (UUID targetId : targets.get(0).getTargets()) {
            Card card = player.getHand().get(targetId, game);
            if (card == null) {
                return false;
            }
            cmc += card.getManaValue();
            this.cards.add(card);
        }
        Cards cardsToExile = new CardsImpl();
        cardsToExile.addAll(cards);
        player.moveCards(cardsToExile, Zone.EXILED, ability, game);
        paid = true;
        if (setXFromCMC) {
            VariableManaCost vmc = new VariableManaCost(VariableCostType.ALTERNATIVE);
            // no x events - rules from Unbound Flourishing:
            // - Spells with additional costs that include X won't be affected by Unbound Flourishing. X must be in the spell's mana cost.
            // TODO: wtf, look at setXFromCMC usage -- it used in cards with alternative costs, not additional... need to fix?
            vmc.setAmount(cmc, cmc, false);
            vmc.setPaid();
            ability.getManaCostsToPay().add(vmc);
        }
    }
    return paid;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card) VariableManaCost(mage.abilities.costs.mana.VariableManaCost)

Example 37 with CardsImpl

use of mage.cards.CardsImpl 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 38 with CardsImpl

use of mage.cards.CardsImpl 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 39 with CardsImpl

use of mage.cards.CardsImpl 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 40 with CardsImpl

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

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