@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Spell targetSpell = game.getStack().getSpell(source.getFirstTarget());
if (targetSpell != null) {
Player controllerOfTargetedSpell = game.getPlayer(targetSpell.getControllerId());
if (controller != null
&& controllerOfTargetedSpell != null) {
int numToDiscard = controller.getAmount(0, controller.getHand().size(), "How many cards do you want to discard?", game);
Cards discardedCards = controller.discard(numToDiscard, false, source, game);
int actualNumberDiscarded = discardedCards.size();
GenericManaCost cost = new GenericManaCost(actualNumberDiscarded * 3);
if (controllerOfTargetedSpell.chooseUse(Outcome.AIDontUseIt, "Do you want to pay " + cost.convertedManaCost() + " to prevent " + targetSpell.getName() + " from gettting countered?", source, game)
&& cost.pay(source, game, source.getSourceId(), controllerOfTargetedSpell.getId(), false)) {
return true;
} else {
targetSpell.counter(source.getSourceId(), game);
return true;
}
}
}
return false;
}
}