Added workaround to random booster drafr booster generation to prevent endless loops (#1136).

This commit is contained in:
LevelX2 2015-07-23 00:23:00 +02:00
parent bc36734c69
commit 0e0678f9d1

View file

@ -120,8 +120,13 @@ public abstract class ExpansionSet implements Serializable {
List<Card> theBooster = this.createBooster();
List<CardInfo> 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<Card> booster, List<CardInfo> 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<Card> createBooster() {
List<Card> booster = new ArrayList<>();
if (!hasBoosters) {
@ -257,18 +274,6 @@ public abstract class ExpansionSet implements Serializable {
}
}
protected void addToBooster(List<Card> booster, List<CardInfo> 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;
}