Merge branch 'move-fatpacks-to-editions' into 'master'

Move fatpacks to editions

See merge request core-developers/forge!5102
This commit is contained in:
Michael Kamensky
2021-07-24 05:18:05 +00:00
90 changed files with 175 additions and 147 deletions

View File

@@ -52,8 +52,6 @@ public class StaticData {
private IStorage<SealedProduct.Template> boosters;
private IStorage<SealedProduct.Template> specialBoosters;
private IStorage<SealedProduct.Template> tournaments;
private IStorage<FatPack.Template> fatPacks;
private IStorage<BoosterBox.Template> boosterBoxes;
private IStorage<PrintSheet> printSheets;
private static StaticData lastInstance = null;
@@ -239,14 +237,6 @@ public class StaticData {
}
}
// TODO Remove these in favor of them being associated to the Edition
/** @return {@link forge.util.storage.IStorage}<{@link forge.item.SealedProduct.Template}> */
public IStorage<FatPack.Template> getFatPacks() {
if (fatPacks == null)
fatPacks = new StorageBase<>("Fat packs", new FatPack.Template.Reader(blockDataFolder + "fatpacks.txt"));
return fatPacks;
}
/** @return {@link forge.util.storage.IStorage}<{@link forge.item.SealedProduct.Template}> */
public final IStorage<SealedProduct.Template> getTournamentPacks() {
if (tournaments == null)

View File

@@ -102,6 +102,16 @@ public final class CardEdition implements Comparable<CardEdition> {
}
}
public String getFatPackDefault() {
switch (this) {
case CORE:
case EXPANSION:
return "10";
default:
return "0";
}
}
public String toString(){
String[] names = TextUtil.splitWithParenthesis(this.name().toLowerCase(), '_');
for (int i = 0; i < names.length; i++)
@@ -261,6 +271,8 @@ public final class CardEdition implements Comparable<CardEdition> {
// SealedProduct
private String prerelease = null;
private int boosterBoxCount = 36;
private int fatPackCount = 10;
private String fatPackExtraSlots = "";
// Booster/draft info
private boolean smallSetOverride = false;
@@ -351,6 +363,8 @@ public final class CardEdition implements Comparable<CardEdition> {
public String getPrerelease() { return prerelease; }
public int getBoosterBoxCount() { return boosterBoxCount; }
public int getFatPackCount() { return fatPackCount; }
public String getFatPackExtraSlots() { return fatPackExtraSlots; }
public FoilType getFoilType() { return foilType; }
public double getFoilChanceInBooster() { return foilChanceInBooster; }
@@ -636,6 +650,8 @@ public final class CardEdition implements Comparable<CardEdition> {
res.type = enumType;
res.prerelease = section.get("Prerelease", null);
res.boosterBoxCount = Integer.parseInt(section.get("BoosterBox", enumType.getBoosterBoxDefault()));
res.fatPackCount = Integer.parseInt(section.get("FatPack", enumType.getFatPackDefault()));
res.fatPackExtraSlots = section.get("FatPackExtraSlots", "");
switch (section.get("foil", "newstyle").toLowerCase()) {
case "notsupported":
@@ -853,7 +869,7 @@ public final class CardEdition implements Comparable<CardEdition> {
private static class CanMakeFatPack implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return StaticData.instance().getFatPacks().contains(subject.getCode());
return subject.getFatPackCount() > 0;
}
}

View File

@@ -18,10 +18,8 @@
package forge.item;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Function;
@@ -30,16 +28,17 @@ import forge.ImageKeys;
import forge.StaticData;
import forge.card.CardEdition;
import forge.item.generation.BoosterGenerator;
import forge.util.TextUtil;
import forge.util.storage.StorageReaderFile;
public class FatPack extends BoxedProduct {
public static final Function<CardEdition, FatPack> FN_FROM_SET = new Function<CardEdition, FatPack>() {
@Override
public FatPack apply(final CardEdition arg1) {
FatPack.Template d = StaticData.instance().getFatPacks().get(arg1.getCode());
public FatPack apply(final CardEdition edition) {
int boosters = edition.getFatPackCount();
if (boosters <= 0) { return null; }
FatPack.Template d = new Template(edition);
if (d == null) { return null; }
return new FatPack(arg1.getName(), d, d.cntBoosters);
return new FatPack(edition.getName(), d, d.cntBoosters);
}
};
@@ -68,17 +67,6 @@ public class FatPack extends BoxedProduct {
return BoosterGenerator.getBoosterPack(fpData);
}
/*@Override
protected List<PaperCard> generate() {
List<PaperCard> result = new ArrayList<PaperCard>();
for (int i = 0; i < fpData.getCntBoosters(); i++) {
result.addAll(super.generate());
}
// Add any extra cards that may come in the fatpack after Boosters
result.addAll(BoosterGenerator.getBoosterPack(fpData));
return result;
}*/
@Override
public final Object clone() {
return new FatPack(name, fpData, fpData.cntBoosters);
@@ -92,38 +80,12 @@ public class FatPack extends BoxedProduct {
public static class Template extends SealedProduct.Template {
private final int cntBoosters;
public int getCntBoosters() { return cntBoosters; }
private Template(String edition, int boosters, Iterable<Pair<String, Integer>> itrSlots)
{
super(edition, itrSlots);
cntBoosters = boosters;
}
private Template(CardEdition edition) {
super(edition.getCode(), edition.getFatPackExtraSlots());
public static final class Reader extends StorageReaderFile<Template> {
public Reader(String pathname) {
super(pathname, FN_GET_NAME);
}
@Override
protected Template read(String line, int i) {
String[] headAndData = TextUtil.split(line, ':', 2);
final String edition = headAndData[0];
final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ',');
int nBoosters = 6;
List<Pair<String, Integer>> slots = new ArrayList<>();
for(String slotDesc : data) {
String[] kv = TextUtil.split(slotDesc, ' ', 2);
if (kv[1].startsWith("Booster"))
nBoosters = Integer.parseInt(kv[0]);
else
slots.add(ImmutablePair.of(kv[1], Integer.parseInt(kv[0])));
}
return new FatPack.Template(edition, nBoosters, slots);
}
cntBoosters = edition.getFatPackCount();
}
@Override

View File

@@ -60,7 +60,7 @@ public abstract class SealedProduct implements InventoryItemFromSet {
public SealedProduct(String name0, Template boosterData) {
if (null == name0) { throw new IllegalArgumentException("name0 must not be null"); }
if (null == boosterData) {
throw new IllegalArgumentException("boosterData must not be null");
throw new IllegalArgumentException("boosterData for " + name0 + " must not be null");
}
contents = boosterData;
name = name0;