From 5ee4b5193e25c044aad6f3344b19a63217ae3017 Mon Sep 17 00:00:00 2001 From: spjspj Date: Sun, 15 May 2016 18:50:59 +1000 Subject: [PATCH 1/2] spjspj - Modify Rich Man draft to be random --- .../mage/tournament/RichManDraftEliminationTournamentType.java | 1 + Mage/src/main/java/mage/game/draft/RichManBoosterDraft.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournamentType.java b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournamentType.java index 8a2480a388..e2136d8a1a 100644 --- a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournamentType.java +++ b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournamentType.java @@ -44,6 +44,7 @@ public class RichManDraftEliminationTournamentType extends TournamentType { this.limited = true; this.cubeBooster = false; this.elimination = true; + this.isRandom = true; } } diff --git a/Mage/src/main/java/mage/game/draft/RichManBoosterDraft.java b/Mage/src/main/java/mage/game/draft/RichManBoosterDraft.java index 4e4d4c7494..52dce9f9c3 100644 --- a/Mage/src/main/java/mage/game/draft/RichManBoosterDraft.java +++ b/Mage/src/main/java/mage/game/draft/RichManBoosterDraft.java @@ -67,7 +67,7 @@ public class RichManBoosterDraft extends DraftImpl { UUID nextId = table.getNext(); DraftPlayer next = players.get(nextId); while (true) { - List nextBooster = sets.get(0).createBooster(); + List nextBooster = sets.get(cardNum % sets.size()).createBooster(); next.setBooster(nextBooster); if (nextId == startId) { break; From f9e363fb30a41b647cbb8f86456a4c80fc4cbd4d Mon Sep 17 00:00:00 2001 From: spjspj Date: Sun, 15 May 2016 23:52:13 +1000 Subject: [PATCH 2/2] spjspj - Update Rich Man draft to allow Random packs --- .../client/dialog/NewTournamentDialog.java | 37 ++++++++++++------- .../dialog/RandomPacksSelectorDialog.java | 37 +++++++++++++++---- .../src/mage/view/TournamentTypeView.java | 13 +++++-- .../RichManDraftEliminationTournament.java | 2 +- ...RichManDraftEliminationTournamentType.java | 5 ++- .../mage/game/draft/RichManBoosterDraft.java | 2 +- .../mage/game/tournament/TournamentType.java | 17 ++++++--- 7 files changed, 77 insertions(+), 36 deletions(-) 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 f9c3b86f2e..c89e580f93 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java @@ -86,6 +86,8 @@ public class NewTournamentDialog extends MageDialog { private final List 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 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 -} +} 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 083f9a42dd..22deb50a89 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.java @@ -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 getSelectedPacks() { ArrayList 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 -} +} diff --git a/Mage.Common/src/mage/view/TournamentTypeView.java b/Mage.Common/src/mage/view/TournamentTypeView.java index 8209b585d9..ed15231783 100644 --- a/Mage.Common/src/mage/view/TournamentTypeView.java +++ b/Mage.Common/src/mage/view/TournamentTypeView.java @@ -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; + } +} diff --git a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournament.java b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournament.java index 72e30e1e90..77bc42cb43 100644 --- a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournament.java +++ b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournament.java @@ -86,4 +86,4 @@ public class RichManDraftEliminationTournament extends TournamentSingleEliminati break; } } -} +} diff --git a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournamentType.java b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournamentType.java index e2136d8a1a..a131f5dc02 100644 --- a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournamentType.java +++ b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/RichManDraftEliminationTournamentType.java @@ -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; } -} +} diff --git a/Mage/src/main/java/mage/game/draft/RichManBoosterDraft.java b/Mage/src/main/java/mage/game/draft/RichManBoosterDraft.java index 52dce9f9c3..2cf844e797 100644 --- a/Mage/src/main/java/mage/game/draft/RichManBoosterDraft.java +++ b/Mage/src/main/java/mage/game/draft/RichManBoosterDraft.java @@ -111,4 +111,4 @@ public class RichManBoosterDraft extends DraftImpl { int time = richManTimes[cardNum - 1] * timing.getFactor(); playerQueryEventSource.pickCard(playerId, "Pick card", player.getBooster(), time); } -} +} diff --git a/Mage/src/main/java/mage/game/tournament/TournamentType.java b/Mage/src/main/java/mage/game/tournament/TournamentType.java index d572743520..7da56cf1d7 100644 --- a/Mage/src/main/java/mage/game/tournament/TournamentType.java +++ b/Mage/src/main/java/mage/game/tournament/TournamentType.java @@ -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; + } + +}