From 0e0678f9d1f35f270ea0b6a4be5859cb41661231 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 23 Jul 2015 00:23:00 +0200 Subject: [PATCH] Added workaround to random booster drafr booster generation to prevent endless loops (#1136). --- Mage/src/mage/cards/ExpansionSet.java | 31 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/Mage/src/mage/cards/ExpansionSet.java b/Mage/src/mage/cards/ExpansionSet.java index a7b968c724c..5c307480558 100644 --- a/Mage/src/mage/cards/ExpansionSet.java +++ b/Mage/src/mage/cards/ExpansionSet.java @@ -120,8 +120,13 @@ public abstract class ExpansionSet implements Serializable { List theBooster = this.createBooster(); List commons = getCardsByRarity(Rarity.COMMON); - while (15 > theBooster.size()) { + int iterations = 0; + while (15 > theBooster.size() && !commons.isEmpty()) { addToBooster(theBooster, commons); + iterations++; + if (iterations > 14) { + break; + } } while (theBooster.size() > 15) { @@ -131,6 +136,18 @@ public abstract class ExpansionSet implements Serializable { return theBooster; } + protected void addToBooster(List booster, List cards) { + if (!cards.isEmpty()) { + CardInfo cardInfo = cards.remove(rnd.nextInt(cards.size())); + if (cardInfo != null) { + Card card = cardInfo.getCard(); + if (card != null) { + booster.add(card); + } + } + } + } + public List createBooster() { List booster = new ArrayList<>(); if (!hasBoosters) { @@ -257,18 +274,6 @@ public abstract class ExpansionSet implements Serializable { } } - protected void addToBooster(List booster, List cards) { - if (!cards.isEmpty()) { - CardInfo cardInfo = cards.remove(rnd.nextInt(cards.size())); - if (cardInfo != null) { - Card card = cardInfo.getCard(); - if (card != null) { - booster.add(card); - } - } - } - } - public boolean hasBoosters() { return hasBoosters; }