Fix for Random booster draft iterates endless while booster generation (#1136)

This commit is contained in:
Simown 2015-07-26 12:45:14 +01:00
parent b029de3ec9
commit 84d2353819
3 changed files with 8 additions and 14 deletions

View file

@ -84,7 +84,8 @@ public class DragonsMaze extends ExpansionSet {
savedCardsInfos = CardRepository.instance.findCards(criteria);
savedCards.put(rarity, savedCardsInfos);
}
return savedCardsInfos;
// Return a copy of the saved cards information, as not to modify the original.
return new ArrayList<>(savedCardsInfos);
} else {
return super.getCardsByRarity(rarity);
}

View file

@ -81,9 +81,8 @@ public class FateReforged extends ExpansionSet {
savedCardsInfos = CardRepository.instance.findCards(criteria);
savedCards.put(rarity, savedCardsInfos);
}
List<CardInfo> cards = new ArrayList<>();
cards.addAll(savedCardsInfos);
return cards;
// Return a copy of the saved cards information, as not to modify the original.
return new ArrayList<>(savedCardsInfos);
} else {
return super.getCardsByRarity(rarity);
}

View file

@ -117,16 +117,11 @@ public abstract class ExpansionSet implements Serializable {
// if the packs are too big, it removes the first cards.
// since it adds lands then commons before uncommons
// and rares this should be the least disruptive.
List<Card> theBooster = this.createBooster();
List<CardInfo> commons = getCardsByRarity(Rarity.COMMON);
int iterations = 0;
while (15 > theBooster.size() && !commons.isEmpty()) {
while (15 > theBooster.size()) {
addToBooster(theBooster, commons);
iterations++;
if (iterations > 14) {
break;
}
}
while (theBooster.size() > 15) {
@ -301,9 +296,8 @@ public abstract class ExpansionSet implements Serializable {
savedCardsInfos = CardRepository.instance.findCards(criteria);
savedCards.put(rarity, savedCardsInfos);
}
List<CardInfo> cards = new ArrayList<>();
cards.addAll(savedCardsInfos);
return cards;
// Return a copy of the saved cards information, as not to modify the original.
return new ArrayList<>(savedCardsInfos);
}
public List<CardInfo> getSpecialCommon() {