int amount = source.getManaCostsToPay().getX();
int discarded = Math.min(amount, player.getHand().size());
player.discard(amount, source, game);
// then return a card from your graveyard to your hand for each card discarded this way
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(discarded, new FilterCard());
target.choose(Outcome.ReturnToHand, player.getId(), source.getSourceId(), game);
for (UUID targetId : target.getTargets()) {
Card card = game.getCard(targetId);
if (card != null) {
player.moveCardToHandWithInfo(card, source.getSourceId(), game, Zone.GRAVEYARD);
}
}