spjspj - Update Rich Man draft to allow Random packs

This commit is contained in:
spjspj 2016-05-15 23:52:13 +10:00
parent 5ee4b5193e
commit f9e363fb30
7 changed files with 77 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);
@ -580,7 +586,7 @@ public class NewTournamentDialog extends MageDialog {
tOptions.getMatchOptions().setGameType(((GameTypeView) this.cbGameType.getSelectedItem()).getName());
tOptions.getMatchOptions().setLimited(false);
}
tOptions.getMatchOptions().setMatchTimeLimit((MatchTimeLimit) this.cbTimeLimit.getSelectedItem());
tOptions.getMatchOptions().setSkillLevel((SkillLevel) this.cbSkillLevel.getSelectedItem());
tOptions.getMatchOptions().setWinsNeeded((Integer)this.spnNumWins.getValue());
@ -598,7 +604,7 @@ public class NewTournamentDialog extends MageDialog {
if (session.joinTournamentTable(
roomId,
table.getTableId(),
this.player1Panel.getPlayerName(),
this.player1Panel.getPlayerName(),
"Human", 1,
DeckImporterUtil.importDeck(this.player1Panel.getDeckFile()),
tOptions.getPassword())) {
@ -673,9 +679,11 @@ public class NewTournamentDialog extends MageDialog {
this.spnNumPlayers.setModel(new SpinnerNumberModel(numPlayers, tournamentType.getMinPlayers(), tournamentType.getMaxPlayers(), 1));
this.spnNumPlayers.setEnabled(tournamentType.getMinPlayers() != tournamentType.getMaxPlayers());
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());
@ -695,8 +703,8 @@ public class NewTournamentDialog extends MageDialog {
}
/**
* Sets elements of the panel to visible or not visible
*
* @param tournamentType
*
* @param tournamentType
*/
private void activatePanelElements(TournamentTypeView tournamentType) {
this.pnlDraftOptions.setVisible(tournamentType.isDraft());
@ -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()) {
@ -838,7 +847,7 @@ public class NewTournamentDialog extends MageDialog {
}
private void createPlayers(int numPlayers) {
// add/remove player panels
// add/remove player panels
if (numPlayers > players.size()) {
while (players.size() != numPlayers) {
TournamentPlayerPanel playerPanel = new TournamentPlayerPanel();
@ -915,7 +924,7 @@ public class NewTournamentDialog extends MageDialog {
this.cbSkillLevel.setSelectedItem(skillLevel);
break;
}
}
}
int constructionTime = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_CONSTR_TIME, "600")) / 60;
if (constructionTime < CONSTRUCTION_TIME_MIN || constructionTime > CONSTRUCTION_TIME_MAX) {
constructionTime = CONSTRUCTION_TIME_MIN;
@ -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, ""));
}
@ -1086,4 +1095,4 @@ public class NewTournamentDialog extends MageDialog {
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration//GEN-END:variables
}
}

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);
@ -56,7 +71,7 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog {
}
}
}
public ArrayList<String> getSelectedPacks() {
ArrayList<String> returnVal = new ArrayList<>();
for (Component pack: pnlPacks.getComponents()){
@ -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,13 +208,15 @@ 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);
}
}
private void setAllCheckBoxes(boolean value) {
for (Component pack : pnlPacks.getComponents()) {
JCheckBox thePack = (JCheckBox) pack;
@ -211,4 +232,4 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog {
private java.awt.Panel pnlPacks;
private javax.swing.JPanel pnlSelect;
// End of variables declaration//GEN-END:variables
}
}

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

@ -86,4 +86,4 @@ public class RichManDraftEliminationTournament extends TournamentSingleEliminati
break;
}
}
}
}

View file

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

View file

@ -111,4 +111,4 @@ public class RichManBoosterDraft extends DraftImpl {
int time = richManTimes[cardNum - 1] * timing.getFactor();
playerQueryEventSource.pickCard(playerId, "Pick card", player.getBooster(), time);
}
}
}

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() {
@ -84,9 +85,13 @@ public class TournamentType implements Serializable {
public boolean isCubeBooster() {
return cubeBooster;
}
public boolean isRandom(){
public boolean isRandom() {
return this.isRandom;
}
}
public boolean isRichMan() {
return this.isRichMan;
}
}