mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
- Sort custom drafts / cubes alphabetically in the list.
This commit is contained in:
@@ -43,6 +43,7 @@ import java.util.*;
|
|||||||
* Booster Draft Format.
|
* Booster Draft Format.
|
||||||
*/
|
*/
|
||||||
public class BoosterDraft implements IBoosterDraft {
|
public class BoosterDraft implements IBoosterDraft {
|
||||||
|
|
||||||
private static final int N_PLAYERS = 8;
|
private static final int N_PLAYERS = 8;
|
||||||
public static final String FILE_EXT = ".draft";
|
public static final String FILE_EXT = ".draft";
|
||||||
private final List<LimitedPlayer> players = new ArrayList<>();
|
private final List<LimitedPlayer> players = new ArrayList<>();
|
||||||
@@ -60,101 +61,114 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
|
|
||||||
public static BoosterDraft createDraft(final LimitedPoolType draftType) {
|
public static BoosterDraft createDraft(final LimitedPoolType draftType) {
|
||||||
final BoosterDraft draft = new BoosterDraft(draftType);
|
final BoosterDraft draft = new BoosterDraft(draftType);
|
||||||
if (!draft.generateProduct()) { return null; }
|
if (!draft.generateProduct()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
draft.initializeBoosters();
|
draft.initializeBoosters();
|
||||||
return draft;
|
return draft;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean generateProduct() {
|
protected boolean generateProduct() {
|
||||||
switch (this.draftFormat) {
|
switch (this.draftFormat) {
|
||||||
case Full: // Draft from all cards in Forge
|
case Full: // Draft from all cards in Forge
|
||||||
final Supplier<List<PaperCard>> s = new UnOpenedProduct(SealedProduct.Template.genericBooster);
|
final Supplier<List<PaperCard>> s = new UnOpenedProduct(SealedProduct.Template.genericBooster);
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
this.product.add(s);
|
this.product.add(s);
|
||||||
}
|
|
||||||
IBoosterDraft.LAND_SET_CODE[0] = CardEdition.Predicates.getRandomSetWithAllBasicLands(FModel.getMagicDb().getEditions());
|
|
||||||
IBoosterDraft.CUSTOM_RANKINGS_FILE[0] = null;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Block: // Draft from cards by block or set
|
|
||||||
case FantasyBlock:
|
|
||||||
final List<CardBlock> blocks = new ArrayList<>();
|
|
||||||
final IStorage<CardBlock> storage = this.draftFormat == LimitedPoolType.Block
|
|
||||||
? FModel.getBlocks()
|
|
||||||
: FModel.getFantasyBlocks();
|
|
||||||
|
|
||||||
for (final CardBlock b : storage) {
|
|
||||||
if (b.getCntBoostersDraft() > 0) {
|
|
||||||
blocks.add(b);
|
|
||||||
}
|
}
|
||||||
}
|
IBoosterDraft.LAND_SET_CODE[0] = CardEdition.Predicates.getRandomSetWithAllBasicLands(FModel.getMagicDb().getEditions());
|
||||||
|
IBoosterDraft.CUSTOM_RANKINGS_FILE[0] = null;
|
||||||
|
break;
|
||||||
|
|
||||||
final CardBlock block = SGuiChoose.oneOrNone("Choose Block", blocks);
|
case Block: // Draft from cards by block or set
|
||||||
if (block == null) { return false; }
|
case FantasyBlock:
|
||||||
|
final List<CardBlock> blocks = new ArrayList<>();
|
||||||
|
final IStorage<CardBlock> storage = this.draftFormat == LimitedPoolType.Block
|
||||||
|
? FModel.getBlocks()
|
||||||
|
: FModel.getFantasyBlocks();
|
||||||
|
|
||||||
final List<CardEdition> cardSets = block.getSets();
|
for (final CardBlock b : storage) {
|
||||||
final Stack<String> sets = new Stack<>();
|
if (b.getCntBoostersDraft() > 0) {
|
||||||
for (int k = cardSets.size() - 1; k >= 0; k--) {
|
blocks.add(b);
|
||||||
sets.add(cardSets.get(k).getCode());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (final String setCode : block.getMetaSetNames()) {
|
|
||||||
if (block.getMetaSet(setCode).isDraftable()) {
|
|
||||||
sets.push(setCode); // to the beginning
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (sets.isEmpty()) {
|
final CardBlock block = SGuiChoose.oneOrNone("Choose Block", blocks);
|
||||||
SOptionPane.showErrorDialog(block.toString() + " does not contain any set combinations.");
|
if (block == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int nPacks = block.getCntBoostersDraft();
|
final List<CardEdition> cardSets = block.getSets();
|
||||||
|
final Stack<String> sets = new Stack<>();
|
||||||
|
for (int k = cardSets.size() - 1; k >= 0; k--) {
|
||||||
|
sets.add(cardSets.get(k).getCode());
|
||||||
|
}
|
||||||
|
|
||||||
if (sets.size() > 1) {
|
for (final String setCode : block.getMetaSetNames()) {
|
||||||
Object p;
|
if (block.getMetaSet(setCode).isDraftable()) {
|
||||||
if (nPacks == 3 && sets.size() < 4) {
|
sets.push(setCode); // to the beginning
|
||||||
p = SGuiChoose.oneOrNone("Choose Set Combination", getSetCombos(sets));
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sets.isEmpty()) {
|
||||||
|
SOptionPane.showErrorDialog(block.toString() + " does not contain any set combinations.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int nPacks = block.getCntBoostersDraft();
|
||||||
|
|
||||||
|
if (sets.size() > 1) {
|
||||||
|
Object p;
|
||||||
|
if (nPacks == 3 && sets.size() < 4) {
|
||||||
|
p = SGuiChoose.oneOrNone("Choose Set Combination", getSetCombos(sets));
|
||||||
|
} else {
|
||||||
|
p = choosePackByPack(sets, nPacks);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String[] pp = p.toString().split("/");
|
||||||
|
for (int i = 0; i < nPacks; i++) {
|
||||||
|
this.product.add(block.getBooster(pp[i]));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
p = choosePackByPack(sets, nPacks);
|
final IUnOpenedProduct product1 = block.getBooster(sets.get(0));
|
||||||
|
|
||||||
|
for (int i = 0; i < nPacks; i++) {
|
||||||
|
this.product.add(product1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p == null) { return false; }
|
IBoosterDraft.LAND_SET_CODE[0] = block.getLandSet();
|
||||||
|
IBoosterDraft.CUSTOM_RANKINGS_FILE[0] = null;
|
||||||
|
break;
|
||||||
|
|
||||||
final String[] pp = p.toString().split("/");
|
case Custom:
|
||||||
for (int i = 0; i < nPacks; i++) {
|
final List<CustomLimited> myDrafts = loadCustomDrafts();
|
||||||
this.product.add(block.getBooster(pp[i]));
|
|
||||||
|
myDrafts.sort(new Comparator<CustomLimited>() {
|
||||||
|
@Override
|
||||||
|
public int compare(CustomLimited o1, CustomLimited o2) {
|
||||||
|
return o1.getName().compareTo(o2.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (myDrafts.isEmpty()) {
|
||||||
|
SOptionPane.showMessageDialog("No custom draft files found.");
|
||||||
|
} else {
|
||||||
|
final CustomLimited customDraft = SGuiChoose.oneOrNone("Choose Custom Draft", myDrafts);
|
||||||
|
if (customDraft == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setupCustomDraft(customDraft);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else {
|
|
||||||
final IUnOpenedProduct product1 = block.getBooster(sets.get(0));
|
|
||||||
|
|
||||||
for (int i = 0; i < nPacks; i++) {
|
default:
|
||||||
this.product.add(product1);
|
throw new NoSuchElementException("Draft for mode " + this.draftFormat + " has not been set up!");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IBoosterDraft.LAND_SET_CODE[0] = block.getLandSet();
|
|
||||||
IBoosterDraft.CUSTOM_RANKINGS_FILE[0] = null;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Custom:
|
|
||||||
final List<CustomLimited> myDrafts = loadCustomDrafts();
|
|
||||||
|
|
||||||
if (myDrafts.isEmpty()) {
|
|
||||||
SOptionPane.showMessageDialog("No custom draft files found.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
final CustomLimited customDraft = SGuiChoose.oneOrNone("Choose Custom Draft", myDrafts);
|
|
||||||
if (customDraft == null) { return false; }
|
|
||||||
|
|
||||||
this.setupCustomDraft(customDraft);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new NoSuchElementException("Draft for mode " + this.draftFormat + " has not been set up!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -177,12 +191,13 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
protected BoosterDraft() {
|
protected BoosterDraft() {
|
||||||
this(LimitedPoolType.Full);
|
this(LimitedPoolType.Full);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BoosterDraft(final LimitedPoolType draftType) {
|
protected BoosterDraft(final LimitedPoolType draftType) {
|
||||||
this.draftFormat = draftType;
|
this.draftFormat = draftType;
|
||||||
|
|
||||||
localPlayer = new LimitedPlayer(0);
|
localPlayer = new LimitedPlayer(0);
|
||||||
players.add(localPlayer);
|
players.add(localPlayer);
|
||||||
for(int i = 1; i < N_PLAYERS; i++) {
|
for (int i = 1; i < N_PLAYERS; i++) {
|
||||||
players.add(new LimitedPlayerAI(i));
|
players.add(new LimitedPlayerAI(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +225,9 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
IBoosterDraft.CUSTOM_RANKINGS_FILE[0] = draft.getCustomRankingsFileName();
|
IBoosterDraft.CUSTOM_RANKINGS_FILE[0] = draft.getCustomRankingsFileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Looks for draft files, reads them, returns a list. */
|
/**
|
||||||
|
* Looks for draft files, reads them, returns a list.
|
||||||
|
*/
|
||||||
private static List<CustomLimited> loadCustomDrafts() {
|
private static List<CustomLimited> loadCustomDrafts() {
|
||||||
String[] dList;
|
String[] dList;
|
||||||
final List<CustomLimited> customs = new ArrayList<>();
|
final List<CustomLimited> customs = new ArrayList<>();
|
||||||
@@ -262,7 +279,7 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initializeBoosters() {
|
public void initializeBoosters() {
|
||||||
for(Supplier<List<PaperCard>> boosterRound : this.product) {
|
for (Supplier<List<PaperCard>> boosterRound : this.product) {
|
||||||
for (int i = 0; i < N_PLAYERS; i++) {
|
for (int i = 0; i < N_PLAYERS; i++) {
|
||||||
this.players.get(i).receiveUnopenedPack(boosterRound.get());
|
this.players.get(i).receiveUnopenedPack(boosterRound.get());
|
||||||
}
|
}
|
||||||
@@ -279,7 +296,7 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(LimitedPlayer pl : this.players) {
|
for (LimitedPlayer pl : this.players) {
|
||||||
pl.newPack();
|
pl.newPack();
|
||||||
}
|
}
|
||||||
this.currentBoosterSize = firstPlayer.packQueue.peek().size();
|
this.currentBoosterSize = firstPlayer.packQueue.peek().size();
|
||||||
@@ -290,7 +307,7 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
public Deck[] getDecks() {
|
public Deck[] getDecks() {
|
||||||
Deck decks[] = new Deck[7];
|
Deck decks[] = new Deck[7];
|
||||||
for (int i = 1; i < N_PLAYERS; i++) {
|
for (int i = 1; i < N_PLAYERS; i++) {
|
||||||
decks[i-1] = ((LimitedPlayerAI)this.players.get(i)).buildDeck();
|
decks[i - 1] = ((LimitedPlayerAI) this.players.get(i)).buildDeck();
|
||||||
}
|
}
|
||||||
return decks;
|
return decks;
|
||||||
}
|
}
|
||||||
@@ -298,7 +315,7 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
public void passPacks() {
|
public void passPacks() {
|
||||||
// Alternate direction of pack passing
|
// Alternate direction of pack passing
|
||||||
int adjust = this.nextBoosterGroup % 2 == 1 ? 1 : -1;
|
int adjust = this.nextBoosterGroup % 2 == 1 ? 1 : -1;
|
||||||
for(int i = 0; i < N_PLAYERS; i++) {
|
for (int i = 0; i < N_PLAYERS; i++) {
|
||||||
List<PaperCard> passingPack = this.players.get(i).passPack();
|
List<PaperCard> passingPack = this.players.get(i).passPack();
|
||||||
|
|
||||||
if (!passingPack.isEmpty()) {
|
if (!passingPack.isEmpty()) {
|
||||||
@@ -335,7 +352,9 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
return !this.isRoundOver() || !this.localPlayer.unopenedPacks.isEmpty();
|
return !this.isRoundOver() || !this.localPlayer.unopenedPacks.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setChoice(final PaperCard c) {
|
public void setChoice(final PaperCard c) {
|
||||||
final List<PaperCard> thisBooster = this.localPlayer.nextChoice();
|
final List<PaperCard> thisBooster = this.localPlayer.nextChoice();
|
||||||
@@ -352,11 +371,10 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
this.passPacks();
|
this.passPacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String choosePackByPack(final List<String> setz, int packs) {
|
private static String choosePackByPack(final List<String> setz, int packs) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
for(int i = 1; i <= packs; i++) {
|
for (int i = 1; i <= packs; i++) {
|
||||||
String choice = SGuiChoose.oneOrNone(String.format("Choose set for Pack %d of %d", i, packs), setz);
|
String choice = SGuiChoose.oneOrNone(String.format("Choose set for Pack %d of %d", i, packs), setz);
|
||||||
if (choice == null) {
|
if (choice == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -443,15 +461,13 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
if (cc.equals(c)) {
|
if (cc.equals(c)) {
|
||||||
pickValue = thisBooster.size()
|
pickValue = thisBooster.size()
|
||||||
* (1f - (((float) this.currentBoosterPick / this.currentBoosterSize) * 2f));
|
* (1f - (((float) this.currentBoosterPick / this.currentBoosterSize) * 2f));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
pickValue = 0;
|
pickValue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.draftPicks.containsKey(cnBk)) {
|
if (!this.draftPicks.containsKey(cnBk)) {
|
||||||
this.draftPicks.put(cnBk, pickValue);
|
this.draftPicks.put(cnBk, pickValue);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
final float curValue = this.draftPicks.get(cnBk);
|
final float curValue = this.draftPicks.get(cnBk);
|
||||||
final float newValue = (curValue + pickValue) / 2;
|
final float newValue = (curValue + pickValue) / 2;
|
||||||
this.draftPicks.put(cnBk, newValue);
|
this.draftPicks.put(cnBk, newValue);
|
||||||
|
|||||||
Reference in New Issue
Block a user