mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Issue 77: Avoid NPE when choosing cards at random for quests.
This commit is contained in:
@@ -80,12 +80,9 @@ public class QuestBoosterPack implements NewConstants {
|
|||||||
if (standardPool) {
|
if (standardPool) {
|
||||||
// filter Cards for cards appearing in Standard Sets
|
// filter Cards for cards appearing in Standard Sets
|
||||||
ArrayList<String> sets = new ArrayList<String>();
|
ArrayList<String> sets = new ArrayList<String>();
|
||||||
|
|
||||||
//TODO: It would be handy if the list of any sets can be chosen
|
//TODO: It would be handy if the list of any sets can be chosen
|
||||||
// ... Huh?
|
// Can someone clarify that? I don't understand it. -Braids
|
||||||
// TODO: Braids: "It would also be handy if comments were written
|
|
||||||
// in clear English."
|
|
||||||
|
|
||||||
sets.add("M12");
|
sets.add("M12");
|
||||||
sets.add("NPH");
|
sets.add("NPH");
|
||||||
sets.add("MBS");
|
sets.add("MBS");
|
||||||
@@ -96,23 +93,8 @@ public class QuestBoosterPack implements NewConstants {
|
|||||||
sets.add("ZEN");
|
sets.add("ZEN");
|
||||||
|
|
||||||
allCards = CardFilter.getSets(allCards, sets);
|
allCards = CardFilter.getSets(allCards, sets);
|
||||||
|
|
||||||
/*
|
|
||||||
* Here we force the generator to evaluate (solidify) into a
|
|
||||||
* temporary ArrayList. This list only contains cards from 7 sets,
|
|
||||||
* so it doesn't have nearly as much heap impact as an array of all
|
|
||||||
* cards. Plus, we need to scan this array 3 times in the code
|
|
||||||
* below. Braids thinks it's better to have the temporary list than
|
|
||||||
* to force evaluation of the original generator three times,
|
|
||||||
* because the original generator examines every card in the
|
|
||||||
* database.
|
|
||||||
*/
|
|
||||||
allCards = GeneratorFunctions.solidify(allCards);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't bother solidifying here, because allCards could be
|
|
||||||
// equal to the set of ALL cards.
|
|
||||||
|
|
||||||
names.addAll(generateCards(allCards, numCommon, Constant.Rarity.Common, null, started));
|
names.addAll(generateCards(allCards, numCommon, Constant.Rarity.Common, null, started));
|
||||||
names.addAll(generateCards(allCards, numUncommon, Constant.Rarity.Uncommon, null, started));
|
names.addAll(generateCards(allCards, numUncommon, Constant.Rarity.Uncommon, null, started));
|
||||||
names.addAll(generateCards(allCards, numRare, Constant.Rarity.Rare, null, started));
|
names.addAll(generateCards(allCards, numRare, Constant.Rarity.Rare, null, started));
|
||||||
@@ -140,21 +122,25 @@ public class QuestBoosterPack implements NewConstants {
|
|||||||
|
|
||||||
allCards = CardFilter.getRarity(allCards, rarity);
|
allCards = CardFilter.getRarity(allCards, rarity);
|
||||||
int count = 0, i = 0;
|
int count = 0, i = 0;
|
||||||
|
|
||||||
if (num > 1) {
|
|
||||||
// Force evaluation (solidify) the generator because we've applied
|
|
||||||
// a filter to it, and we're about to use it more than once.
|
|
||||||
|
|
||||||
allCards = GeneratorFunctions.solidify(allCards);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (count < num) {
|
|
||||||
String name;
|
|
||||||
|
|
||||||
if (color == null)
|
while (count < num) {
|
||||||
name = getCardName(allCards, colorOrder.get(i % size));
|
String name = null;
|
||||||
else
|
|
||||||
|
if (color == null) {
|
||||||
|
final String color2 = colorOrder.get(i % size);
|
||||||
|
|
||||||
|
if (color2 != null) {
|
||||||
|
// Mantis Issue 77: avoid calling
|
||||||
|
// getCardName(Generator<Card>, String) with null as 2nd
|
||||||
|
// parameter.
|
||||||
|
name = getCardName(allCards, color2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name == null) {
|
||||||
|
// We can't decide on a color, so just pick a card.
|
||||||
name = getCardName(allCards);
|
name = getCardName(allCards);
|
||||||
|
}
|
||||||
|
|
||||||
if (name != null && !names.contains(name)) {
|
if (name != null && !names.contains(name)) {
|
||||||
names.add(name);
|
names.add(name);
|
||||||
|
|||||||
Reference in New Issue
Block a user