Search in sources :

Example 71 with Cost

use of mage.abilities.costs.Cost 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 72 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class IndulgentTormentorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (opponent != null) {
        Cost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT));
        if (cost.canPay(source, source, opponent.getId(), game) && opponent.chooseUse(outcome, "Sacrifice a creature to prevent the card draw?", source, game)) {
            if (cost.pay(source, game, source, opponent.getId(), false, null)) {
                return true;
            }
        }
        cost = new PayLifeCost(3);
        if (cost.canPay(source, source, opponent.getId(), game) && opponent.chooseUse(outcome, "Pay 3 life to prevent the card draw?", source, game)) {
            if (cost.pay(source, game, source, opponent.getId(), false, null)) {
                return true;
            }
        }
        game.getPlayer(source.getControllerId()).drawCards(1, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 73 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class LegacyOfTheBelovedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card sourceCard = game.getCard(source.getSourceId());
    if (sourceCard != null) {
        for (Cost cost : source.getCosts()) {
            if (cost instanceof SacrificeTargetCost) {
                Permanent p = (Permanent) game.getLastKnownInformation(((SacrificeTargetCost) cost).getPermanents().get(0).getId(), Zone.BATTLEFIELD);
                if (p != null) {
                    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, p.getManaValue()));
                    TargetCardInLibrary target = new TargetCardInLibrary(0, 2, filter);
                    Player player = game.getPlayer(source.getControllerId());
                    if (player != null && player.searchLibrary(target, source, game)) {
                        player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, false, false, false, null);
                        player.shuffleLibrary(source, game);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 74 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class PowerSinkCounterUnlessPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        Player controller = game.getPlayer(source.getControllerId());
        MageObject sourceObject = game.getObject(source.getSourceId());
        if (player != null && controller != null && sourceObject != null) {
            int amount = source.getManaCostsToPay().getX();
            if (amount > 0) {
                Cost cost = ManaUtil.createManaCost(amount, true);
                if (player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + " to prevent?", source, game)) {
                    if (cost.pay(source, game, source, player.getId(), false)) {
                        game.informPlayers(sourceObject.getName() + ": additional cost was paid");
                        return true;
                    }
                }
                game.informPlayers(sourceObject.getName() + ": additional cost wasn't paid - countering " + spell.getName());
                // Counter target spell unless its controller pays {X}
                game.getStack().counter(source.getFirstTarget(), source, game);
                // that player taps all lands with mana abilities they control...
                List<Permanent> lands = game.getBattlefield().getAllActivePermanents(new FilterLandPermanent(), player.getId(), game);
                for (Permanent land : lands) {
                    Abilities<Ability> landAbilities = land.getAbilities();
                    for (Ability ability : landAbilities) {
                        if (ability instanceof ActivatedManaAbilityImpl) {
                            land.tap(source, game);
                            break;
                        }
                    }
                }
                // ...and empties their mana pool
                player.getManaPool().emptyPool(game);
            }
            return true;
        }
    }
    return false;
}
Also used : Ability(mage.abilities.Ability) Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) Cost(mage.abilities.costs.Cost)

Example 75 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class PossessedPortalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        Cost discardCost = new DiscardCardCost();
        if (player != null && discardCost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Discard, "Discard a card? (Otherwise sacrifice a permanent)", source, game)) {
            discardCost.pay(source, game, source, playerId, true, null);
        } else {
            Cost sacrificeCost = new SacrificeTargetCost(new TargetControlledPermanent());
            sacrificeCost.pay(source, game, source, playerId, true, null);
        }
    }
    return true;
}
Also used : DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) UUID(java.util.UUID) DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Aggregations

Cost (mage.abilities.costs.Cost)174 Player (mage.players.Player)142 Permanent (mage.game.permanent.Permanent)86 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)41 Card (mage.cards.Card)32 UUID (java.util.UUID)30 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)29 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)26 TapSourceCost (mage.abilities.costs.common.TapSourceCost)23 FilterCard (mage.filter.FilterCard)22 MageObject (mage.MageObject)19 PayLifeCost (mage.abilities.costs.common.PayLifeCost)17 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)16 FixedTarget (mage.target.targetpointer.FixedTarget)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)14 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)13 ContinuousEffect (mage.abilities.effects.ContinuousEffect)12 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)11 OneShotEffect (mage.abilities.effects.OneShotEffect)9