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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations