* Fixed a bug that could lock the game if you should pick more cards from shown cards from your library than cards left in your library (e.g. Dig Through Time).
*/
package mage.abilities.effects.common;
+import static java.lang.Integer.min;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.dynamicvalue.DynamicValue;
@@ -186,7 +187,8 @@ public class LookLibraryAndPickControllerEffect extends LookLibraryControllerEff
if (!optional || player.chooseUse(Outcome.DrawCard, getMayText(), source, game)) {
FilterCard pickFilter = filter.copy();
pickFilter.setMessage(getPickText());
- TargetCard target = new TargetCard((upTo ? 0 : numberToPick.calculate(game, source, this)), numberToPick.calculate(game, source, this), Zone.LIBRARY, pickFilter);
+ int number = min(cards.size(), numberToPick.calculate(game, source, this));
+ TargetCard target = new TargetCard((upTo ? 0 : number), number, Zone.LIBRARY, pickFilter);
if (player.choose(Outcome.DrawCard, cards, target, game)) {
Cards pickedCards = new CardsImpl(target.getTargets());
cards.removeAll(pickedCards);
