mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
Fixed a bug in random deck generation where generating a deck from a set
with too few cards caused an exception. Minor formatting fixes.
This commit is contained in:
parent
db7784f39d
commit
1bdc54556a
1 changed files with 10 additions and 2 deletions
|
|
@ -385,6 +385,12 @@ public class DeckGeneratorPool
|
|||
if(spellSize < nonLandSize) {
|
||||
|
||||
int spellsNeeded = nonLandSize-spellSize;
|
||||
|
||||
// If we haven't got enough spells in reserve to fulfil the amount we need, we can't continue.
|
||||
if(reserveSpells.size() < spellsNeeded) {
|
||||
throw new IllegalStateException("Not enough cards found to generate deck. Please try again");
|
||||
}
|
||||
|
||||
List<Card> spellsToAdd = new ArrayList<>(spellsNeeded);
|
||||
|
||||
// Initial reservoir
|
||||
|
|
@ -401,7 +407,6 @@ public class DeckGeneratorPool
|
|||
// Add randomly selected spells needed
|
||||
deckCards.addAll(spellsToAdd);
|
||||
}
|
||||
|
||||
// More spells than needed
|
||||
else if(spellSize > (deckSize - landCount)) {
|
||||
|
||||
|
|
@ -410,8 +415,11 @@ public class DeckGeneratorPool
|
|||
deckCards.remove(random.nextInt(deckCards.size()));
|
||||
}
|
||||
}
|
||||
if(deckCards.size() != nonLandSize)
|
||||
|
||||
// Not strictly necessary as we check when adding cards, but worth double checking anyway.
|
||||
if(deckCards.size() != nonLandSize) {
|
||||
throw new IllegalStateException("Not enough cards found to generate deck. Please try again");
|
||||
}
|
||||
|
||||
// Return the fixed amount
|
||||
return deckCards;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue