mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 05:09:16 -08:00
Added workaround to random booster drafr booster generation to prevent endless loops (#1136).
This commit is contained in:
parent
bc36734c69
commit
0e0678f9d1
1 changed files with 18 additions and 13 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue