Merge pull request #1938 from spjspj/master

spjspj - Update rich man to allow it to have random packs
This commit is contained in:
spjspj 2016-05-15 23:57:49 +10:00
commit 8222b06121
7 changed files with 78 additions and 36 deletions

View file

@ -86,6 +86,8 @@ public class NewTournamentDialog extends MageDialog {
private final List<JComboBox> packs = new ArrayList<>();
private final int CONSTRUCTION_TIME_MIN = 6;
private final int CONSTRUCTION_TIME_MAX = 30;
private boolean isRandom = false;
private boolean isRichMan = false;
private boolean automaticChange = false;
@ -315,7 +317,6 @@ public class NewTournamentDialog extends MageDialog {
spnConstructTime.setToolTipText("The time players have to build their deck.");
player1Panel.setPreferredSize(new java.awt.Dimension(400, 44));
pnlOtherPlayers.setBorder(javax.swing.BorderFactory.createEtchedBorder());
pnlOtherPlayers.setLayout(new java.awt.GridLayout(0, 1, 2, 0));
@ -549,10 +550,15 @@ public class NewTournamentDialog extends MageDialog {
tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom());
if (tournamentType.isCubeBooster()) {
tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
} else if (tournamentType.isRandom()) {
} else if (tournamentType.isRandom() || tournamentType.isRichMan()) {
this.isRandom = tournamentType.isRandom();
this.isRichMan = tournamentType.isRichMan();
tOptions.getLimitedOptions().getSetCodes().clear();
ArrayList<String> selected = randomPackSelector.getSelectedPacks();
int maxPacks = 3 * (players.size() + 1);
if (tournamentType.isRichMan()) {
maxPacks = 36;
}
if (selected.size() > maxPacks ){
StringBuilder infoString = new StringBuilder("More sets were selected than needed. ");
infoString.append(maxPacks);
@ -675,7 +681,9 @@ public class NewTournamentDialog extends MageDialog {
createPlayers((Integer) spnNumPlayers.getValue() - 1);
if (tournamentType.isLimited()) {
if (tournamentType.isRandom()){
this.isRandom = tournamentType.isRandom();
this.isRichMan = tournamentType.isRichMan();
if (this.isRandom || this.isRichMan){
createRandomPacks();
}else{
createPacks(tournamentType.getNumBoosters());
@ -719,7 +727,7 @@ public class NewTournamentDialog extends MageDialog {
this.lblPacks.setVisible(false);
this.pnlPacks.setVisible(false);
this.pnlRandomPacks.setVisible(false);
} else if (tournamentType.isRandom()){
} else if (tournamentType.isRandom() || tournamentType.isRichMan()){
this.lblDraftCube.setVisible(false);
this.cbDraftCube.setVisible(false);
this.lblPacks.setVisible(true);
@ -745,7 +753,7 @@ public class NewTournamentDialog extends MageDialog {
private void createRandomPacks() {
if (pnlRandomPacks.getComponentCount() == 0) {
if (randomPackSelector == null) {
randomPackSelector = new RandomPacksSelectorDialog();
randomPackSelector = new RandomPacksSelectorDialog(isRandom, isRichMan);
randomPackSelector.setLocationRelativeTo(this);
}
txtRandomPacks = new JTextArea();
@ -787,6 +795,7 @@ public class NewTournamentDialog extends MageDialog {
}
private void showRandomPackSelectorDialog() {
randomPackSelector.setType(isRandom, isRichMan);
randomPackSelector.showDialog();
StringBuilder packList = new StringBuilder();
for (String str : randomPackSelector.getSelectedPacks()) {
@ -945,7 +954,7 @@ public class NewTournamentDialog extends MageDialog {
if (tournamentType.isDraft()) {
numPlayers = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PLAYERS_DRAFT, "4"));
setTournamentOptions(numPlayers);
if (!tournamentType.isRandom()){
if (!(tournamentType.isRandom() || tournamentType.isRichMan())){
loadBoosterPacks(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PACKS_DRAFT, ""));
}

View file

@ -22,15 +22,30 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog {
* Creates new form RandomPacksSelectorDialog
*/
private boolean boxesCreated;
private boolean isRandomDraft;
private boolean isRichManDraft;
private String title = "";
public final static String randomDraftDescription = ("The selected packs will be randomly distributed to players. Each player may open different packs. Duplicates will be avoided.");
public RandomPacksSelectorDialog() {
public RandomPacksSelectorDialog(boolean isRandomDraft, boolean isRichManDraft) {
initComponents();
setType(isRandomDraft, isRichManDraft);
this.pnlApply.setToolTipText(randomDraftDescription);
this.pnlSelect.setToolTipText(randomDraftDescription);
boxesCreated = false;
}
public void setType(boolean isRandomDraft, boolean isRichManDraft) {
this.isRandomDraft = isRandomDraft;
this.isRichManDraft = isRichManDraft;
if (this.isRandomDraft) {
title = "Random Booster Draft Packs Selector";
} else if (this.isRichManDraft) {
title = "Rich Man Booster Draft Packs Selector";
}
setTitle(title);
}
public void showDialog() {
createCheckboxes();
pnlPacks.setVisible(true);
@ -103,7 +118,7 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog {
btnApply = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setTitle("Random Booster Draft Packs Selector");
setTitle(title);
setModal(true);
setModalExclusionType(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
setPreferredSize(new java.awt.Dimension(600, 450));
@ -138,7 +153,11 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog {
pnlApply.setLayout(new javax.swing.BoxLayout(pnlApply, javax.swing.BoxLayout.LINE_AXIS));
btnApply.setText("Apply");
btnApply.setToolTipText("At least two packs must be selected");
if (isRandomDraft) {
btnApply.setToolTipText("At least 2 packs must be selected");
} else if (isRichManDraft) {
btnApply.setToolTipText("At least 1 pack must be selected");
}
btnApply.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnApplyActionPerformed(evt);
@ -189,8 +208,10 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog {
}//GEN-LAST:event_formWindowClosing
public void doApply() {
if (getSelectedPacks().size() < 2) {
if (getSelectedPacks().size() < 2 && isRandomDraft) {
JOptionPane.showMessageDialog(this, "At least 2 sets must be selected", "Error", JOptionPane.ERROR_MESSAGE);
} else if (getSelectedPacks().size() < 1 && isRichManDraft) {
JOptionPane.showMessageDialog(this, "At least 1 set must be selected", "Error", JOptionPane.ERROR_MESSAGE);
} else {
this.setVisible(false);
}

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.view;
import java.io.Serializable;
@ -36,6 +35,7 @@ import mage.game.tournament.TournamentType;
* @author BetaSteward_at_googlemail.com
*/
public class TournamentTypeView implements Serializable {
private static final long serialVersionUID = 2L;
private final String name;
@ -47,7 +47,7 @@ public class TournamentTypeView implements Serializable {
private final boolean cubeBooster;
private final boolean elimination;
private final boolean random;
private final boolean richMan;
public TournamentTypeView(TournamentType tournamentType) {
this.name = tournamentType.getName();
@ -59,6 +59,7 @@ public class TournamentTypeView implements Serializable {
this.cubeBooster = tournamentType.isCubeBooster();
this.elimination = tournamentType.isElimination();
this.random = tournamentType.isRandom();
this.richMan = tournamentType.isRichMan();
}
@Override
@ -98,7 +99,11 @@ public class TournamentTypeView implements Serializable {
return elimination;
}
public boolean isRandom(){
public boolean isRandom() {
return random;
}
public boolean isRichMan() {
return richMan;
}
}

View file

@ -44,6 +44,8 @@ public class RichManDraftEliminationTournamentType extends TournamentType {
this.limited = true;
this.cubeBooster = false;
this.elimination = true;
this.isRandom = false;
this.isRichMan = true;
}
}

View file

@ -67,7 +67,7 @@ public class RichManBoosterDraft extends DraftImpl {
UUID nextId = table.getNext();
DraftPlayer next = players.get(nextId);
while (true) {
List<Card> nextBooster = sets.get(0).createBooster();
List<Card> nextBooster = sets.get(cardNum % sets.size()).createBooster();
next.setBooster(nextBooster);
if (nextId == startId) {
break;

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.tournament;
import java.io.Serializable;
@ -45,8 +44,10 @@ public class TournamentType implements Serializable {
protected boolean limited; // or construced
protected boolean elimination; // or Swiss
protected boolean isRandom;
protected boolean isRichMan = false; // or Rich Man Draft
protected TournamentType() {}
protected TournamentType() {
}
@Override
public String toString() {
@ -85,8 +86,12 @@ public class TournamentType implements Serializable {
return cubeBooster;
}
public boolean isRandom(){
public boolean isRandom() {
return this.isRandom;
}
public boolean isRichMan() {
return this.isRichMan;
}
}