Search in sources :

Example 1 with DiscardCardCost

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

the class ImpulsiveWagerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        DiscardCardCost cost = (DiscardCardCost) source.getCosts().get(0);
        if (cost != null) {
            List<Card> cards = cost.getCards();
            if (cards.size() == 1 && cards.get(0).isLand(game)) {
                Effect effect = new AddCountersTargetEffect(CounterType.BOUNTY.createInstance());
                effect.setTargetPointer(getTargetPointer());
                effect.apply(game, source);
            } else {
                player.drawCards(2, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Player(mage.players.Player) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) Card(mage.cards.Card)

Example 2 with DiscardCardCost

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

the class WolfOfDevilsBreachDiscardCostCardConvertedManaCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    for (Effect sourceEffect : sourceAbility.getEffects()) {
        if (sourceEffect instanceof DoIfCostPaid) {
            Cost doCosts = ((DoIfCostPaid) sourceEffect).getCost();
            if (doCosts instanceof Costs) {
                Costs costs = (Costs) doCosts;
                for (Object cost : costs) {
                    if (cost instanceof DiscardCardCost) {
                        DiscardCardCost discardCost = (DiscardCardCost) cost;
                        int cmc = 0;
                        for (Card card : discardCost.getCards()) {
                            cmc += card.getManaValue();
                        }
                        return cmc;
                    }
                }
            }
        }
    }
    return 0;
}
Also used : DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Costs(mage.abilities.costs.Costs) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card)

Example 3 with DiscardCardCost

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

the class DralnusPetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
        permanent = game.getPermanentEntering(source.getSourceId());
    }
    if (controller != null && permanent != null) {
        SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
        if (spellAbility != null && spellAbility.getSourceId().equals(source.getSourceId()) && permanent.getZoneChangeCounter(game) == spellAbility.getSourceObjectZoneChangeCounter()) {
            int cmc = 0;
            for (Cost cost : spellAbility.getCosts()) {
                if (cost instanceof DiscardCardCost && !((DiscardCardCost) cost).getCards().isEmpty()) {
                    cmc = ((DiscardCardCost) cost).getCards().get(0).getManaValue();
                }
                if (cmc > 0) {
                    return new AddCountersSourceEffect(CounterType.P1P1.createInstance(cmc), true).apply(game, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) SpellAbility(mage.abilities.SpellAbility) DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Cost(mage.abilities.costs.Cost)

Example 4 with DiscardCardCost

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

the class ChainOfPlasmaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID targetId = source.getFirstTarget();
        Player affectedPlayer = null;
        Player player = game.getPlayer(targetId);
        if (player != null) {
            player.damage(3, source.getSourceId(), source, game);
            affectedPlayer = player;
        } else {
            Permanent permanent = game.getPermanent(targetId);
            if (permanent != null) {
                permanent.damage(3, source.getSourceId(), source, game, false, true);
                affectedPlayer = game.getPlayer(permanent.getControllerId());
            }
        }
        if (affectedPlayer != null) {
            if (affectedPlayer.chooseUse(Outcome.Copy, "Discard a card to copy the spell?", source, game)) {
                Cost cost = new DiscardCardCost();
                if (cost.pay(source, game, source, affectedPlayer.getId(), false, null)) {
                    Spell spell = game.getStack().getSpell(source.getSourceId());
                    if (spell != null) {
                        spell.createCopyOnStack(game, source, affectedPlayer.getId(), true);
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Cost(mage.abilities.costs.Cost) Spell(mage.game.stack.Spell)

Example 5 with DiscardCardCost

use of mage.abilities.costs.common.DiscardCardCost 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

DiscardCardCost (mage.abilities.costs.common.DiscardCardCost)8 Player (mage.players.Player)7 Cost (mage.abilities.costs.Cost)5 Effect (mage.abilities.effects.Effect)3 Card (mage.cards.Card)3 Permanent (mage.game.permanent.Permanent)3 UUID (java.util.UUID)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)2 SpellAbility (mage.abilities.SpellAbility)1 Costs (mage.abilities.costs.Costs)1 CostsImpl (mage.abilities.costs.CostsImpl)1 PayLifeCost (mage.abilities.costs.common.PayLifeCost)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)1 DoIfCostPaid (mage.abilities.effects.common.DoIfCostPaid)1 InfoEffect (mage.abilities.effects.common.InfoEffect)1 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)1 AddCountersTargetEffect (mage.abilities.effects.common.counter.AddCountersTargetEffect)1 Spell (mage.game.stack.Spell)1