Prevent crash in DeckGeneratorBase

This commit is contained in:
drdev
2014-12-06 04:26:01 +00:00
parent 70c2afa96a
commit 32a1ee130f

View File

@@ -94,10 +94,12 @@ public abstract class DeckGeneratorBase {
} }
protected void addSome(int cnt, List<PaperCard> source) { protected void addSome(int cnt, List<PaperCard> source) {
int srcLen = source.size();
if (srcLen == 0) { return; }
for (int i = 0; i < cnt; i++) { for (int i = 0; i < cnt; i++) {
PaperCard cp; PaperCard cp;
int lc = 0; int lc = 0;
int srcLen = source.size();
do { do {
cp = source.get(this.r.nextInt(srcLen)); cp = source.get(this.r.nextInt(srcLen));
lc++; lc++;
@@ -111,8 +113,12 @@ public abstract class DeckGeneratorBase {
final int n = this.cardCounts.get(cp.getName()); final int n = this.cardCounts.get(cp.getName());
this.cardCounts.put(cp.getName(), n + 1); this.cardCounts.put(cp.getName(), n + 1);
if( n + 1 == this.maxDuplicates ) if (n + 1 == this.maxDuplicates) {
source.remove(cp); if (source.remove(cp)) {
srcLen--;
if (srcLen == 0) { return; }
}
}
tmpDeck.append(String.format("(%d) %s [%s]%n", cp.getRules().getManaCost().getCMC(), cp.getName(), cp.getRules().getManaCost())); tmpDeck.append(String.format("(%d) %s [%s]%n", cp.getRules().getManaCost().getCMC(), cp.getName(), cp.getRules().getManaCost()));
} }
} }