Added fallback for quest match rewards when no boosters are in the selected sets.

This commit is contained in:
Krazy
2015-06-06 16:24:32 +00:00
parent c876abba66
commit a37ad72882
3 changed files with 87 additions and 59 deletions

View File

@@ -1,9 +1,5 @@
package forge;
import java.io.File;
import java.util.Map;
import java.util.TreeMap;
import forge.card.CardDb;
import forge.card.CardEdition;
import forge.card.CardRules;
@@ -14,10 +10,14 @@ import forge.item.SealedProduct;
import forge.util.storage.IStorage;
import forge.util.storage.StorageBase;
import java.io.File;
import java.util.Map;
import java.util.TreeMap;
/**
* The class holding game invariants, such as cards, editions, game formats. All that data, which is not supposed to be changed by player
*
*
* @author Max
*/
public class StaticData {
@@ -37,8 +37,8 @@ public class StaticData {
this.editions = new CardEdition.Collection(new CardEdition.Reader(new File(editionFolder)));
lastInstance = this;
final Map<String, CardRules> regularCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
final Map<String, CardRules> variantsCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
final Map<String, CardRules> regularCards = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
final Map<String, CardRules> variantsCards = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for (CardRules card : reader.loadCards()) {
if (null == card) continue;
@@ -59,15 +59,15 @@ public class StaticData {
commonCards.initialize(false, false);
variantCards.initialize(false, false);
this.boosters = new StorageBase<SealedProduct.Template>("Boosters", editions.getBoosterGenerator());
this.specialBoosters = new StorageBase<SealedProduct.Template>("Special boosters", new SealedProduct.Template.Reader(new File(blockDataFolder, "boosters-special.txt")));
this.tournaments = new StorageBase<SealedProduct.Template>("Starter sets", new SealedProduct.Template.Reader(new File(blockDataFolder, "starters.txt")));
this.fatPacks = new StorageBase<FatPack.Template>("Fat packs", new FatPack.Template.Reader(blockDataFolder + "fatpacks.txt"));
this.boosterBoxes = new StorageBase<BoosterBox.Template>("Booster boxes", new BoosterBox.Template.Reader(blockDataFolder + "boosterboxes.txt"));
this.printSheets = new StorageBase<PrintSheet>("Special print runs", new PrintSheet.Reader(new File(blockDataFolder, "printsheets.txt")));
this.boosters = new StorageBase<>("Boosters", editions.getBoosterGenerator());
this.specialBoosters = new StorageBase<>("Special boosters", new SealedProduct.Template.Reader(new File(blockDataFolder, "boosters-special.txt")));
this.tournaments = new StorageBase<>("Starter sets", new SealedProduct.Template.Reader(new File(blockDataFolder, "starters.txt")));
this.fatPacks = new StorageBase<>("Fat packs", new FatPack.Template.Reader(blockDataFolder + "fatpacks.txt"));
this.boosterBoxes = new StorageBase<>("Booster boxes", new BoosterBox.Template.Reader(blockDataFolder + "boosterboxes.txt"));
this.printSheets = new StorageBase<>("Special print runs", new PrintSheet.Reader(new File(blockDataFolder, "printsheets.txt")));
}
public final static StaticData instance() {
public static StaticData instance() {
return lastInstance;
}
@@ -75,21 +75,21 @@ public class StaticData {
return this.editions;
}
/** @return {@link forge.util.storage.IStorageView}<{@link forge.item.FatPackTemplate}> */
/** @return {@link forge.util.storage.IStorage}<{@link forge.item.SealedProduct.Template}> */
public IStorage<FatPack.Template> getFatPacks() {
return fatPacks;
}
public IStorage<BoosterBox.Template> getBoosterBoxes() {
return boosterBoxes;
}
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
/** @return {@link forge.util.storage.IStorage}<{@link forge.item.SealedProduct.Template}> */
public final IStorage<SealedProduct.Template> getTournamentPacks() {
return tournaments;
}
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
/** @return {@link forge.util.storage.IStorage}<{@link forge.item.SealedProduct.Template}> */
public final IStorage<SealedProduct.Template> getBoosters() {
return boosters;
}

View File

@@ -18,7 +18,7 @@ public class UnOpenedProduct implements IUnOpenedProduct {
private final SealedProduct.Template tpl;
private final Map<String, PrintSheet> sheets;
private boolean poolLimited = false; // if true after successful generation cards are removed from printsheets.
private boolean poolLimited = false; // if true after successful generation cards are removed from printsheets.
public final boolean isPoolLimited() {
return poolLimited;
@@ -27,7 +27,7 @@ public class UnOpenedProduct implements IUnOpenedProduct {
public final void setLimitedPool(boolean considerNumbersInPool) {
this.poolLimited = considerNumbersInPool; // TODO: Add 0 to parameter's name.
}
// Means to select from all unique cards (from base game, ie. no schemes or avatars)
public UnOpenedProduct(SealedProduct.Template template) {
@@ -42,7 +42,7 @@ public class UnOpenedProduct implements IUnOpenedProduct {
public UnOpenedProduct(SealedProduct.Template template, Iterable<PaperCard> cards) {
tpl = template;
sheets = new TreeMap<String, PrintSheet>();
sheets = new TreeMap<>();
prebuildSheets(cards);
}
@@ -62,15 +62,15 @@ public class UnOpenedProduct implements IUnOpenedProduct {
}
// If they request cards from an arbitrary pool, there's no use to cache printsheets.
private final List<PaperCard> getBoosterPack() {
List<PaperCard> result = new ArrayList<PaperCard>();
private List<PaperCard> getBoosterPack() {
List<PaperCard> result = new ArrayList<>();
for(Pair<String, Integer> slot : tpl.getSlots()) {
PrintSheet ps = sheets.get(slot.getLeft());
if(ps.isEmpty() && poolLimited ) {
throw new IllegalStateException("The cardpool has been depleted and has no more cards for slot " + slot.getKey());
}
List<PaperCard> foundCards = ps.random(slot.getRight().intValue(), true);
List<PaperCard> foundCards = ps.random(slot.getRight(), true);
if(poolLimited)
ps.removeAll(foundCards);
result.addAll(foundCards);
@@ -79,4 +79,3 @@ public class UnOpenedProduct implements IUnOpenedProduct {
}
}