Search in sources :

Example 1 with ExileFromHandCost

use of mage.abilities.costs.common.ExileFromHandCost in project mage by magefree.

the class HolisticWisdomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getFirstTarget());
    if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
        for (Cost cost : source.getCosts()) {
            if (cost instanceof ExileFromHandCost) {
                List<CardType> cardtypes = new ArrayList<>();
                ExileFromHandCost exileCost = (ExileFromHandCost) cost;
                for (CardType cardtype : exileCost.getCards().get(0).getCardType(game)) {
                    cardtypes.add(cardtype);
                }
                for (CardType cardtype : card.getCardType(game)) {
                    if (cardtypes.contains(cardtype)) {
                        Effect effect = new ReturnToHandTargetEffect();
                        effect.setTargetPointer(new FixedTarget(card.getId(), game));
                        return effect.apply(game, source);
                    }
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) CardType(mage.constants.CardType) ArrayList(java.util.ArrayList) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) Cost(mage.abilities.costs.Cost) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 2 with ExileFromHandCost

use of mage.abilities.costs.common.ExileFromHandCost in project mage by magefree.

the class JhoiraOfTheGhituSuspendEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<Card> cards = new ArrayList<>();
    for (Cost cost : source.getCosts()) {
        if (cost instanceof ExileFromHandCost) {
            cards = ((ExileFromHandCost) cost).getCards();
        }
    }
    if (cards != null && !cards.isEmpty()) {
        // always one card to exile
        Card card = game.getCard(cards.get(0).getId());
        if (card == null) {
            return false;
        }
        card = card.getMainCard();
        boolean hasSuspend = card.getAbilities(game).containsClass(SuspendAbility.class);
        UUID exileId = SuspendAbility.getSuspendExileId(controller.getId(), game);
        if (controller.moveCardToExileWithInfo(card, exileId, "Suspended cards of " + controller.getName(), source, game, Zone.HAND, true)) {
            card.addCounters(CounterType.TIME.createInstance(4), source.getControllerId(), source, game);
            if (!hasSuspend) {
                game.addEffect(new GainSuspendEffect(new MageObjectReference(card, game)), source);
            }
            game.informPlayers(controller.getLogName() + " suspends 4 - " + card.getName());
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) ArrayList(java.util.ArrayList) UUID(java.util.UUID) GainSuspendEffect(mage.abilities.effects.common.continuous.GainSuspendEffect) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) Cost(mage.abilities.costs.Cost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) MageObjectReference(mage.MageObjectReference) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 3 with ExileFromHandCost

use of mage.abilities.costs.common.ExileFromHandCost in project mage by magefree.

the class ExileCardsFromHandAdjuster method adjustCosts.

@Override
public void adjustCosts(Ability ability, Game game) {
    if (game.inCheckPlayableState()) {
        return;
    }
    Player player = game.getPlayer(ability.getControllerId());
    if (player == null) {
        return;
    }
    int cardCount = player.getHand().count(filter, game);
    int toExile = cardCount > 0 ? player.getAmount(0, cardCount, "Choose how many " + filter.getMessage() + " to exile", game) : 0;
    if (toExile > 0) {
        ability.addCost(new ExileFromHandCost(new TargetCardInHand(toExile, filter)));
        CardUtil.reduceCost(ability, 2 * toExile);
    }
}
Also used : Player(mage.players.Player) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) TargetCardInHand(mage.target.common.TargetCardInHand)

Example 4 with ExileFromHandCost

use of mage.abilities.costs.common.ExileFromHandCost in project mage by magefree.

the class GemstoneCavernsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean result = false;
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = game.getCard(source.getSourceId());
        if (card != null) {
            ContinuousEffect effect = new EntersBattlefieldEffect(new AddCountersSourceEffect(CounterType.LUCK.createInstance()), "");
            effect.setDuration(Duration.OneUse);
            game.addEffect(effect, source);
            if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                Permanent permanent = game.getPermanent(card.getId());
                if (permanent != null) {
                    Cost cost = new ExileFromHandCost(new TargetCardInHand());
                    if (cost.canPay(source, source, source.getControllerId(), game)) {
                        result = cost.pay(source, game, source, source.getControllerId(), true, null);
                    }
                }
            }
        }
    }
    return result;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) EntersBattlefieldEffect(mage.abilities.effects.EntersBattlefieldEffect) Card(mage.cards.Card)

Aggregations

ExileFromHandCost (mage.abilities.costs.common.ExileFromHandCost)4 Cost (mage.abilities.costs.Cost)3 Card (mage.cards.Card)3 Player (mage.players.Player)3 ArrayList (java.util.ArrayList)2 TargetCardInHand (mage.target.common.TargetCardInHand)2 UUID (java.util.UUID)1 MageObjectReference (mage.MageObjectReference)1 TapSourceCost (mage.abilities.costs.common.TapSourceCost)1 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 Effect (mage.abilities.effects.Effect)1 EntersBattlefieldEffect (mage.abilities.effects.EntersBattlefieldEffect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 ReturnToHandTargetEffect (mage.abilities.effects.common.ReturnToHandTargetEffect)1 GainSuspendEffect (mage.abilities.effects.common.continuous.GainSuspendEffect)1 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)1 CardType (mage.constants.CardType)1 FilterCard (mage.filter.FilterCard)1 FilterNonlandCard (mage.filter.common.FilterNonlandCard)1