From 84d23538196a362154a50dc96218b5e5b3365955 Mon Sep 17 00:00:00 2001 From: Simown Date: Sun, 26 Jul 2015 12:45:14 +0100 Subject: [PATCH] Fix for Random booster draft iterates endless while booster generation (#1136) --- Mage.Sets/src/mage/sets/DragonsMaze.java | 3 ++- Mage.Sets/src/mage/sets/FateReforged.java | 5 ++--- Mage/src/mage/cards/ExpansionSet.java | 14 ++++---------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Mage.Sets/src/mage/sets/DragonsMaze.java b/Mage.Sets/src/mage/sets/DragonsMaze.java index 45c316b308e..1fe91979797 100644 --- a/Mage.Sets/src/mage/sets/DragonsMaze.java +++ b/Mage.Sets/src/mage/sets/DragonsMaze.java @@ -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); } diff --git a/Mage.Sets/src/mage/sets/FateReforged.java b/Mage.Sets/src/mage/sets/FateReforged.java index f1126deeb10..76d31b292a2 100644 --- a/Mage.Sets/src/mage/sets/FateReforged.java +++ b/Mage.Sets/src/mage/sets/FateReforged.java @@ -81,9 +81,8 @@ public class FateReforged extends ExpansionSet { savedCardsInfos = CardRepository.instance.findCards(criteria); savedCards.put(rarity, savedCardsInfos); } - List 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); } diff --git a/Mage/src/mage/cards/ExpansionSet.java b/Mage/src/mage/cards/ExpansionSet.java index 5c307480558..23c5649fbe3 100644 --- a/Mage/src/mage/cards/ExpansionSet.java +++ b/Mage/src/mage/cards/ExpansionSet.java @@ -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 theBooster = this.createBooster(); List 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 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 getSpecialCommon() {