mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Dragon's maze Race - sealed event packs generation
Converted all guild boosters to PrintSheet+booster-special
This commit is contained in:
@@ -18,6 +18,9 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@@ -48,6 +51,7 @@ import forge.util.TextUtil;
|
||||
*/
|
||||
public class BoosterGenerator {
|
||||
|
||||
private static final String LAND = "Land";
|
||||
public static final String ANY = "Any";
|
||||
public static final String COMMON = "Common";
|
||||
public static final String UNCOMMON = "Uncommon";
|
||||
@@ -73,7 +77,8 @@ public class BoosterGenerator {
|
||||
int numCards = slot.getRight().intValue();
|
||||
|
||||
String[] sType = TextUtil.splitWithParenthesis(slotType, ' ', '(', ')');
|
||||
String sheetKey = sType.length == 1 && booster.getEdition() != null ? slotType.trim() + " " + booster.getEdition() : slotType.trim();
|
||||
String setCode = sType.length == 1 && booster.getEdition() != null ? booster.getEdition() : null;
|
||||
String sheetKey = Singletons.getModel().getEditions().contains(setCode) ? slotType.trim() + " " + setCode: slotType.trim();
|
||||
|
||||
PrintSheet ps = getPrintSheet(sheetKey);
|
||||
result.addAll(ps.random(numCards, true));
|
||||
@@ -85,40 +90,46 @@ public class BoosterGenerator {
|
||||
public static final PrintSheet makeSheet(String sheetKey, Iterable<CardPrinted> src) {
|
||||
PrintSheet ps = new PrintSheet(sheetKey);
|
||||
String[] sKey = TextUtil.splitWithParenthesis(sheetKey, ' ', '(', ')', 2);
|
||||
|
||||
String[] operators = TextUtil.splitWithParenthesis(sKey[0], ':', '(', ')');
|
||||
Predicate<CardPrinted> extraPred = buildExtraPredicate(operators);
|
||||
String mainCode = operators[0].trim();
|
||||
if(mainCode.endsWith("s"))
|
||||
mainCode = mainCode.substring(0, mainCode.length()-1);
|
||||
|
||||
Predicate<CardPrinted> setPred = (Predicate<CardPrinted>) (sKey.length > 1 ? IPaperCard.Predicates.printedInSets(sKey[1].split(" ")) : Predicates.alwaysTrue());
|
||||
|
||||
// Pre-defined sheets:
|
||||
if (mainCode.startsWith("promo(")) { // get exactly the named cards, nevermind any restrictions
|
||||
String list = StringUtils.strip(mainCode.substring(5), "() ");
|
||||
String[] cardNames = TextUtil.splitWithParenthesis(list, ',', '"', '"');
|
||||
for(String cardName: cardNames) {
|
||||
ps.add(CardDb.instance().getCard(cardName));
|
||||
}
|
||||
List<String> operators = new LinkedList<String>(Arrays.asList(TextUtil.splitWithParenthesis(sKey[0], ':', '(', ')')));
|
||||
Predicate<CardPrinted> extraPred = buildExtraPredicate(operators);
|
||||
|
||||
} else if( mainCode.equalsIgnoreCase(ANY) ) { // no restriction on rarity
|
||||
// source replacement operators - if one is applied setPredicate will be ignored
|
||||
Iterator<String> itMod = operators.iterator();
|
||||
while(itMod.hasNext()) {
|
||||
String mainCode = itMod.next();
|
||||
if ( mainCode.regionMatches(true, 0, "fromSheet", 0, 9)) { // custom print sheet
|
||||
String sheetName = StringUtils.strip(mainCode.substring(9), "()\" ");
|
||||
src = Singletons.getModel().getPrintSheets().get(sheetName).toFlatList();
|
||||
setPred = Predicates.alwaysTrue();
|
||||
|
||||
} else if (mainCode.startsWith("promo")) { // get exactly the named cards, that's a tiny inlined print sheet
|
||||
String list = StringUtils.strip(mainCode.substring(5), "() ");
|
||||
String[] cardNames = TextUtil.splitWithParenthesis(list, ',', '"', '"');
|
||||
List<CardPrinted> srcList = new ArrayList<CardPrinted>();
|
||||
for(String cardName: cardNames)
|
||||
srcList.add(CardDb.instance().getCard(cardName));
|
||||
src = srcList;
|
||||
setPred = Predicates.alwaysTrue();
|
||||
|
||||
} else
|
||||
continue;
|
||||
|
||||
itMod.remove();
|
||||
}
|
||||
|
||||
// only special operators should remain by now - the ones that could not be turned into one predicate
|
||||
String mainCode = operators.isEmpty() ? null : operators.get(0).trim();
|
||||
|
||||
if( null == mainCode || mainCode.equalsIgnoreCase(ANY) ) { // no restriction on rarity
|
||||
Predicate<CardPrinted> predicate = Predicates.and(setPred, extraPred);
|
||||
ps.addAll(Iterables.filter(src, predicate));
|
||||
|
||||
} else if( mainCode.equalsIgnoreCase(COMMON) ) {
|
||||
Predicate<CardPrinted> predicate = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_COMMON, extraPred);
|
||||
ps.addAll(Iterables.filter(src, predicate));
|
||||
|
||||
} else if ( mainCode.equalsIgnoreCase(UNCOMMON) ) {
|
||||
Predicate<CardPrinted> predicate = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_UNCOMMON, extraPred);
|
||||
ps.addAll(Iterables.filter(src, predicate));
|
||||
|
||||
} else if ( mainCode.equalsIgnoreCase(UNCOMMON_RARE) ) { // for sets like ARN, where U1 cards are considered rare and U3 are uncommon
|
||||
|
||||
Predicate<CardPrinted> predicateRares = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred);
|
||||
ps.addAll(Iterables.filter(src, predicateRares));
|
||||
|
||||
|
||||
Predicate<CardPrinted> predicateUncommon = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_UNCOMMON, extraPred);
|
||||
ps.addAll(Iterables.filter(src, predicateUncommon), 3);
|
||||
|
||||
@@ -128,56 +139,43 @@ public class BoosterGenerator {
|
||||
|
||||
Predicate<CardPrinted> predicateMythic = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE, extraPred);
|
||||
ps.addAll(Iterables.filter(src, predicateMythic));
|
||||
|
||||
|
||||
Predicate<CardPrinted> predicateRare = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred);
|
||||
ps.addAll(Iterables.filter(src, predicateRare), 2);
|
||||
|
||||
} else if ( mainCode.equalsIgnoreCase(RARE) ) {
|
||||
Predicate<CardPrinted> predicateRare = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred);
|
||||
ps.addAll(Iterables.filter(src, predicateRare));
|
||||
|
||||
} else if ( mainCode.equalsIgnoreCase(MYTHIC) ) {
|
||||
Predicate<CardPrinted> predicateMythic = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE, extraPred);
|
||||
ps.addAll(Iterables.filter(src, predicateMythic));
|
||||
|
||||
} else if ( mainCode.equalsIgnoreCase(BASIC_LAND) ) {
|
||||
Predicate<CardPrinted> predicateLand = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_BASIC_LAND, extraPred );
|
||||
ps.addAll(Iterables.filter(src, predicateLand));
|
||||
|
||||
} else if ( mainCode.equalsIgnoreCase(TIME_SHIFTED) ) {
|
||||
Predicate<CardPrinted> predicate = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_SPECIAL, extraPred );
|
||||
ps.addAll(Iterables.filter(src, predicate));
|
||||
|
||||
} else if ( mainCode.startsWith("Custom(") || mainCode.startsWith("custom(") ) {
|
||||
String sheetName = StringUtils.strip(mainCode.substring(6), "()\" ");
|
||||
return Singletons.getModel().getPrintSheets().get(sheetName);
|
||||
}
|
||||
} else
|
||||
throw new IllegalArgumentException("Booster generator: operator could not be parsed - " + mainCode);
|
||||
return ps;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param operators
|
||||
* @return
|
||||
* This method also modifies passed parameter
|
||||
*/
|
||||
private static Predicate<CardPrinted> buildExtraPredicate(String[] operators) {
|
||||
if ( operators.length <= 1)
|
||||
return Predicates.alwaysTrue();
|
||||
|
||||
private static Predicate<CardPrinted> buildExtraPredicate(List<String> operators) {
|
||||
List<Predicate<CardPrinted>> conditions = new ArrayList<Predicate<CardPrinted>>();
|
||||
for(int i = 1; i < operators.length; i++) {
|
||||
String operator = operators[i];
|
||||
if(StringUtils.isEmpty(operator))
|
||||
|
||||
Iterator<String> itOp = operators.iterator();
|
||||
while(itOp.hasNext()) {
|
||||
String operator = itOp.next();
|
||||
if(StringUtils.isEmpty(operator)) {
|
||||
itOp.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(operator.endsWith("s"))
|
||||
operator = operator.substring(0, operator.length()-1);
|
||||
|
||||
boolean invert = operator.charAt(0) == '!';
|
||||
if( invert ) operator = operator.substring(1);
|
||||
|
||||
Predicate<CardPrinted> toAdd = null;
|
||||
if( operator.equals("dfc") ) {
|
||||
toAdd = Predicates.compose(CardRulesPredicates.splitType(CardSplitType.Transform), CardPrinted.FN_GET_RULES);
|
||||
} else if( operator.equals("land") ) {
|
||||
toAdd = Predicates.compose(CardRulesPredicates.Presets.IS_LAND, CardPrinted.FN_GET_RULES);
|
||||
if( operator.equalsIgnoreCase("dfc") ) { toAdd = Predicates.compose(CardRulesPredicates.splitType(CardSplitType.Transform), CardPrinted.FN_GET_RULES);
|
||||
} else if ( operator.equalsIgnoreCase(LAND) ) { toAdd = Predicates.compose(CardRulesPredicates.Presets.IS_LAND, CardPrinted.FN_GET_RULES);
|
||||
} else if ( operator.equalsIgnoreCase(BASIC_LAND)) { toAdd = IPaperCard.Predicates.Presets.IS_BASIC_LAND;
|
||||
} else if ( operator.equalsIgnoreCase(TIME_SHIFTED)) { toAdd = IPaperCard.Predicates.Presets.IS_SPECIAL;
|
||||
} else if ( operator.equalsIgnoreCase(MYTHIC)) { toAdd = IPaperCard.Predicates.Presets.IS_MYTHIC_RARE;
|
||||
} else if ( operator.equalsIgnoreCase(RARE)) { toAdd = IPaperCard.Predicates.Presets.IS_RARE;
|
||||
} else if ( operator.equalsIgnoreCase(UNCOMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_UNCOMMON;
|
||||
} else if ( operator.equalsIgnoreCase(COMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_COMMON;
|
||||
} else if ( operator.startsWith("name(") ) {
|
||||
operator = StringUtils.strip(operator.substring(4), "() ");
|
||||
String[] cardNames = TextUtil.splitWithParenthesis(operator, ',', '"', '"');
|
||||
@@ -185,12 +183,16 @@ public class BoosterGenerator {
|
||||
}
|
||||
|
||||
if(toAdd == null)
|
||||
throw new IllegalArgumentException("Booster generator: operator could not be parsed - " + operator);
|
||||
continue;
|
||||
else
|
||||
itOp.remove();
|
||||
|
||||
if( invert )
|
||||
toAdd = Predicates.not(toAdd);
|
||||
conditions.add(toAdd);
|
||||
}
|
||||
if( conditions.isEmpty() )
|
||||
return Predicates.alwaysTrue();
|
||||
return Predicates.and(conditions);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.List;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.util.TextUtil;
|
||||
@@ -22,11 +21,9 @@ public class BoosterTemplate extends SealedProductTemplate {
|
||||
|
||||
private final int foilRate = 68;
|
||||
private final int artIndices;
|
||||
private final String edition;
|
||||
|
||||
private BoosterTemplate(String edition0, int artIndices0, Iterable<Pair<String, Integer>> itrSlots) {
|
||||
super(itrSlots);
|
||||
this.edition = edition0;
|
||||
|
||||
private BoosterTemplate(String edition, int artIndices0, Iterable<Pair<String, Integer>> itrSlots) {
|
||||
super(edition, itrSlots);
|
||||
artIndices = artIndices0;
|
||||
}
|
||||
|
||||
@@ -38,8 +35,6 @@ public class BoosterTemplate extends SealedProductTemplate {
|
||||
return artIndices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getEdition() { return edition; }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -63,17 +58,9 @@ public class BoosterTemplate extends SealedProductTemplate {
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public static final Function<? super BoosterTemplate, String> FN_GET_CODE = new Function<BoosterTemplate, String>() {
|
||||
@Override
|
||||
public String apply(BoosterTemplate arg1) {
|
||||
return arg1.edition;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static final class Reader extends StorageReaderFile<BoosterTemplate> {
|
||||
public Reader(String pathname) {
|
||||
super(pathname, BoosterTemplate.FN_GET_CODE);
|
||||
super(pathname, BoosterTemplate.FN_GET_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -284,12 +284,10 @@ public final class CardBlock implements Comparable<CardBlock> {
|
||||
return metaSets.keySet();
|
||||
}
|
||||
|
||||
|
||||
public MetaSet getMetaSet(String key) {
|
||||
return metaSets.get(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tries to create a booster for the selected meta-set code.
|
||||
*
|
||||
|
||||
@@ -6,8 +6,6 @@ import java.util.List;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.util.TextUtil;
|
||||
import forge.util.storage.StorageReaderFile;
|
||||
|
||||
@@ -17,29 +15,19 @@ import forge.util.storage.StorageReaderFile;
|
||||
*/
|
||||
public class FatPackTemplate extends SealedProductTemplate {
|
||||
private final int cntBoosters;
|
||||
private final String edition;
|
||||
|
||||
@Override
|
||||
public String getEdition() { return edition; }
|
||||
|
||||
public int getCntBoosters() { return cntBoosters; }
|
||||
|
||||
public static final Function<? super FatPackTemplate, String> FN_GET_CODE = new Function<FatPackTemplate, String>() {
|
||||
@Override
|
||||
public String apply(FatPackTemplate arg1) {
|
||||
return arg1.edition;
|
||||
}
|
||||
};
|
||||
|
||||
private FatPackTemplate(String edition0, int boosters, Iterable<Pair<String, Integer>> itrSlots)
|
||||
private FatPackTemplate(String edition, int boosters, Iterable<Pair<String, Integer>> itrSlots)
|
||||
{
|
||||
super(itrSlots);
|
||||
edition = edition0;
|
||||
super(edition, itrSlots);
|
||||
cntBoosters = boosters;
|
||||
}
|
||||
|
||||
public static final class Reader extends StorageReaderFile<FatPackTemplate> {
|
||||
public Reader(String pathname) {
|
||||
super(pathname, FatPackTemplate.FN_GET_CODE);
|
||||
super(pathname, FatPackTemplate.FN_GET_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -91,13 +91,30 @@ import forge.util.FileUtil;
|
||||
public class MetaSet {
|
||||
|
||||
private enum MetaSetType {
|
||||
Full,
|
||||
Cube,
|
||||
JoinedSet,
|
||||
Choose,
|
||||
Random,
|
||||
Booster,
|
||||
Pack
|
||||
Full("F", "All cards"),
|
||||
Cube("C", "Cube"),
|
||||
JoinedSet("J", "Joined set"),
|
||||
Choose("Select", "Choose from list"),
|
||||
Combo("All", "Combined booster"),
|
||||
Random("Any", "Randomly selected"),
|
||||
Booster("B", "Booster"),
|
||||
SpecialBooster("S", "Special Booster"),
|
||||
Pack("T", "Tournament/Starter");
|
||||
|
||||
private final String shortHand;
|
||||
public final String descriptiveName;
|
||||
private MetaSetType(String shortname, String descName) {
|
||||
shortHand = shortname;
|
||||
descriptiveName = descName;
|
||||
}
|
||||
|
||||
public static MetaSetType smartValueOf(String trim) {
|
||||
for(MetaSetType mt : MetaSetType.values()) {
|
||||
if( mt.name().equalsIgnoreCase(trim) || mt.shortHand.equalsIgnoreCase(trim))
|
||||
return mt;
|
||||
}
|
||||
throw new IllegalArgumentException(trim + " not recognized as Meta Set");
|
||||
}
|
||||
}
|
||||
|
||||
private final MetaSetType type;
|
||||
@@ -118,21 +135,10 @@ public class MetaSet {
|
||||
int idxLastPar = creationString.lastIndexOf(')');
|
||||
|
||||
draftable = canDraft;
|
||||
type = MetaSetType.valueOf(creationString.substring(0, idxFirstPar).trim());
|
||||
type = MetaSetType.smartValueOf(creationString.substring(0, idxFirstPar).trim());
|
||||
data = creationString.substring(idxFirstPar + 1, idxLastPar);
|
||||
String description = creationString.substring(idxLastPar + 1);
|
||||
|
||||
switch (type) {
|
||||
case Cube: code = "*C:" + description; break;
|
||||
case Full: code = "*FULL"; break;
|
||||
case JoinedSet: code = "*B:" + description; break;
|
||||
case Choose: code = "*!:" + description; break;
|
||||
case Random: code = "*?:" + description; break;
|
||||
case Booster: code = "*" + description; break;
|
||||
case Pack: code = "*" + description + "(S)"; break;
|
||||
|
||||
default: throw new RuntimeException("Invalid MetaSet type: " + type);
|
||||
}
|
||||
code = description + "\u00A0(" + type.descriptiveName + ")"; // u00A0 (nbsp) will not be equal to simple space
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,6 +166,9 @@ public class MetaSet {
|
||||
case Booster:
|
||||
return new UnOpenedProduct(Singletons.getModel().getBoosters().get(data));
|
||||
|
||||
case SpecialBooster:
|
||||
return new UnOpenedProduct(Singletons.getModel().getSpecialBoosters().get(data));
|
||||
|
||||
case Pack:
|
||||
return new UnOpenedProduct(Singletons.getModel().getTournamentPacks().get(data));
|
||||
|
||||
@@ -167,11 +176,9 @@ public class MetaSet {
|
||||
Predicate<CardPrinted> predicate = IPaperCard.Predicates.printedInSets(data.split(" "));
|
||||
return new UnOpenedProduct(BoosterTemplate.genericBooster, predicate);
|
||||
|
||||
case Choose:
|
||||
return new UnOpenedMeta(data, true);
|
||||
|
||||
case Random:
|
||||
return new UnOpenedMeta(data, false);
|
||||
case Choose: return UnOpenedMeta.choose(data);
|
||||
case Random: return UnOpenedMeta.random(data);
|
||||
case Combo: return UnOpenedMeta.selectAll(data);
|
||||
|
||||
case Cube:
|
||||
final File dFolder = new File("res/sealed/");
|
||||
@@ -193,6 +200,11 @@ public class MetaSet {
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public boolean isDraftable() {
|
||||
return draftable;
|
||||
|
||||
@@ -18,28 +18,40 @@
|
||||
|
||||
package forge.card;
|
||||
|
||||
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;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.util.TextUtil;
|
||||
import forge.util.storage.StorageReaderFile;
|
||||
|
||||
public class SealedProductTemplate {
|
||||
|
||||
protected final List<Pair<String, Integer>> slots;
|
||||
protected final String name;
|
||||
|
||||
|
||||
public final List<Pair<String, Integer>> getSlots() {
|
||||
return slots;
|
||||
}
|
||||
|
||||
public String getEdition() {
|
||||
return null;
|
||||
public final String getEdition() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public SealedProductTemplate(Iterable<Pair<String, Integer>> itrSlots)
|
||||
{
|
||||
this(null, itrSlots);
|
||||
}
|
||||
|
||||
public SealedProductTemplate(String name0, Iterable<Pair<String, Integer>> itrSlots)
|
||||
{
|
||||
slots = Lists.newArrayList(itrSlots);
|
||||
name = name0;
|
||||
}
|
||||
|
||||
public int getNumberOfCardsExpected() {
|
||||
@@ -49,4 +61,32 @@ public class SealedProductTemplate {
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
protected static final Function<? super SealedProductTemplate, String> FN_GET_NAME = new Function<SealedProductTemplate, String>() {
|
||||
@Override
|
||||
public String apply(SealedProductTemplate arg1) {
|
||||
return arg1.name;
|
||||
}
|
||||
};
|
||||
|
||||
public static final class Reader extends StorageReaderFile<SealedProductTemplate> {
|
||||
public Reader(String pathname) {
|
||||
super(pathname, SealedProductTemplate.FN_GET_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SealedProductTemplate read(String line, int i) {
|
||||
String[] headAndData = TextUtil.split(line, ':', 2);
|
||||
final String edition = headAndData[0];
|
||||
final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ',', '(', ')');
|
||||
|
||||
List<Pair<String, Integer>> slots = new ArrayList<Pair<String,Integer>>();
|
||||
for(String slotDesc : data) {
|
||||
String[] kv = TextUtil.splitWithParenthesis(slotDesc, ' ', '(', ')', 2);
|
||||
slots.add(ImmutablePair.of(kv[1], Integer.parseInt(kv[0])));
|
||||
}
|
||||
|
||||
return new SealedProductTemplate(edition, slots);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.Random;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
/**
|
||||
* This type extends UnOpenedProduct to support booster choice or random boosters
|
||||
@@ -33,8 +34,14 @@ import forge.util.MyRandom;
|
||||
|
||||
public class UnOpenedMeta implements IUnOpenedProduct {
|
||||
|
||||
private enum JoinOperation {
|
||||
RandomOne,
|
||||
ChooseOne,
|
||||
SelectAll,
|
||||
}
|
||||
|
||||
private final ArrayList<MetaSet> metaSets;
|
||||
private final boolean canChoose;
|
||||
private final JoinOperation operation;
|
||||
private final Random generator = MyRandom.getRandom();
|
||||
|
||||
/**
|
||||
@@ -44,12 +51,11 @@ public class UnOpenedMeta implements IUnOpenedProduct {
|
||||
* @param choose
|
||||
* sets the random/choice status.
|
||||
*/
|
||||
public UnOpenedMeta(final String creationString, final boolean choose) {
|
||||
private UnOpenedMeta(final String creationString, final JoinOperation op) {
|
||||
metaSets = new ArrayList<MetaSet>();
|
||||
canChoose = choose;
|
||||
operation = op;
|
||||
|
||||
|
||||
for(String m : creationString.split(";")) {
|
||||
for(String m : TextUtil.splitWithParenthesis(creationString, ';', '(', ')')) {
|
||||
metaSets.add(new MetaSet(m, true));
|
||||
}
|
||||
}
|
||||
@@ -72,41 +78,42 @@ public class UnOpenedMeta implements IUnOpenedProduct {
|
||||
* known partialities for the AI.
|
||||
* @return List, list of cards.
|
||||
*/
|
||||
|
||||
public List<CardPrinted> open(final boolean isHuman) {
|
||||
|
||||
if (metaSets.size() < 1) {
|
||||
if (metaSets.isEmpty()) {
|
||||
throw new RuntimeException("Empty UnOpenedMetaset, cannot generate booster.");
|
||||
}
|
||||
|
||||
if (canChoose) {
|
||||
if (isHuman) {
|
||||
final List<String> choices = new ArrayList<String>();
|
||||
|
||||
for (MetaSet meta : metaSets) {
|
||||
choices.add(meta.getCode());
|
||||
switch(operation) {
|
||||
case ChooseOne:
|
||||
if (isHuman) {
|
||||
final MetaSet ms = GuiChoose.one("Choose booster:", metaSets);
|
||||
return ms.getBooster().get();
|
||||
}
|
||||
final Object o = GuiChoose.one("Choose booster:", choices);
|
||||
|
||||
for (int i = 0; i < metaSets.size(); i++) {
|
||||
if (o.toString().equals(metaSets.get(i).getCode())) {
|
||||
final IUnOpenedProduct newBooster = metaSets.get(i).getBooster();
|
||||
return newBooster.get();
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Could not find MetaSet " + o.toString());
|
||||
}
|
||||
else {
|
||||
|
||||
case RandomOne: // AI should fall though here from the case above
|
||||
int selected = generator.nextInt(metaSets.size());
|
||||
final IUnOpenedProduct newBooster = metaSets.get(selected).getBooster();
|
||||
return newBooster.get();
|
||||
}
|
||||
}
|
||||
else {
|
||||
int selected = generator.nextInt(metaSets.size());
|
||||
final IUnOpenedProduct newBooster = metaSets.get(selected).getBooster();
|
||||
return newBooster.get();
|
||||
|
||||
case SelectAll:
|
||||
List<CardPrinted> allCards = new ArrayList<CardPrinted>();
|
||||
for (MetaSet ms : metaSets) {
|
||||
allCards.addAll(ms.getBooster().get());
|
||||
}
|
||||
return allCards;
|
||||
}
|
||||
throw new IllegalStateException("Got wrong operation type in unopenedMeta - execution should never reach this point");
|
||||
}
|
||||
|
||||
public static UnOpenedMeta choose(String desc) {
|
||||
return new UnOpenedMeta(desc, JoinOperation.ChooseOne);
|
||||
}
|
||||
public static UnOpenedMeta random(String desc) {
|
||||
return new UnOpenedMeta(desc, JoinOperation.RandomOne);
|
||||
}
|
||||
public static UnOpenedMeta selectAll(String desc) {
|
||||
return new UnOpenedMeta(desc, JoinOperation.SelectAll);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -108,10 +108,9 @@ public class SealedCardPoolGenerator {
|
||||
return;
|
||||
|
||||
for (String pz : TextUtil.split(p, ',')) {
|
||||
String pp = pz.trim();
|
||||
int idxSp = pp.indexOf(' ');
|
||||
String setCode = idxSp > 0 ? pp.substring(idxSp+1) : pp;
|
||||
int nBoosters = idxSp > 0 ? Integer.parseInt(pp.substring(0, idxSp)) : 1;
|
||||
String[] pps = TextUtil.splitWithParenthesis(pz.trim(), ' ' , '(', ')');
|
||||
String setCode = pps[pps.length - 1];
|
||||
int nBoosters = pps.length > 1 ? Integer.parseInt(pps[0]) : 1;
|
||||
while(nBoosters-- > 0)
|
||||
this.product.add(block.getBooster(setCode));
|
||||
}
|
||||
@@ -218,17 +217,25 @@ public class SealedCardPoolGenerator {
|
||||
}
|
||||
}
|
||||
else if (nPacks == 5) {
|
||||
if (sets.length >= 2) {
|
||||
setCombos.add(String.format("%s, %s, %s, %s, %s", sets[0], sets[0], sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s, %s, %s, %s, %s", sets[1], sets[1], sets[0], sets[0], sets[0]));
|
||||
if (sets.length == 1 || !sets[0].equals(sets[1]) ) {
|
||||
setCombos.add(String.format("5 %s", sets[0]));
|
||||
}
|
||||
if (sets.length >= 3) {
|
||||
setCombos.add(String.format("%s, %s, %s, %s, %s", sets[2], sets[2], sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s, %s, %s, %s, %s", sets[2], sets[1], sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s, %s, %s, %s, %s", sets[2], sets[1], sets[1], sets[0], sets[0]));
|
||||
|
||||
if (sets.length >= 2 && !sets[0].equals(sets[1])) {
|
||||
setCombos.add(String.format("3 %s, 2 %s", sets[0], sets[1]));
|
||||
setCombos.add(String.format("2 %s, 3 %s", sets[0], sets[1]));
|
||||
}
|
||||
if (sets.length >= 3 && !sets[0].equals(sets[2])) {
|
||||
setCombos.add(String.format("3 %s, 2 %s", sets[0], sets[2]));
|
||||
setCombos.add(String.format("3 %s, %s, %s", sets[0], sets[1], sets[2]));
|
||||
setCombos.add(String.format("2 %s, 2 %s, %s", sets[0], sets[1], sets[2]));
|
||||
}
|
||||
if (sets.length >= 4) {
|
||||
setCombos.add(String.format("%s, %s, %s, %s, %s", sets[3], sets[2], sets[1], sets[0], sets[0]));
|
||||
if( sets[1].equals(sets[2]) && sets[1].equals(sets[0])) {
|
||||
setCombos.add(String.format("%s, 4 %s", sets[3], sets[0])); // for guild sealed
|
||||
} else {
|
||||
setCombos.add(String.format("%s, %s, %s, 2 %s", sets[3], sets[2], sets[1], sets[0]));
|
||||
}
|
||||
}
|
||||
if (sets.length >= 5) {
|
||||
setCombos.add(String.format("%s, %s, %s, %s, %s", sets[4], sets[3], sets[2], sets[1], sets[0]));
|
||||
|
||||
@@ -121,5 +121,9 @@ public class PrintSheet {
|
||||
return cardsWithWeights.isEmpty();
|
||||
}
|
||||
|
||||
public Iterable<CardPrinted> toFlatList() {
|
||||
return cardsWithWeights.toFlatList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import forge.card.CardRulesReader;
|
||||
import forge.card.EditionCollection;
|
||||
import forge.card.FatPackTemplate;
|
||||
import forge.card.FormatCollection;
|
||||
import forge.card.SealedProductTemplate;
|
||||
import forge.card.cardfactory.CardStorageReader;
|
||||
import forge.deck.CardCollections;
|
||||
import forge.error.BugReporter;
|
||||
@@ -85,6 +86,7 @@ public enum FModel {
|
||||
private final EditionCollection editions;
|
||||
private final FormatCollection formats;
|
||||
private final IStorageView<BoosterTemplate> boosters;
|
||||
private final IStorageView<SealedProductTemplate> specialBoosters;
|
||||
private final IStorageView<BoosterTemplate> tournaments;
|
||||
private final IStorageView<FatPackTemplate> fatPacks;
|
||||
private final IStorageView<CardBlock> blocks;
|
||||
@@ -147,6 +149,7 @@ public enum FModel {
|
||||
this.editions = CardRulesReader.editions; // CardRules ctor cannot refer to FModel, since it is not yet build by that moment
|
||||
this.formats = new FormatCollection("res/blockdata/formats.txt");
|
||||
this.boosters = new StorageView<BoosterTemplate>(new BoosterTemplate.Reader("res/blockdata/boosters.txt"));
|
||||
this.specialBoosters = new StorageView<SealedProductTemplate>(new SealedProductTemplate.Reader("res/blockdata/boosters-special.txt"));
|
||||
this.tournaments = new StorageView<BoosterTemplate>(new BoosterTemplate.Reader("res/blockdata/starters.txt"));
|
||||
this.fatPacks = new StorageView<FatPackTemplate>(new FatPackTemplate.Reader("res/blockdata/fatpacks.txt"));
|
||||
this.blocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/blocks.txt", editions));
|
||||
@@ -377,6 +380,10 @@ public enum FModel {
|
||||
return boosters;
|
||||
}
|
||||
|
||||
public final IStorageView<SealedProductTemplate> getSpecialBoosters() {
|
||||
return specialBoosters;
|
||||
}
|
||||
|
||||
public IStorageView<PrintSheet> getPrintSheets() {
|
||||
return printSheets;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class StorageView<T> implements IStorageView<T> {
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(String name) {
|
||||
return this.map.containsKey(name);
|
||||
return name == null ? false : this.map.containsKey(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user