Fixed crash when there were no cards on a sheet, will message to stderr instead. (when asking mythics from a ARN-themed cube)

This commit is contained in:
Maxmtg
2013-04-25 14:01:32 +00:00
parent 2a2a347340
commit c9d275b8fb

View File

@@ -70,16 +70,15 @@ public class PrintSheet {
return fetchRoulette(sum + 1, roulette, toSkip); // start over from beginning, in case last cards were to skip return fetchRoulette(sum + 1, roulette, toSkip); // start over from beginning, in case last cards were to skip
} }
public CardPrinted random() {
int totalWeight = cardsWithWeights.countAll();
int index = MyRandom.getRandom().nextInt(totalWeight);
return fetchRoulette(0, index, null);
}
public List<CardPrinted> random(int number, boolean wantUnique) { public List<CardPrinted> random(int number, boolean wantUnique) {
List<CardPrinted> result = new ArrayList<CardPrinted>(); List<CardPrinted> result = new ArrayList<CardPrinted>();
int totalWeight = cardsWithWeights.countAll(); int totalWeight = cardsWithWeights.countAll();
if( totalWeight == 0) {
System.err.println("No cards were found on sheet " + name);
return result;
}
for(int iC = 0; iC < number; iC++) { for(int iC = 0; iC < number; iC++) {
int index = MyRandom.getRandom().nextInt(totalWeight); int index = MyRandom.getRandom().nextInt(totalWeight);
CardPrinted toAdd = fetchRoulette(0, index, wantUnique ? result : null); CardPrinted toAdd = fetchRoulette(0, index, wantUnique ? result : null);