mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
data for booster generation incorporated into CardSet
This commit is contained in:
@@ -46,7 +46,7 @@ public final class SetUtils {
|
|||||||
|
|
||||||
// Perform that first of all
|
// Perform that first of all
|
||||||
static {
|
static {
|
||||||
loadSetData();
|
loadSetData(loadBoosterData());
|
||||||
loadBlockData();
|
loadBlockData();
|
||||||
loadFormatData();
|
loadFormatData();
|
||||||
}
|
}
|
||||||
@@ -67,8 +67,35 @@ public final class SetUtils {
|
|||||||
return set == null ? "" : set.getCode2();
|
return set == null ? "" : set.getCode2();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Map<String, CardSet.BoosterData> loadBoosterData()
|
||||||
|
{
|
||||||
|
ArrayList<String> fData = FileUtil.readFile("res/blockdata/boosters.txt");
|
||||||
|
Map<String, CardSet.BoosterData> result = new HashMap<String, CardSet.BoosterData>();
|
||||||
|
|
||||||
|
|
||||||
|
for (String s : fData) {
|
||||||
|
if (StringUtils.isBlank(s)) { continue; }
|
||||||
|
|
||||||
|
String[] sParts = s.trim().split("\\|");
|
||||||
|
String code = null;
|
||||||
|
int nC = 0, nU = 0, nR = 0, nS = 0;
|
||||||
|
for (String sPart : sParts) {
|
||||||
|
String[] kv = sPart.split(":", 2);
|
||||||
|
String key = kv[0].toLowerCase();
|
||||||
|
|
||||||
|
if (key.equalsIgnoreCase("Set")) { code = kv[1]; }
|
||||||
|
if (key.equalsIgnoreCase("Commons")) { nC = Integer.parseInt(kv[1]); }
|
||||||
|
if (key.equalsIgnoreCase("Uncommons")) { nU = Integer.parseInt(kv[1]); }
|
||||||
|
if (key.equalsIgnoreCase("Rares")) { nR = Integer.parseInt(kv[1]); }
|
||||||
|
if (key.equalsIgnoreCase("Special")) { nS = Integer.parseInt(kv[1]); }
|
||||||
|
}
|
||||||
|
result.put(code, new CardSet.BoosterData(nC, nU, nR, nS));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// parser code - quite boring.
|
// parser code - quite boring.
|
||||||
private static void loadSetData() {
|
private static void loadSetData(Map<String, CardSet.BoosterData> boosters) {
|
||||||
ArrayList<String> fData = FileUtil.readFile("res/blockdata/setdata.txt");
|
ArrayList<String> fData = FileUtil.readFile("res/blockdata/setdata.txt");
|
||||||
|
|
||||||
for (String s : fData) {
|
for (String s : fData) {
|
||||||
@@ -94,11 +121,13 @@ public final class SetUtils {
|
|||||||
alias = kv[1];
|
alias = kv[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CardSet set = new CardSet(index, name, code, code2);
|
CardSet set = new CardSet(index, name, code, code2, boosters.get(code));
|
||||||
|
boosters.remove(code);
|
||||||
setsByCode.put(code, set);
|
setsByCode.put(code, set);
|
||||||
if (alias != null) { setsByCode.put(alias, set); }
|
if (alias != null) { setsByCode.put(alias, set); }
|
||||||
allSets.add(set);
|
allSets.add(set);
|
||||||
}
|
}
|
||||||
|
assert boosters.isEmpty();
|
||||||
Collections.sort(allSets);
|
Collections.sort(allSets);
|
||||||
allSets = Collections.unmodifiableList(allSets);
|
allSets = Collections.unmodifiableList(allSets);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import forge.MyRandom;
|
|||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.item.CardDb;
|
import forge.item.CardDb;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
|
|
||||||
|
import java.security.InvalidParameterException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -36,7 +38,8 @@ public class BoosterGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// These lists are to hold cards grouped by rarity in advance.
|
// These lists are to hold cards grouped by rarity in advance.
|
||||||
private final List<CardPrinted> allNoLands = new ArrayList<CardPrinted>();
|
private final List<CardPrinted> basicLands = new ArrayList<CardPrinted>();
|
||||||
|
private final List<CardPrinted> allButLands = new ArrayList<CardPrinted>();
|
||||||
private final List<CardPrinted> commons = new ArrayList<CardPrinted>();
|
private final List<CardPrinted> commons = new ArrayList<CardPrinted>();
|
||||||
private final List<CardPrinted> uncommons = new ArrayList<CardPrinted>();
|
private final List<CardPrinted> uncommons = new ArrayList<CardPrinted>();
|
||||||
private final List<CardPrinted> rares = new ArrayList<CardPrinted>();
|
private final List<CardPrinted> rares = new ArrayList<CardPrinted>();
|
||||||
@@ -48,21 +51,17 @@ public class BoosterGenerator {
|
|||||||
|
|
||||||
private static final List<CardPrinted> emptyList = Collections.unmodifiableList( new ArrayList<CardPrinted>(0) );
|
private static final List<CardPrinted> emptyList = Collections.unmodifiableList( new ArrayList<CardPrinted>(0) );
|
||||||
|
|
||||||
// This set of cards
|
// Modern boosters contain 10 commons, 3 uncommmons, 1 rare/mythic
|
||||||
private int numCommons = 0;
|
// They also contain 1 land and 1 token/rules, but we don't pick them now.
|
||||||
private int numUncommons = 0;
|
private int numCommons = 10;
|
||||||
private int numRareSlots = 0;
|
private int numUncommons = 3;
|
||||||
|
private int numRareSlots = 1;
|
||||||
private int numSpecials = 0;
|
private int numSpecials = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Constructor for BoosterGenerator.</p>
|
* <p>Constructor for BoosterGenerator.</p>
|
||||||
*/
|
*/
|
||||||
public BoosterGenerator(Iterable<CardPrinted> cards) {
|
public BoosterGenerator(Iterable<CardPrinted> cards) {
|
||||||
numCommons = 11;
|
|
||||||
numUncommons = 3;
|
|
||||||
numRareSlots = 1;
|
|
||||||
numSpecials = 0;
|
|
||||||
|
|
||||||
for (CardPrinted c : cards) {
|
for (CardPrinted c : cards) {
|
||||||
addToRarity(c);
|
addToRarity(c);
|
||||||
}
|
}
|
||||||
@@ -78,42 +77,24 @@ public class BoosterGenerator {
|
|||||||
*
|
*
|
||||||
* @param setCode a {@link java.lang.String} object.
|
* @param setCode a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public BoosterGenerator(final String setCode) {
|
public BoosterGenerator(final CardSet cardSet) {
|
||||||
numCommons = 0;
|
if (!cardSet.canGenerateBooster()) {
|
||||||
numUncommons = 0;
|
throw new InvalidParameterException("BoosterGenerator: Set " + cardSet + " cannot generate boosters!");
|
||||||
numRareSlots = 0;
|
}
|
||||||
numSpecials = 0;
|
CardSet.BoosterData bs = cardSet.getBoosterData();
|
||||||
|
|
||||||
List<String> setsList = Arrays.asList(new String[]{setCode});
|
numCommons = bs.getCommon();
|
||||||
Predicate<CardPrinted> filter = CardPrinted.Predicates.printedInSets(setsList, true);
|
numUncommons = bs.getUncommon();
|
||||||
|
numRareSlots = bs.getRare();
|
||||||
|
numSpecials = bs.getSpecial();
|
||||||
|
|
||||||
|
Predicate<CardPrinted> filter = CardPrinted.Predicates.printedInSets(cardSet.getCode());
|
||||||
List<CardPrinted> cardsInThisSet = filter.select(CardDb.instance().getAllCards());
|
List<CardPrinted> cardsInThisSet = filter.select(CardDb.instance().getAllCards());
|
||||||
|
|
||||||
for (CardPrinted c : cardsInThisSet) {
|
for (CardPrinted c : cardsInThisSet) {
|
||||||
addToRarity(c);
|
addToRarity(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<String> bpData = FileUtil.readFile("res/boosterdata/" + setCode + ".pack");
|
|
||||||
|
|
||||||
for (String line : bpData) {
|
|
||||||
if (line.startsWith("Commons:")) {
|
|
||||||
numCommons = Integer.parseInt(line.substring(8));
|
|
||||||
} else if (line.startsWith("Uncommons:")) {
|
|
||||||
numUncommons = Integer.parseInt(line.substring(10));
|
|
||||||
} else if (line.startsWith("Rares:")) {
|
|
||||||
numRareSlots = Integer.parseInt(line.substring(6));
|
|
||||||
} else if (line.startsWith("Specials:")) {
|
|
||||||
numSpecials = Integer.parseInt(line.substring(9));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Constant.Runtime.DevMode[0]) {
|
|
||||||
System.out.println("numCommons: " + numCommons);
|
|
||||||
System.out.println("numUncommons: " + numUncommons);
|
|
||||||
System.out.println("numRares: " + numRareSlots);
|
|
||||||
System.out.println("numSpecials: " + numSpecials);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CardPrinted> pickRandomCards(List<CardPrinted> source, int count)
|
private List<CardPrinted> pickRandomCards(List<CardPrinted> source, int count)
|
||||||
@@ -202,7 +183,7 @@ public class BoosterGenerator {
|
|||||||
|
|
||||||
temp.addAll(pickRandomCards(specials, nSpecs));
|
temp.addAll(pickRandomCards(specials, nSpecs));
|
||||||
|
|
||||||
temp.addAll(pickRandomCards(allNoLands, nAnyCard));
|
temp.addAll(pickRandomCards(allButLands, nAnyCard));
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
@@ -216,9 +197,8 @@ public class BoosterGenerator {
|
|||||||
case Special: specials.add(c); break;
|
case Special: specials.add(c); break;
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
if (!c.getCard().getType().isBasicLand()) {
|
|
||||||
allNoLands.add(c);
|
if (c.getCard().getType().isBasicLand()) { basicLands.add(c); } else { allButLands.add(c); }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,17 @@ public final class CardSet implements Comparable<CardSet> { // immutable
|
|||||||
private final String code;
|
private final String code;
|
||||||
private final String code2;
|
private final String code2;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private final BoosterData boosterData;
|
||||||
|
|
||||||
public CardSet(final int index, final String name, final String code, final String code2) {
|
public CardSet(final int index, final String name, final String code, final String code2) {
|
||||||
|
this(index, name, code, code2, null);
|
||||||
|
}
|
||||||
|
public CardSet(final int index, final String name, final String code, final String code2, BoosterData booster) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.code2 = code2;
|
this.code2 = code2;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.boosterData = booster;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final CardSet unknown = new CardSet(-1, "Undefined", "???", "??");
|
public static final CardSet unknown = new CardSet(-1, "Undefined", "???", "??");
|
||||||
@@ -28,6 +33,8 @@ public final class CardSet implements Comparable<CardSet> { // immutable
|
|||||||
public String getCode2() { return code2; }
|
public String getCode2() { return code2; }
|
||||||
public int getIndex() { return index; }
|
public int getIndex() { return index; }
|
||||||
|
|
||||||
|
public boolean canGenerateBooster() { return boosterData != null; }
|
||||||
|
public BoosterData getBoosterData() { return boosterData; }
|
||||||
|
|
||||||
public static final Lambda1<String, CardSet> fnGetName = new Lambda1<String, CardSet>() {
|
public static final Lambda1<String, CardSet> fnGetName = new Lambda1<String, CardSet>() {
|
||||||
@Override public String apply(final CardSet arg1) { return arg1.name; } };
|
@Override public String apply(final CardSet arg1) { return arg1.name; } };
|
||||||
@@ -59,4 +66,35 @@ public final class CardSet implements Comparable<CardSet> { // immutable
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name + " (set)";
|
return this.name + " (set)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class BoosterData {
|
||||||
|
private final int nCommon;
|
||||||
|
private final int nUncommon;
|
||||||
|
private final int nRare;
|
||||||
|
private final int nSpecial;
|
||||||
|
private final int nLand;
|
||||||
|
private final int foilRate;
|
||||||
|
private final static int CARDS_PER_BOOSTER = 15;
|
||||||
|
|
||||||
|
//private final String landCode;
|
||||||
|
public BoosterData(final int nC, final int nU, final int nR, final int nS) {
|
||||||
|
this(nC, nU, nR, nS, CARDS_PER_BOOSTER - nC - nR - nU - nS, 68);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BoosterData(final int nC, final int nU, final int nR, final int nS, final int nL, final int oneFoilPer) {
|
||||||
|
nCommon = nC;
|
||||||
|
nUncommon = nU;
|
||||||
|
nRare = nR;
|
||||||
|
nSpecial = nS;
|
||||||
|
nLand = nL > 0 ? nL : 0;
|
||||||
|
foilRate = oneFoilPer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCommon() { return nCommon; }
|
||||||
|
public int getUncommon() { return nUncommon; }
|
||||||
|
public int getRare() { return nRare; }
|
||||||
|
public int getSpecial() { return nSpecial; }
|
||||||
|
public int getLand() { return nLand; }
|
||||||
|
public int getFoilChance() { return foilRate; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,12 +102,12 @@ public final class BoosterDraft_1 implements BoosterDraft {
|
|||||||
Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray());
|
Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray());
|
||||||
String[] pp = p.toString().split("/");
|
String[] pp = p.toString().split("/");
|
||||||
for (int i = 0; i < nPacks; i++) {
|
for (int i = 0; i < nPacks; i++) {
|
||||||
BoosterGenerator bpMulti = new BoosterGenerator(pp[i]);
|
BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i]));
|
||||||
packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
BoosterGenerator bpOne = new BoosterGenerator(sets[0]);
|
BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0]));
|
||||||
Closure1<List<CardPrinted>, BoosterGenerator> pick1 = BoosterGenerator.getSimplePicker(bpOne);
|
Closure1<List<CardPrinted>, BoosterGenerator> pick1 = BoosterGenerator.getSimplePicker(bpOne);
|
||||||
for (int i = 0; i < nPacks; i++) { packs.add(pick1); }
|
for (int i = 0; i < nPacks; i++) { packs.add(pick1); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,11 +83,11 @@ public class SealedDeck {
|
|||||||
|
|
||||||
String[] pp = p.toString().split("/");
|
String[] pp = p.toString().split("/");
|
||||||
for (int i = 0; i < nPacks; i++) {
|
for (int i = 0; i < nPacks; i++) {
|
||||||
BoosterGenerator bpMulti = new BoosterGenerator(pp[i]);
|
BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i]));
|
||||||
packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
BoosterGenerator bpOne = new BoosterGenerator(sets[0]);
|
BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0]));
|
||||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpOne);
|
Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpOne);
|
||||||
for (int i = 0; i < nPacks; i++) { packs.add(picker); }
|
for (int i = 0; i < nPacks; i++) { packs.add(picker); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class BoosterPack implements InventoryItemFromSet {
|
|||||||
public List<CardPrinted> getCards() {
|
public List<CardPrinted> getCards() {
|
||||||
if (null == cards)
|
if (null == cards)
|
||||||
{
|
{
|
||||||
BoosterGenerator gen = new BoosterGenerator(cardSet);
|
BoosterGenerator gen = new BoosterGenerator(SetUtils.getSetByCode(cardSet));
|
||||||
cards = gen.getBoosterPack();
|
cards = gen.getBoosterPack();
|
||||||
// TODO: Add land here!
|
// TODO: Add land here!
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class BoosterDraftTest implements BoosterDraft {
|
|||||||
*/
|
*/
|
||||||
public ItemPoolView<CardPrinted> nextChoice() {
|
public ItemPoolView<CardPrinted> nextChoice() {
|
||||||
n--;
|
n--;
|
||||||
BoosterGenerator pack = new BoosterGenerator("M11");
|
BoosterGenerator pack = new BoosterGenerator(SetUtils.getSetByCode("M11"));
|
||||||
return ItemPool.createFrom(pack.getBoosterPack(), CardPrinted.class);
|
return ItemPool.createFrom(pack.getBoosterPack(), CardPrinted.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user