- Sort custom drafts / cubes alphabetically in the list.

This commit is contained in:
Agetian
2017-07-11 17:03:35 +00:00
parent 546fc33ba6
commit df56df5ede

View File

@@ -43,6 +43,7 @@ import java.util.*;
* Booster Draft Format.
*/
public class BoosterDraft implements IBoosterDraft {
private static final int N_PLAYERS = 8;
public static final String FILE_EXT = ".draft";
private final List<LimitedPlayer> players = new ArrayList<>();
@@ -60,7 +61,9 @@ public class BoosterDraft implements IBoosterDraft {
public static BoosterDraft createDraft(final LimitedPoolType draftType) {
final BoosterDraft draft = new BoosterDraft(draftType);
if (!draft.generateProduct()) { return null; }
if (!draft.generateProduct()) {
return null;
}
draft.initializeBoosters();
return draft;
}
@@ -91,7 +94,9 @@ public class BoosterDraft implements IBoosterDraft {
}
final CardBlock block = SGuiChoose.oneOrNone("Choose Block", blocks);
if (block == null) { return false; }
if (block == null) {
return false;
}
final List<CardEdition> cardSets = block.getSets();
final Stack<String> sets = new Stack<>();
@@ -120,14 +125,15 @@ public class BoosterDraft implements IBoosterDraft {
p = choosePackByPack(sets, nPacks);
}
if (p == null) { return false; }
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 {
final IUnOpenedProduct product1 = block.getBooster(sets.get(0));
for (int i = 0; i < nPacks; i++) {
@@ -142,12 +148,20 @@ public class BoosterDraft implements IBoosterDraft {
case Custom:
final List<CustomLimited> myDrafts = loadCustomDrafts();
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 {
} else {
final CustomLimited customDraft = SGuiChoose.oneOrNone("Choose Custom Draft", myDrafts);
if (customDraft == null) { return false; }
if (customDraft == null) {
return false;
}
this.setupCustomDraft(customDraft);
}
@@ -177,12 +191,13 @@ public class BoosterDraft implements IBoosterDraft {
protected BoosterDraft() {
this(LimitedPoolType.Full);
}
protected BoosterDraft(final LimitedPoolType draftType) {
this.draftFormat = draftType;
localPlayer = new LimitedPlayer(0);
players.add(localPlayer);
for(int i = 1; i < N_PLAYERS; i++) {
for (int i = 1; i < N_PLAYERS; i++) {
players.add(new LimitedPlayerAI(i));
}
}
@@ -210,7 +225,9 @@ public class BoosterDraft implements IBoosterDraft {
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() {
String[] dList;
final List<CustomLimited> customs = new ArrayList<>();
@@ -262,7 +279,7 @@ public class BoosterDraft implements IBoosterDraft {
}
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++) {
this.players.get(i).receiveUnopenedPack(boosterRound.get());
}
@@ -279,7 +296,7 @@ public class BoosterDraft implements IBoosterDraft {
return false;
}
for(LimitedPlayer pl : this.players) {
for (LimitedPlayer pl : this.players) {
pl.newPack();
}
this.currentBoosterSize = firstPlayer.packQueue.peek().size();
@@ -290,7 +307,7 @@ public class BoosterDraft implements IBoosterDraft {
public Deck[] getDecks() {
Deck decks[] = new Deck[7];
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;
}
@@ -298,7 +315,7 @@ public class BoosterDraft implements IBoosterDraft {
public void passPacks() {
// Alternate direction of pack passing
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();
if (!passingPack.isEmpty()) {
@@ -335,7 +352,9 @@ public class BoosterDraft implements IBoosterDraft {
return !this.isRoundOver() || !this.localPlayer.unopenedPacks.isEmpty();
}
/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
@Override
public void setChoice(final PaperCard c) {
final List<PaperCard> thisBooster = this.localPlayer.nextChoice();
@@ -352,11 +371,10 @@ public class BoosterDraft implements IBoosterDraft {
this.passPacks();
}
private static String choosePackByPack(final List<String> setz, int packs) {
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);
if (choice == null) {
return null;
@@ -443,15 +461,13 @@ public class BoosterDraft implements IBoosterDraft {
if (cc.equals(c)) {
pickValue = thisBooster.size()
* (1f - (((float) this.currentBoosterPick / this.currentBoosterSize) * 2f));
}
else {
} else {
pickValue = 0;
}
if (!this.draftPicks.containsKey(cnBk)) {
this.draftPicks.put(cnBk, pickValue);
}
else {
} else {
final float curValue = this.draftPicks.get(cnBk);
final float newValue = (curValue + pickValue) / 2;
this.draftPicks.put(cnBk, newValue);