From c7a349f65f96052897702bf308cc46dc6c45a426 Mon Sep 17 00:00:00 2001 From: brodee Date: Tue, 14 Jul 2015 22:34:58 -0700 Subject: [PATCH] random draft bug fix: packs are forced to be 15 cards; weirdness occurs if the packs are uneven sizes including the draft ending early. Random draft ui improvements: only the sets that will be used are displayed in the lobby, and the number of characters is large but still greatly reduced. the pack selector ui will prevent you from chosing fewer than 2 packs. --- .../client/dialog/NewTournamentDialog.form | 8 ++--- .../client/dialog/NewTournamentDialog.java | 33 ++++++++++++++----- .../dialog/RandomPacksSelectorDialog.form | 4 +++ .../dialog/RandomPacksSelectorDialog.java | 21 ++++++++++-- .../server/tournament/TournamentFactory.java | 7 ++++ Mage/src/mage/cards/ExpansionSet.java | 20 +++++++++++ .../mage/game/draft/RandomBoosterDraft.java | 19 +---------- 7 files changed, 77 insertions(+), 35 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.form b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.form index beb4c5799d..92ca80af08 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.form @@ -169,7 +169,7 @@ - + @@ -521,10 +521,8 @@ - - - - + + diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java index 59eacfaa88..101b3f708d 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java @@ -34,8 +34,10 @@ package mage.client.dialog; +import java.awt.Component; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.UUID; import javax.swing.ComboBoxModel; @@ -122,8 +124,8 @@ public class NewTournamentDialog extends MageDialog { cbAllowSpectators.setSelected(true); setTournamentSettingsFromPrefs(); this.setModal(true); - this.setLocation(150, 100); - } + this.setLocation(150, 100); + } this.setVisible(true); } @@ -341,7 +343,7 @@ public class NewTournamentDialog extends MageDialog { pnlRandomPacks.setBorder(javax.swing.BorderFactory.createEtchedBorder()); pnlRandomPacks.setToolTipText(""); - pnlRandomPacks.setLayout(new java.awt.GridLayout(0, 1, 2, 0)); + pnlRandomPacks.setLayout(new javax.swing.BoxLayout(pnlRandomPacks, javax.swing.BoxLayout.Y_AXIS)); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -468,7 +470,7 @@ public class NewTournamentDialog extends MageDialog { .addGroup(layout.createSequentialGroup() .addComponent(pnlPacks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pnlRandomPacks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(pnlRandomPacks, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) @@ -477,7 +479,7 @@ public class NewTournamentDialog extends MageDialog { .addComponent(lblNumRounds)) .addComponent(lblNbrPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(spnNumPlayers) - .addComponent(pnlDraftOptions, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)) + .addComponent(pnlDraftOptions, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblPlayer1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) @@ -533,7 +535,18 @@ public class NewTournamentDialog extends MageDialog { tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString()); } else if (tournamentType.isRandom()) { tOptions.getLimitedOptions().getSetCodes().clear(); - tOptions.getLimitedOptions().getSetCodes().addAll(randomPackSelector.getSelectedPacks()); + ArrayList selected = randomPackSelector.getSelectedPacks(); + int maxPacks = 3 * (players.size() + 1); + if (selected.size() > maxPacks ){ + StringBuilder infoString = new StringBuilder("More sets were selected than needed. "); + infoString.append(maxPacks); + infoString.append(" sets will be randomly chosen."); + JOptionPane.showMessageDialog(MageFrame.getDesktop(), infoString, "Information", JOptionPane.INFORMATION_MESSAGE); + Collections.shuffle(selected); + tOptions.getLimitedOptions().getSetCodes().addAll(selected.subList(0, maxPacks)); + }else{ + tOptions.getLimitedOptions().getSetCodes().addAll(selected); + } } else { for (JComboBox pack: packs) { tOptions.getLimitedOptions().getSetCodes().add(((ExpansionInfo) pack.getSelectedItem()).getCode()); @@ -717,6 +730,7 @@ public class NewTournamentDialog extends MageDialog { if (pnlRandomPacks.getComponentCount() == 0) { if (randomPackSelector == null) { randomPackSelector = new RandomPacksSelectorDialog(); + randomPackSelector.setLocationRelativeTo(this); } txtRandomPacks = new JTextArea(); txtRandomPacks.setEnabled(false); @@ -736,9 +750,10 @@ public class NewTournamentDialog extends MageDialog { } txtRandomPacks.setText(packList.toString()); } - + txtRandomPacks.setAlignmentX(Component.LEFT_ALIGNMENT); pnlRandomPacks.add(txtRandomPacks); JButton btnSelectRandomPacks = new JButton(); + btnSelectRandomPacks.setAlignmentX(Component.LEFT_ALIGNMENT); btnSelectRandomPacks.setText("Select packs to be included in the pool"); btnSelectRandomPacks.setToolTipText(RandomPacksSelectorDialog.randomDraftDescription); btnSelectRandomPacks.addActionListener(new java.awt.event.ActionListener() { @@ -749,11 +764,11 @@ public class NewTournamentDialog extends MageDialog { } }); pnlRandomPacks.add(btnSelectRandomPacks); - } + } this.pack(); this.revalidate(); this.repaint(); - } + } private void showRandomPackSelectorDialog() { randomPackSelector.showDialog(); diff --git a/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.form b/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.form index d486cab047..7644055a2a 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.form @@ -2,6 +2,7 @@
+ @@ -16,6 +17,9 @@ + + + diff --git a/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.java b/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.java index 5b9b3cc0d0..083f9a42dd 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.java @@ -8,6 +8,7 @@ package mage.client.dialog; import java.awt.Component; import java.util.ArrayList; import javax.swing.JCheckBox; +import javax.swing.JOptionPane; import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionRepository; @@ -101,11 +102,17 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog { pnlApply = new javax.swing.JPanel(); btnApply = new javax.swing.JButton(); + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); setTitle("Random Booster Draft Packs Selector"); setModal(true); setModalExclusionType(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE); setPreferredSize(new java.awt.Dimension(600, 450)); setResizable(false); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + formWindowClosing(evt); + } + }); pnlPacks.setLayout(new java.awt.GridLayout(11, 12)); @@ -174,13 +181,21 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog { }//GEN-LAST:event_btnNoneActionPerformed private void btnApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnApplyActionPerformed + this.doApply(); + }//GEN-LAST:event_btnApplyActionPerformed + + private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing + this.doApply(); + }//GEN-LAST:event_formWindowClosing + + public void doApply() { if (getSelectedPacks().size() < 2) { - // at least 2 packs must be selected. + JOptionPane.showMessageDialog(this, "At least 2 sets must be selected", "Error", JOptionPane.ERROR_MESSAGE); } else { this.setVisible(false); } - }//GEN-LAST:event_btnApplyActionPerformed - + } + private void setAllCheckBoxes(boolean value) { for (Component pack : pnlPacks.getComponents()) { JCheckBox thePack = (JCheckBox) pack; diff --git a/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java b/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java index 114331fb78..9575acc3bb 100644 --- a/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java +++ b/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java @@ -80,6 +80,13 @@ public class TournamentFactory { if (tournament.getTournamentType().isCubeBooster()) { tournament.getOptions().getLimitedOptions().setDraftCube(CubeFactory.getInstance().createDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName())); tournament.setBoosterInfo(tournament.getOptions().getLimitedOptions().getDraftCubeName()); + } else if (tournament.getTournamentType().isRandom()) { + StringBuilder rv = new StringBuilder( "Random Draft using sets: "); + for (Map.Entry entry: setInfo.entrySet()){ + rv.append(entry.getKey()); + rv.append(";"); + } + tournament.setBoosterInfo(rv.toString()); } else { StringBuilder sb = new StringBuilder(); for (Map.Entry entry:setInfo.entrySet()) { diff --git a/Mage/src/mage/cards/ExpansionSet.java b/Mage/src/mage/cards/ExpansionSet.java index 5a808a456c..17aee8cbb9 100644 --- a/Mage/src/mage/cards/ExpansionSet.java +++ b/Mage/src/mage/cards/ExpansionSet.java @@ -112,6 +112,26 @@ public abstract class ExpansionSet implements Serializable { return name; } + public List create15CardBooster() { + // Forces 15 card booster packs. + // if the packs are too small, it adds commons to fill it out. + // if the packs are too big, it removes the first cards. + // since it adds lands then commons before uncommons + // and rares this should be the least disruptive. + + List theBooster = this.createBooster(); + List commons = getCardsByRarity(Rarity.COMMON); + while (15 > theBooster.size()) { + addToBooster(theBooster, commons); + } + + while (theBooster.size() > 15) { + theBooster.remove(0); + } + + return theBooster; + } + public List createBooster() { List booster = new ArrayList<>(); if (!hasBoosters) { diff --git a/Mage/src/mage/game/draft/RandomBoosterDraft.java b/Mage/src/mage/game/draft/RandomBoosterDraft.java index ebd0a8a9ef..cc7604b447 100644 --- a/Mage/src/mage/game/draft/RandomBoosterDraft.java +++ b/Mage/src/mage/game/draft/RandomBoosterDraft.java @@ -50,28 +50,11 @@ public class RandomBoosterDraft extends BoosterDraft { resetBoosters(); } - @Override - public void start() { - while (!isAbort() && boosterNum < numberBoosters) { - openBooster(); - while (!isAbort() && pickCards()) { - if (boosterNum % 2 == 1) { - passLeft(); - } else { - passRight(); - } - fireUpdatePlayersEvent(); - } - } - resetBufferedCards(); - this.fireEndDraftEvent(); - } - @Override protected void openBooster() { if (boosterNum < numberBoosters) { for (DraftPlayer player: players.values()) { - player.setBooster(getNextBooster().createBooster()); + player.setBooster(getNextBooster().create15CardBooster()); } } boosterNum++;