Search in sources :

Example 6 with DiscardTargetCost

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

the class MoxDiamondReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        TargetCardInHand target = new TargetCardInHand(new FilterLandCard());
        Cost cost = new DiscardTargetCost(target);
        if (cost.canPay(source, source, source.getControllerId(), game) && player.chooseUse(outcome, "Discard land? (Otherwise Mox Diamond goes to graveyard)", source, game) && player.chooseTarget(Outcome.Discard, target, source, game)) {
            player.discard(game.getCard(target.getFirstTarget()), false, source, game);
            return false;
        } else {
            Permanent permanent = game.getPermanentEntering(event.getTargetId());
            if (permanent != null) {
                player.moveCards(permanent, Zone.GRAVEYARD, source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) FilterLandCard(mage.filter.common.FilterLandCard) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) Cost(mage.abilities.costs.Cost)

Example 7 with DiscardTargetCost

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

the class OathOfLimDulEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean sacrificeDone = false;
    int numberSacrificed = 0;
    int numberToDiscard = 0;
    int numberOfControlledPermanents = 0;
    Player controller = game.getPlayer(source.getControllerId());
    int amountDamage = (int) game.getState().getValue(source.getSourceId().toString() + "oathOfLimDul");
    if (amountDamage > 0 && controller != null) {
        TargetControlledPermanent target = new TargetControlledPermanent(0, numberOfControlledPermanents, filter, true);
        target.setNotTarget(true);
        if (controller.choose(Outcome.Detriment, target, source.getSourceId(), game)) {
            for (UUID targetPermanentId : target.getTargets()) {
                Permanent permanent = game.getPermanent(targetPermanentId);
                if (permanent != null && permanent.sacrifice(source, game)) {
                    numberSacrificed += 1;
                    sacrificeDone = true;
                }
            }
        }
        numberToDiscard = amountDamage - numberSacrificed;
        Cost cost = new DiscardTargetCost(new TargetCardInHand(numberToDiscard, new FilterCard("card(s) in your hand to discard")));
        if (numberToDiscard > 0 && cost.canPay(source, source, controller.getId(), game)) {
            // discard cost paid simultaneously
            return cost.pay(source, game, source, controller.getId(), true);
        }
    }
    return sacrificeDone;
}
Also used : FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) UUID(java.util.UUID) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) Cost(mage.abilities.costs.Cost)

Example 8 with DiscardTargetCost

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

the class CounterSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null) {
        DiscardTargetCost cost = new DiscardTargetCost(new TargetCardInHand(3, 3, new FilterCard()));
        for (UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
            Player player = game.getPlayer(playerId);
            cost.clearPaid();
            if (player != null && cost.canPay(source, source, player.getId(), game) && player.chooseUse(outcome, "Discard three cards to counter " + sourceObject.getIdName() + '?', source, game)) {
                if (cost.pay(source, game, source, playerId, false, null)) {
                    game.informPlayers(player.getLogName() + " discards 3 cards to counter " + sourceObject.getIdName() + '.');
                    Spell spell = game.getStack().getSpell(source.getSourceId());
                    if (spell != null) {
                        game.getStack().counter(spell.getId(), source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) MageObject(mage.MageObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Aggregations

DiscardTargetCost (mage.abilities.costs.common.DiscardTargetCost)8 Cost (mage.abilities.costs.Cost)6 Player (mage.players.Player)6 TargetCardInHand (mage.target.common.TargetCardInHand)6 FilterCard (mage.filter.FilterCard)5 SearchLibraryPutInHandEffect (mage.abilities.effects.common.search.SearchLibraryPutInHandEffect)3 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)3 UUID (java.util.UUID)2 MageObject (mage.MageObject)2 Permanent (mage.game.permanent.Permanent)2 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)1 DestroyTargetEffect (mage.abilities.effects.common.DestroyTargetEffect)1 DoWhenCostPaid (mage.abilities.effects.common.DoWhenCostPaid)1 Card (mage.cards.Card)1 FilterPermanent (mage.filter.FilterPermanent)1 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)1 FilterCreatureOrPlaneswalkerPermanent (mage.filter.common.FilterCreatureOrPlaneswalkerPermanent)1 FilterLandCard (mage.filter.common.FilterLandCard)1