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