mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
added tournaments - drafts are now a variant of tournament
This commit is contained in:
parent
78e60ce457
commit
ffc7b5bfd8
88 changed files with 3768 additions and 311 deletions
|
@ -75,6 +75,7 @@ import java.util.prefs.Preferences;
|
|||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import mage.client.draft.DraftPane;
|
||||
import mage.client.tournament.TournamentPane;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -155,6 +156,14 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
tournamentPane = new TournamentPane();
|
||||
desktopPane.add(tournamentPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
|
||||
try {
|
||||
tournamentPane.setMaximum(true);
|
||||
} catch (java.beans.PropertyVetoException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
addTooltipContainer();
|
||||
setBackground();
|
||||
addMageLabel();
|
||||
|
@ -407,6 +416,12 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
this.draftPane.showDraft(draftId);
|
||||
}
|
||||
|
||||
public void showTournament(UUID tournamentId) {
|
||||
this.tournamentPane.setVisible(true);
|
||||
this.tournamentPane.toFront();
|
||||
this.tournamentPane.showTournament(tournamentId);
|
||||
}
|
||||
|
||||
public static boolean connect(String userName, String serverName, int port) {
|
||||
return session.connect(userName, serverName, port);
|
||||
}
|
||||
|
@ -746,6 +761,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
private static final long serialVersionUID = -9104885239063142218L;
|
||||
private ImagePanel backgroundPane;
|
||||
private DraftPane draftPane;
|
||||
private TournamentPane tournamentPane;
|
||||
|
||||
public void setStatusText(String status) {
|
||||
this.lblStatus.setText(status);
|
||||
|
|
|
@ -1,6 +1,29 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -14,11 +37,9 @@ package mage.client.cards;
|
|||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.cards.CardDimensions;
|
||||
import mage.cards.MageCard;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.Config;
|
||||
import mage.view.CardView;
|
||||
|
@ -97,13 +118,6 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
|
|||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
/*if (e.getClickCount() == 2 && !e.isConsumed()) {
|
||||
e.consume();
|
||||
Object obj = e.getSource();
|
||||
if (obj instanceof MageCard) {
|
||||
this.cardEventSource.doubleClick(((MageCard)obj).getOriginal().getId(), "double-click");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<?xml version="1.1" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
|
|
|
@ -35,13 +35,9 @@
|
|||
package mage.client.dialog;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JOptionPane;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.remote.Session;
|
||||
import mage.client.util.Config;
|
||||
import mage.util.Logging;
|
||||
|
||||
|
@ -212,9 +208,6 @@ public class ConnectDialog extends MageDialog {
|
|||
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
|
||||
this.setVisible(false);
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(rootPane, "Unable to connect to server");
|
||||
}
|
||||
}
|
||||
finally {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
|
|
|
@ -0,0 +1,210 @@
|
|||
<?xml version="1.1" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="title" type="java.lang.String" value="New Tournament"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="pnlPacks" alignment="1" pref="525" max="32767" attributes="0"/>
|
||||
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="btnOk" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jLabel1" min="-2" pref="113" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="cbTournamentType" pref="408" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="spnNumPlayers" min="-2" pref="45" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="cbTournamentType" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
|
||||
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
|
||||
<Component id="pnlPacks" pref="47" max="32767" attributes="0"/>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="spnNumPlayers" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
|
||||
<Component id="jPanel1" max="32767" attributes="0"/>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnOk" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Tournament Type:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="cbTournamentType">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="4">
|
||||
<StringItem index="0" value="Item 1"/>
|
||||
<StringItem index="1" value="Item 2"/>
|
||||
<StringItem index="2" value="Item 3"/>
|
||||
<StringItem index="3" value="Item 4"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbTournamentTypeActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JSpinner" name="spnNumPlayers">
|
||||
<Events>
|
||||
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="spnNumPlayersStateChanged"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel2">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Players:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnOk">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="OK"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOkActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnCancel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Cancel"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCancelActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="pnlPacks">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
|
||||
<Property name="columns" type="int" value="1"/>
|
||||
<Property name="horizontalGap" type="int" value="2"/>
|
||||
<Property name="rows" type="int" value="0"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="jPanel1">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="pnlOtherPlayers" alignment="0" pref="525" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="445" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="txtPlayer1Name" pref="490" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtPlayer1Name" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="pnlOtherPlayers" pref="58" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="jLabel3">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="11" style="1"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Player 1 (You)"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel4">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Name:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtPlayer1Name">
|
||||
<Properties>
|
||||
<Property name="editable" type="boolean" value="false"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="pnlOtherPlayers">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
|
||||
<Property name="columns" type="int" value="1"/>
|
||||
<Property name="horizontalGap" type="int" value="2"/>
|
||||
<Property name="rows" type="int" value="0"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JLabel" name="jLabel5">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="11" style="1"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Packs"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
|
@ -0,0 +1,359 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
/*
|
||||
* NewTournamentDialog.java
|
||||
*
|
||||
* Created on Jan 28, 2011, 12:15:56 PM
|
||||
*/
|
||||
|
||||
package mage.client.dialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import mage.Constants.MultiplayerAttackOption;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.remote.Session;
|
||||
import mage.client.table.TournamentPlayerPanel;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.sets.Sets;
|
||||
import mage.util.Logging;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentTypeView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class NewTournamentDialog extends MageDialog {
|
||||
|
||||
private final static Logger logger = Logging.getLogger(NewTournamentDialog.class.getName());
|
||||
|
||||
private TableView table;
|
||||
private UUID playerId;
|
||||
private UUID roomId;
|
||||
private Session session;
|
||||
private List<TournamentPlayerPanel> players = new ArrayList<TournamentPlayerPanel>();
|
||||
private List<JComboBox> packs = new ArrayList<JComboBox>();
|
||||
|
||||
/** Creates new form NewTournamentDialog */
|
||||
public NewTournamentDialog() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public void showDialog(UUID roomId) {
|
||||
this.roomId = roomId;
|
||||
session = MageFrame.getSession();
|
||||
this.txtPlayer1Name.setText(session.getUserName());
|
||||
cbTournamentType.setModel(new DefaultComboBoxModel(session.getTournamentTypes().toArray()));
|
||||
this.setModal(true);
|
||||
setTournamentOptions();
|
||||
this.setLocation(150, 100);
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
cbTournamentType = new javax.swing.JComboBox();
|
||||
spnNumPlayers = new javax.swing.JSpinner();
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
btnOk = new javax.swing.JButton();
|
||||
btnCancel = new javax.swing.JButton();
|
||||
pnlPacks = new javax.swing.JPanel();
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
jLabel3 = new javax.swing.JLabel();
|
||||
jLabel4 = new javax.swing.JLabel();
|
||||
txtPlayer1Name = new javax.swing.JTextField();
|
||||
pnlOtherPlayers = new javax.swing.JPanel();
|
||||
jLabel5 = new javax.swing.JLabel();
|
||||
|
||||
setTitle("New Tournament");
|
||||
|
||||
jLabel1.setText("Tournament Type:");
|
||||
|
||||
cbTournamentType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
|
||||
cbTournamentType.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
cbTournamentTypeActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
spnNumPlayers.addChangeListener(new javax.swing.event.ChangeListener() {
|
||||
public void stateChanged(javax.swing.event.ChangeEvent evt) {
|
||||
spnNumPlayersStateChanged(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabel2.setText("Players:");
|
||||
|
||||
btnOk.setText("OK");
|
||||
btnOk.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnOkActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.setText("Cancel");
|
||||
btnCancel.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnCancelActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
pnlPacks.setLayout(new java.awt.GridLayout(0, 1, 2, 0));
|
||||
|
||||
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
|
||||
jLabel3.setText("Player 1 (You)");
|
||||
|
||||
jLabel4.setText("Name:");
|
||||
|
||||
txtPlayer1Name.setEditable(false);
|
||||
|
||||
pnlOtherPlayers.setLayout(new java.awt.GridLayout(0, 1, 2, 0));
|
||||
|
||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||
jPanel1.setLayout(jPanel1Layout);
|
||||
jPanel1Layout.setHorizontalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
|
||||
.addComponent(jLabel3)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 445, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
|
||||
.addComponent(jLabel4)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(txtPlayer1Name, javax.swing.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE)))
|
||||
.addContainerGap())
|
||||
);
|
||||
jPanel1Layout.setVerticalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addComponent(jLabel3)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel4)
|
||||
.addComponent(txtPlayer1Name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
|
||||
jLabel5.setText("Packs");
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(pnlPacks, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(btnOk)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnCancel))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(cbTournamentType, 0, 408, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jLabel2)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(jLabel5))
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel1)
|
||||
.addComponent(cbTournamentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(3, 3, 3)
|
||||
.addComponent(jLabel5)
|
||||
.addGap(1, 1, 1)
|
||||
.addComponent(pnlPacks, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jLabel2))
|
||||
.addGap(19, 19, 19)
|
||||
.addComponent(jPanel1, 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.BASELINE)
|
||||
.addComponent(btnCancel)
|
||||
.addComponent(btnOk))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void cbTournamentTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTournamentTypeActionPerformed
|
||||
setTournamentOptions();
|
||||
}//GEN-LAST:event_cbTournamentTypeActionPerformed
|
||||
|
||||
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
|
||||
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
|
||||
TournamentOptions tOptions = new TournamentOptions(tournamentType.getName());
|
||||
tOptions.setTournamentType(tournamentType.getName());
|
||||
tOptions.getPlayerTypes().add("Human");
|
||||
for (TournamentPlayerPanel player: players) {
|
||||
tOptions.getPlayerTypes().add(player.getPlayerType());
|
||||
}
|
||||
if (tournamentType.isDraft()) {
|
||||
tOptions.getDraftOptions().setDraftType("");
|
||||
tOptions.getDraftOptions().setTiming(DraftOptions.TimingOption.REGULAR);
|
||||
for (JComboBox pack: packs) {
|
||||
tOptions.getDraftOptions().getSets().add((ExpansionSet) pack.getSelectedItem());
|
||||
}
|
||||
}
|
||||
tOptions.getMatchOptions().setDeckType("Limited");
|
||||
tOptions.getMatchOptions().setWinsNeeded(2);
|
||||
tOptions.getMatchOptions().setAttackOption(MultiplayerAttackOption.LEFT);
|
||||
tOptions.getMatchOptions().setRange(RangeOfInfluence.ALL);
|
||||
table = session.createTournamentTable(roomId, tOptions);
|
||||
if (session.joinTournamentTable(roomId, table.getTableId(), this.txtPlayer1Name.getText())) {
|
||||
for (TournamentPlayerPanel player: players) {
|
||||
if (!player.getPlayerType().equals("Human")) {
|
||||
if (!player.joinTournamentTable(roomId, table.getTableId())) {
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
session.removeTable(roomId, table.getTableId());
|
||||
table = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setVisible(false);
|
||||
return;
|
||||
}
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
session.removeTable(roomId, table.getTableId());
|
||||
table = null;
|
||||
}//GEN-LAST:event_btnOkActionPerformed
|
||||
|
||||
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
|
||||
this.table = null;
|
||||
this.playerId = null;
|
||||
this.setVisible(false);
|
||||
}//GEN-LAST:event_btnCancelActionPerformed
|
||||
|
||||
private void spnNumPlayersStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spnNumPlayersStateChanged
|
||||
int numPlayers = (Integer)this.spnNumPlayers.getValue() - 1;
|
||||
createPlayers(numPlayers);
|
||||
}//GEN-LAST:event_spnNumPlayersStateChanged
|
||||
|
||||
private void setTournamentOptions() {
|
||||
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
|
||||
this.spnNumPlayers.setModel(new SpinnerNumberModel(tournamentType.getMinPlayers(), tournamentType.getMinPlayers(), tournamentType.getMaxPlayers(), 1));
|
||||
this.spnNumPlayers.setEnabled(tournamentType.getMinPlayers() != tournamentType.getMaxPlayers());
|
||||
createPlayers(tournamentType.getMinPlayers() - 1);
|
||||
createPacks(tournamentType.getNumBoosters());
|
||||
}
|
||||
|
||||
private void createPacks(int numPacks) {
|
||||
while (packs.size() < numPacks) {
|
||||
JComboBox pack = new JComboBox();
|
||||
pack.setModel(new DefaultComboBoxModel(Sets.getInstance().values().toArray()));
|
||||
pnlPacks.add(pack);
|
||||
packs.add(pack);
|
||||
}
|
||||
this.pack();
|
||||
this.revalidate();
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
private void createPlayers(int numPlayers) {
|
||||
if (numPlayers > players.size()) {
|
||||
while (players.size() != numPlayers) {
|
||||
TournamentPlayerPanel playerPanel = new TournamentPlayerPanel();
|
||||
playerPanel.init(players.size() + 2);
|
||||
players.add(playerPanel);
|
||||
}
|
||||
}
|
||||
else if (numPlayers < players.size()) {
|
||||
while (players.size() != numPlayers) {
|
||||
players.remove(players.size() - 1);
|
||||
}
|
||||
}
|
||||
drawPlayers();
|
||||
}
|
||||
|
||||
private void drawPlayers() {
|
||||
this.pnlOtherPlayers.removeAll();
|
||||
for (TournamentPlayerPanel panel: players) {
|
||||
this.pnlOtherPlayers.add(panel);
|
||||
}
|
||||
this.pack();
|
||||
this.revalidate();
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public TableView getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JButton btnOk;
|
||||
private javax.swing.JComboBox cbTournamentType;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JLabel jLabel2;
|
||||
private javax.swing.JLabel jLabel3;
|
||||
private javax.swing.JLabel jLabel4;
|
||||
private javax.swing.JLabel jLabel5;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel pnlOtherPlayers;
|
||||
private javax.swing.JPanel pnlPacks;
|
||||
private javax.swing.JSpinner spnNumPlayers;
|
||||
private javax.swing.JTextField txtPlayer1Name;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<?xml version="1.1" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.6" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
|
||||
<Properties>
|
||||
|
@ -39,7 +39,7 @@
|
|||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="jSplitPane1" pref="247" max="32767" attributes="0"/>
|
||||
<Component id="jSplitPane1" pref="251" max="32767" attributes="0"/>
|
||||
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="btnMoveDown" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
|
|
|
@ -60,6 +60,7 @@ public class TableWaitingDialog extends MageDialog implements Observer {
|
|||
|
||||
private UUID tableId;
|
||||
private UUID roomId;
|
||||
private boolean isTournament;
|
||||
private Session session;
|
||||
private TableWaitModel tableWaitModel;
|
||||
private SeatsWatchdog seatsWatchdog = new SeatsWatchdog();
|
||||
|
@ -105,9 +106,10 @@ public class TableWaitingDialog extends MageDialog implements Observer {
|
|||
}
|
||||
}
|
||||
|
||||
public void showDialog(UUID roomId, UUID tableId) {
|
||||
public void showDialog(UUID roomId, UUID tableId, boolean isTournament) {
|
||||
this.roomId = roomId;
|
||||
this.tableId = tableId;
|
||||
this.isTournament = isTournament;
|
||||
session = MageFrame.getSession();
|
||||
if (session.isTableOwner(roomId, tableId)) {
|
||||
this.btnStart.setVisible(true);
|
||||
|
@ -235,7 +237,10 @@ public class TableWaitingDialog extends MageDialog implements Observer {
|
|||
|
||||
private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed
|
||||
closeDialog();
|
||||
session.startGame(roomId, tableId);
|
||||
if (!isTournament)
|
||||
session.startGame(roomId, tableId);
|
||||
else
|
||||
session.startTournament(roomId, tableId);
|
||||
}//GEN-LAST:event_btnStartActionPerformed
|
||||
|
||||
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
|
||||
|
|
|
@ -86,6 +86,10 @@ public class Client implements CallbackClient {
|
|||
GameManager.getInstance().setCurrentPlayerUUID(message.getPlayerId());
|
||||
gameStarted(message.getGameId(), message.getPlayerId());
|
||||
}
|
||||
else if(callback.getMethod().equals("startTournament")) {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
tournamentStarted(message.getGameId(), message.getPlayerId());
|
||||
}
|
||||
else if(callback.getMethod().equals("startDraft")) {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
draftStarted(message.getGameId(), message.getPlayerId());
|
||||
|
@ -171,6 +175,9 @@ public class Client implements CallbackClient {
|
|||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
construct(message.getDeck(), message.getTableId());
|
||||
}
|
||||
else if (callback.getMethod().equals("draftOver")) {
|
||||
session.getDraft().hideDraft();
|
||||
}
|
||||
else if (callback.getMethod().equals("draftPick")) {
|
||||
DraftClientMessage message = (DraftClientMessage) callback.getData();
|
||||
session.getDraft().loadBooster(message.getDraftPickView());
|
||||
|
@ -189,6 +196,9 @@ public class Client implements CallbackClient {
|
|||
else if (callback.getMethod().equals("draftInit")) {
|
||||
session.ack("draftInit");
|
||||
}
|
||||
else if (callback.getMethod().equals("tournamentInit")) {
|
||||
session.ack("tournamentInit");
|
||||
}
|
||||
messageId = callback.getMessageId();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
@ -202,7 +212,7 @@ public class Client implements CallbackClient {
|
|||
return clientId;
|
||||
}
|
||||
|
||||
protected void gameStarted(UUID gameId, UUID playerId) {
|
||||
protected void gameStarted(final UUID gameId, final UUID playerId) {
|
||||
try {
|
||||
frame.showGame(gameId, playerId);
|
||||
logger.info("Game " + gameId + " started for player " + playerId);
|
||||
|
@ -210,7 +220,7 @@ public class Client implements CallbackClient {
|
|||
catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
||||
|
||||
if (Plugins.getInstance().isCounterPluginLoaded()) {
|
||||
Plugins.getInstance().addGamesPlayed();
|
||||
}
|
||||
|
@ -226,6 +236,16 @@ public class Client implements CallbackClient {
|
|||
}
|
||||
}
|
||||
|
||||
protected void tournamentStarted(UUID tournamentId, UUID playerId) {
|
||||
try {
|
||||
frame.showTournament(tournamentId);
|
||||
logger.info("Tournament " + tournamentId + " started for player " + playerId);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected void watchGame(UUID gameId) {
|
||||
try {
|
||||
frame.watchGame(gameId);
|
||||
|
|
|
@ -46,17 +46,20 @@ import mage.client.chat.ChatPanel;
|
|||
import mage.client.components.MageUI;
|
||||
import mage.client.draft.DraftPanel;
|
||||
import mage.client.game.GamePanel;
|
||||
import mage.client.tournament.TournamentPanel;
|
||||
import mage.client.util.Config;
|
||||
import mage.game.GameException;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.interfaces.MageException;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.Server;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.interfaces.callback.CallbackClientDaemon;
|
||||
import mage.util.Logging;
|
||||
import mage.view.GameTypeView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentTypeView;
|
||||
import mage.view.TournamentView;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -75,6 +78,7 @@ public class Session {
|
|||
private Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
|
||||
private GamePanel game;
|
||||
private DraftPanel draft;
|
||||
private TournamentPanel tournament;
|
||||
private CallbackClientDaemon callbackDaemon;
|
||||
private MageUI ui = new MageUI();
|
||||
|
||||
|
@ -101,6 +105,7 @@ public class Session {
|
|||
return true;
|
||||
} catch (MageException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
JOptionPane.showMessageDialog(frame, "Unable to connect to server. " + ex.getMessage());
|
||||
} catch (RemoteException ex) {
|
||||
logger.log(Level.SEVERE, "Unable to connect to server - ", ex);
|
||||
} catch (NotBoundException ex) {
|
||||
|
@ -156,6 +161,10 @@ public class Session {
|
|||
return serverState.getDeckTypes();
|
||||
}
|
||||
|
||||
public List<TournamentTypeView> getTournamentTypes() {
|
||||
return serverState.getTournamentTypes();
|
||||
}
|
||||
|
||||
public boolean isTestMode() {
|
||||
return serverState.isTestMode();
|
||||
}
|
||||
|
@ -180,6 +189,10 @@ public class Session {
|
|||
draft = draftPanel;
|
||||
}
|
||||
|
||||
public void setTournament(TournamentPanel tournament) {
|
||||
this.tournament = tournament;
|
||||
}
|
||||
|
||||
public UUID getMainRoomId() {
|
||||
try {
|
||||
return server.getMainRoomId();
|
||||
|
@ -272,9 +285,9 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean joinDraftTable(UUID roomId, UUID tableId, String playerName) {
|
||||
public boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName) {
|
||||
try {
|
||||
return server.joinDraftTable(sessionId, roomId, tableId, playerName);
|
||||
return server.joinTournamentTable(sessionId, roomId, tableId, playerName);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
|
@ -297,6 +310,29 @@ public class Session {
|
|||
}
|
||||
}
|
||||
|
||||
public TournamentView getTournament(UUID tournamentId) throws MageRemoteException {
|
||||
try {
|
||||
return server.getTournament(tournamentId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
throw new MageRemoteException();
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
throw new MageRemoteException();
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getTournamentChatId(UUID tournamentId) {
|
||||
try {
|
||||
return server.getTournamentChatId(tournamentId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean sendPlayerUUID(UUID gameId, UUID data) {
|
||||
try {
|
||||
server.sendPlayerUUID(gameId, sessionId, data);
|
||||
|
@ -419,6 +455,18 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean joinTournament(UUID tournamentId) {
|
||||
try {
|
||||
server.joinTournament(tournamentId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean watchGame(UUID gameId) {
|
||||
try {
|
||||
server.watchGame(gameId, sessionId);
|
||||
|
@ -454,9 +502,9 @@ public class Session {
|
|||
return null;
|
||||
}
|
||||
|
||||
public TableView createDraftTable(UUID roomId, DraftOptions draftOptions) {
|
||||
public TableView createTournamentTable(UUID roomId, TournamentOptions tournamentOptions) {
|
||||
try {
|
||||
return server.createDraftTable(sessionId, roomId, draftOptions);
|
||||
return server.createTournamentTable(sessionId, roomId, tournamentOptions);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
|
@ -524,9 +572,9 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean startDraft(UUID roomId, UUID tableId) {
|
||||
public boolean startTournament(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
server.startDraft(sessionId, roomId, tableId);
|
||||
server.startTournament(sessionId, roomId, tableId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
|
@ -650,4 +698,5 @@ public class Session {
|
|||
public MageUI getUI() {
|
||||
return ui;
|
||||
}
|
||||
|
||||
}
|
|
@ -34,30 +34,15 @@
|
|||
|
||||
package mage.client.table;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.deck.generator.DeckGenerator;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.gui.ColorsChooser;
|
||||
import mage.sets.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -119,8 +104,8 @@ public class NewPlayerPanel extends javax.swing.JPanel {
|
|||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
// </editor-fold>//GEN-END:initComponents
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">
|
||||
// </editor-fold>
|
||||
private void initComponents() {
|
||||
|
||||
lblPlayerName = new javax.swing.JLabel();
|
||||
|
|
|
@ -40,10 +40,10 @@
|
|||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnNewTable" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
|
||||
<Component id="btnNewDraft" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnNewTournament" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnQuickStart" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="450" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="416" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
@ -54,7 +54,7 @@
|
|||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="btnNewTable" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnQuickStart" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnNewDraft" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnNewTournament" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="16" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
|
@ -78,12 +78,12 @@
|
|||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnQuickStartActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnNewDraft">
|
||||
<Component class="javax.swing.JButton" name="btnNewTournament">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="New Draft"/>
|
||||
<Property name="text" type="java.lang.String" value="New Tournament"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnNewDraftActionPerformed"/>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnNewTournamentActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
|
|
|
@ -58,6 +58,9 @@ import java.awt.event.ActionListener;
|
|||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.client.dialog.NewTournamentDialog;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -73,6 +76,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
private TablesWatchdog tablesWatchdog = new TablesWatchdog();
|
||||
private JoinTableDialog joinTableDialog;
|
||||
private NewTableDialog newTableDialog;
|
||||
private NewTournamentDialog newTournamentDialog;
|
||||
private TableWaitingDialog tableWaitingDialog;
|
||||
private Session session;
|
||||
|
||||
|
@ -99,7 +103,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
|
||||
joinTableDialog.showDialog(roomId, tableId);
|
||||
if (joinTableDialog.isJoined())
|
||||
tableWaitingDialog.showDialog(roomId, tableId);
|
||||
tableWaitingDialog.showDialog(roomId, tableId, false);
|
||||
} else if (state.equals("Watch")) {
|
||||
logger.info("Watching table " + tableId);
|
||||
if (!session.watchTable(roomId, tableId))
|
||||
|
@ -152,6 +156,10 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
newTableDialog = new NewTableDialog();
|
||||
MageFrame.getDesktop().add(newTableDialog);
|
||||
}
|
||||
if (newTournamentDialog == null) {
|
||||
newTournamentDialog = new NewTournamentDialog();
|
||||
MageFrame.getDesktop().add(newTournamentDialog);
|
||||
}
|
||||
if (joinTableDialog == null) {
|
||||
joinTableDialog = new JoinTableDialog();
|
||||
MageFrame.getDesktop().add(joinTableDialog);
|
||||
|
@ -201,7 +209,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
jPanel1 = new javax.swing.JPanel();
|
||||
btnNewTable = new javax.swing.JButton();
|
||||
btnQuickStart = new javax.swing.JButton();
|
||||
btnNewDraft = new javax.swing.JButton();
|
||||
btnNewTournament = new javax.swing.JButton();
|
||||
jSplitPane1 = new javax.swing.JSplitPane();
|
||||
chatPanel = new mage.client.chat.ChatPanel();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
|
@ -221,14 +229,12 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
}
|
||||
});
|
||||
|
||||
btnNewDraft.setText("New Draft");
|
||||
btnNewDraft.addActionListener(new java.awt.event.ActionListener() {
|
||||
btnNewTournament.setText("New Tournament");
|
||||
btnNewTournament.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnNewDraftActionPerformed(evt);
|
||||
btnNewTournamentActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
//FIXME: removed on released 0.6 version
|
||||
btnNewDraft.setVisible(false);
|
||||
|
||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||
jPanel1.setLayout(jPanel1Layout);
|
||||
|
@ -238,10 +244,10 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
.addContainerGap()
|
||||
.addComponent(btnNewTable)
|
||||
.addGap(6, 6, 6)
|
||||
.addComponent(btnNewDraft)
|
||||
.addComponent(btnNewTournament)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnQuickStart)
|
||||
.addContainerGap(450, Short.MAX_VALUE))
|
||||
.addContainerGap(416, Short.MAX_VALUE))
|
||||
);
|
||||
jPanel1Layout.setVerticalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
|
@ -250,7 +256,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(btnNewTable)
|
||||
.addComponent(btnQuickStart)
|
||||
.addComponent(btnNewDraft))
|
||||
.addComponent(btnNewTournament))
|
||||
.addContainerGap(16, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
|
@ -284,7 +290,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
private void btnNewTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewTableActionPerformed
|
||||
newTableDialog.showDialog(roomId);
|
||||
if (newTableDialog.getTable() != null) {
|
||||
tableWaitingDialog.showDialog(roomId, newTableDialog.getTable().getTableId());
|
||||
tableWaitingDialog.showDialog(roomId, newTableDialog.getTable().getTableId(), false);
|
||||
}
|
||||
}//GEN-LAST:event_btnNewTableActionPerformed
|
||||
|
||||
|
@ -318,9 +324,12 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
}
|
||||
}//GEN-LAST:event_btnQuickStartActionPerformed
|
||||
|
||||
private void btnNewDraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewDraftActionPerformed
|
||||
|
||||
}//GEN-LAST:event_btnNewDraftActionPerformed
|
||||
private void btnNewTournamentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewTournamentActionPerformed
|
||||
newTournamentDialog.showDialog(roomId);
|
||||
if (newTournamentDialog.getTable() != null) {
|
||||
tableWaitingDialog.showDialog(roomId, newTournamentDialog.getTable().getTableId(), true);
|
||||
}
|
||||
}//GEN-LAST:event_btnNewTournamentActionPerformed
|
||||
|
||||
private void handleError(Exception ex) {
|
||||
logger.log(Level.SEVERE, "Error loading deck", ex);
|
||||
|
@ -329,8 +338,8 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnNewDraft;
|
||||
private javax.swing.JButton btnNewTable;
|
||||
private javax.swing.JButton btnNewTournament;
|
||||
private javax.swing.JButton btnQuickStart;
|
||||
private mage.client.chat.ChatPanel chatPanel;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
<?xml version="1.1" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="lblPlayerNum" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="cbPlayerType" min="-2" pref="175" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="pnlPlayerName" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="2" attributes="0">
|
||||
<Component id="lblPlayerNum" alignment="2" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" alignment="2" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="cbPlayerType" alignment="2" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="pnlPlayerName" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="cbPlayerType"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Type:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="cbPlayerType">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="4">
|
||||
<StringItem index="0" value="Item 1"/>
|
||||
<StringItem index="1" value="Item 2"/>
|
||||
<StringItem index="2" value="Item 3"/>
|
||||
<StringItem index="3" value="Item 4"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbPlayerTypeActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblPlayerNum">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="11" style="1"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Player Num:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="pnlPlayerName">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="txtPlayerName" pref="189" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="txtPlayerName" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTextField" name="txtPlayerName">
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel2">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Name:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
/*
|
||||
* TournamentPlayerPanel.java
|
||||
*
|
||||
* Created on Jan 28, 2011, 1:50:29 PM
|
||||
*/
|
||||
|
||||
package mage.client.table;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.remote.Session;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentPlayerPanel extends javax.swing.JPanel {
|
||||
|
||||
private Session session;
|
||||
|
||||
/** Creates new form TournamentPlayerPanel */
|
||||
public TournamentPlayerPanel() {
|
||||
initComponents();
|
||||
this.pnlPlayerName.setVisible(false);
|
||||
}
|
||||
|
||||
public void init(int playerNum) {
|
||||
session = MageFrame.getSession();
|
||||
cbPlayerType.setModel(new DefaultComboBoxModel(session.getPlayerTypes()));
|
||||
this.lblPlayerNum.setText("Player " + playerNum);
|
||||
}
|
||||
|
||||
public String getPlayerType() {
|
||||
return (String) this.cbPlayerType.getSelectedItem();
|
||||
}
|
||||
|
||||
public boolean joinTournamentTable(UUID roomId, UUID tableId) {
|
||||
if (!this.cbPlayerType.getSelectedItem().equals("Human")) {
|
||||
return session.joinTournamentTable(roomId, tableId, this.txtPlayerName.getText());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
cbPlayerType = new javax.swing.JComboBox();
|
||||
lblPlayerNum = new javax.swing.JLabel();
|
||||
pnlPlayerName = new javax.swing.JPanel();
|
||||
txtPlayerName = new javax.swing.JTextField();
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
|
||||
jLabel1.setLabelFor(cbPlayerType);
|
||||
jLabel1.setText("Type:");
|
||||
|
||||
cbPlayerType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
|
||||
cbPlayerType.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
cbPlayerTypeActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
lblPlayerNum.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
|
||||
lblPlayerNum.setText("Player Num:");
|
||||
|
||||
jLabel2.setText("Name:");
|
||||
|
||||
javax.swing.GroupLayout pnlPlayerNameLayout = new javax.swing.GroupLayout(pnlPlayerName);
|
||||
pnlPlayerName.setLayout(pnlPlayerNameLayout);
|
||||
pnlPlayerNameLayout.setHorizontalGroup(
|
||||
pnlPlayerNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(pnlPlayerNameLayout.createSequentialGroup()
|
||||
.addComponent(jLabel2)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(txtPlayerName, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE))
|
||||
);
|
||||
pnlPlayerNameLayout.setVerticalGroup(
|
||||
pnlPlayerNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(pnlPlayerNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(txtPlayerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jLabel2))
|
||||
);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(lblPlayerNum)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jLabel1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(cbPlayerType, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(pnlPlayerName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
|
||||
.addComponent(lblPlayerNum)
|
||||
.addComponent(jLabel1)
|
||||
.addComponent(cbPlayerType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(pnlPlayerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void cbPlayerTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPlayerTypeActionPerformed
|
||||
if (!this.cbPlayerType.getSelectedItem().equals("Human")) {
|
||||
this.pnlPlayerName.setVisible(true);
|
||||
if (this.txtPlayerName.getText().length() == 0) {
|
||||
this.txtPlayerName.setText("Computer " + this.lblPlayerNum.getText());
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.pnlPlayerName.setVisible(false);
|
||||
}
|
||||
this.revalidate();
|
||||
this.repaint();
|
||||
}//GEN-LAST:event_cbPlayerTypeActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JComboBox cbPlayerType;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JLabel jLabel2;
|
||||
private javax.swing.JLabel lblPlayerNum;
|
||||
private javax.swing.JPanel pnlPlayerName;
|
||||
private javax.swing.JTextField txtPlayerName;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.1" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="tournamentPanel1" alignment="0" pref="758" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="tournamentPanel1" alignment="0" pref="522" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="mage.client.tournament.TournamentPanel" name="tournamentPanel1">
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
/*
|
||||
* TournamentPane.java
|
||||
*
|
||||
* Created on 22-Jan-2011, 11:41:47 PM
|
||||
*/
|
||||
|
||||
package mage.client.tournament;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.client.MagePane;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentPane extends MagePane {
|
||||
|
||||
/** Creates new form TournamentPane */
|
||||
public TournamentPane() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public void showTournament(UUID tournamentId) {
|
||||
this.setTitle("Tournament " + tournamentId);
|
||||
this.tournamentPanel1.showTournament(tournamentId);
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
tournamentPanel1 = new mage.client.tournament.TournamentPanel();
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(tournamentPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(tournamentPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private mage.client.tournament.TournamentPanel tournamentPanel1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.1" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="jScrollPane1" pref="573" max="32767" attributes="2"/>
|
||||
<Component id="jScrollPane2" alignment="1" pref="573" max="32767" attributes="2"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="chatPanel1" min="-2" pref="215" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="jScrollPane1" min="-2" pref="262" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane2" pref="260" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="chatPanel1" alignment="0" pref="522" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="mage.client.chat.ChatPanel" name="chatPanel1">
|
||||
</Component>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTable" name="tablePlayers">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="this.playersModel" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane2">
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTable" name="tableMatches">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="matchesModel" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
|
@ -0,0 +1,300 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
/*
|
||||
* TournamentPanel.java
|
||||
*
|
||||
* Created on 20-Jan-2011, 9:18:30 PM
|
||||
*/
|
||||
|
||||
package mage.client.tournament;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.UUID;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.remote.MageRemoteException;
|
||||
import mage.client.remote.Session;
|
||||
import mage.view.RoundView;
|
||||
import mage.view.TournamentGameView;
|
||||
import mage.view.TournamentPlayerView;
|
||||
import mage.view.TournamentView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentPanel extends javax.swing.JPanel implements Observer {
|
||||
|
||||
private UUID tournamentId;
|
||||
private Session session;
|
||||
private TournamentPlayersTableModel playersModel;
|
||||
private TournamentMatchesTableModel matchesModel;
|
||||
private TournamentWatchdog tournamentWatchdog = new TournamentWatchdog();
|
||||
|
||||
/** Creates new form TournamentPanel */
|
||||
public TournamentPanel() {
|
||||
playersModel = new TournamentPlayersTableModel();
|
||||
matchesModel = new TournamentMatchesTableModel();
|
||||
|
||||
initComponents();
|
||||
|
||||
tablePlayers.createDefaultColumnsFromModel();
|
||||
tableMatches.createDefaultColumnsFromModel();
|
||||
|
||||
}
|
||||
|
||||
public synchronized void showTournament(UUID tournamentId) {
|
||||
this.tournamentId = tournamentId;
|
||||
session = MageFrame.getSession();
|
||||
session.setTournament(this);
|
||||
UUID chatRoomId = session.getTournamentChatId(tournamentId);
|
||||
if (session.joinTournament(tournamentId) && chatRoomId != null) {
|
||||
this.chatPanel1.connect(chatRoomId);
|
||||
tournamentWatchdog.addObserver(this);
|
||||
this.setVisible(true);
|
||||
this.repaint();
|
||||
}
|
||||
else {
|
||||
hideTournament();
|
||||
}
|
||||
}
|
||||
|
||||
public void hideTournament() {
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable arg0, Object arg1) {
|
||||
TournamentView tournament;
|
||||
try {
|
||||
tournament = MageFrame.getSession().getTournament(tournamentId);
|
||||
playersModel.loadData(tournament);
|
||||
matchesModel.loadData(tournament);
|
||||
this.tablePlayers.repaint();
|
||||
this.tableMatches.repaint();
|
||||
} catch (MageRemoteException ex) {
|
||||
hideTournament();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
chatPanel1 = new mage.client.chat.ChatPanel();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
tablePlayers = new javax.swing.JTable();
|
||||
jScrollPane2 = new javax.swing.JScrollPane();
|
||||
tableMatches = new javax.swing.JTable();
|
||||
|
||||
tablePlayers.setModel(this.playersModel);
|
||||
jScrollPane1.setViewportView(tablePlayers);
|
||||
|
||||
tableMatches.setModel(matchesModel);
|
||||
jScrollPane2.setViewportView(tableMatches);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE)
|
||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE))
|
||||
.addGap(0, 0, 0)
|
||||
.addComponent(chatPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 0, 0)
|
||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
|
||||
.addComponent(chatPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private mage.client.chat.ChatPanel chatPanel1;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JScrollPane jScrollPane2;
|
||||
private javax.swing.JTable tableMatches;
|
||||
private javax.swing.JTable tablePlayers;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
|
||||
class TournamentPlayersTableModel extends AbstractTableModel {
|
||||
private String[] columnNames = new String[]{"Player Name", "Points", "Results"};
|
||||
private TournamentPlayerView[] players = new TournamentPlayerView[0];
|
||||
|
||||
public void loadData(TournamentView tournament) {
|
||||
players = tournament.getPlayers().toArray(new TournamentPlayerView[0]);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return players.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columnNames.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int arg0, int arg1) {
|
||||
switch (arg1) {
|
||||
case 0:
|
||||
return players[arg0].getName();
|
||||
case 1:
|
||||
return Integer.toString(players[arg0].getPoints());
|
||||
case 2:
|
||||
return players[arg0].getResults();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int columnIndex) {
|
||||
String colName = "";
|
||||
|
||||
if (columnIndex <= getColumnCount())
|
||||
colName = columnNames[columnIndex];
|
||||
|
||||
return colName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getColumnClass(int columnIndex){
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TournamentMatchesTableModel extends AbstractTableModel {
|
||||
private String[] columnNames = new String[]{"Round Number", "Players", "Match Id", "Game Id", "State", "Result"};
|
||||
private TournamentGameView[] games = new TournamentGameView[0];
|
||||
|
||||
public void loadData(TournamentView tournament) {
|
||||
List<TournamentGameView> views = new ArrayList<TournamentGameView>();
|
||||
for (RoundView round: tournament.getRounds()) {
|
||||
for (TournamentGameView game: round.getGames()) {
|
||||
views.add(game);
|
||||
}
|
||||
}
|
||||
games = views.toArray(new TournamentGameView[0]);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return games.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columnNames.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int arg0, int arg1) {
|
||||
switch (arg1) {
|
||||
case 0:
|
||||
return Integer.toString(games[arg0].getRoundNum());
|
||||
case 1:
|
||||
return games[arg0].getPlayers();
|
||||
case 2:
|
||||
return games[arg0].getMatchId().toString();
|
||||
case 3:
|
||||
return games[arg0].getGameId().toString();
|
||||
case 4:
|
||||
return games[arg0].getState();
|
||||
case 5:
|
||||
return games[arg0].getResult();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int columnIndex) {
|
||||
String colName = "";
|
||||
|
||||
if (columnIndex <= getColumnCount())
|
||||
colName = columnNames[columnIndex];
|
||||
|
||||
return colName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getColumnClass(int columnIndex){
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TournamentWatchdog extends Observable implements ActionListener {
|
||||
|
||||
Timer t = new Timer(1000, this); // check every second
|
||||
|
||||
public TournamentWatchdog() {
|
||||
t.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
|
||||
}
|
|
@ -35,10 +35,11 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.callback.CallbackServer;
|
||||
import mage.view.TableView;
|
||||
import mage.view.GameView;
|
||||
import mage.view.TournamentView;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -54,9 +55,9 @@ public interface Server extends Remote, CallbackServer {
|
|||
|
||||
//table methods
|
||||
public TableView createTable(UUID sessionId, UUID roomId, MatchOptions matchOptions) throws RemoteException, MageException;
|
||||
public TableView createDraftTable(UUID sessionId, UUID roomId, DraftOptions draftOptions) throws RemoteException, MageException;
|
||||
public TableView createTournamentTable(UUID sessionId, UUID roomId, TournamentOptions tournamentOptions) throws RemoteException, MageException;
|
||||
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, DeckCardLists deckList) throws RemoteException, MageException, GameException;
|
||||
public boolean joinDraftTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws RemoteException, MageException, GameException;
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws RemoteException, MageException, GameException;
|
||||
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws RemoteException, MageException, GameException;
|
||||
public boolean watchTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public boolean replayTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
|
@ -74,6 +75,7 @@ public interface Server extends Remote, CallbackServer {
|
|||
public UUID getTableChatId(UUID tableId) throws RemoteException, MageException;
|
||||
public UUID getGameChatId(UUID gameId) throws RemoteException, MageException;
|
||||
public UUID getRoomChatId(UUID roomId) throws RemoteException, MageException;
|
||||
public UUID getTournamentChatId(UUID tournamentId) throws RemoteException, MageException;
|
||||
|
||||
//room methods
|
||||
public UUID getMainRoomId() throws RemoteException, MageException;
|
||||
|
@ -89,8 +91,12 @@ public interface Server extends Remote, CallbackServer {
|
|||
public void sendPlayerInteger(UUID gameId, UUID sessionId, Integer data) throws RemoteException, MageException;
|
||||
public void concedeGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
|
||||
//tournament methods
|
||||
public void startTournament(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void joinTournament(UUID draftId, UUID sessionId) throws RemoteException, MageException;
|
||||
public TournamentView getTournament(UUID tournamentId) throws RemoteException, MageException;
|
||||
|
||||
//draft methods
|
||||
public void startDraft(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void joinDraft(UUID draftId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) throws RemoteException, MageException;
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ package mage.interfaces;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import mage.view.GameTypeView;
|
||||
import mage.view.TournamentTypeView;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -39,12 +40,14 @@ import mage.view.GameTypeView;
|
|||
public class ServerState implements Serializable {
|
||||
|
||||
private List<GameTypeView> gameTypes;
|
||||
private List<TournamentTypeView> tournamentTypes;
|
||||
private String[] playerTypes;
|
||||
private String[] deckTypes;
|
||||
private boolean testMode;
|
||||
|
||||
public ServerState(List<GameTypeView> gameTypes, String[] playerTypes, String[] deckTypes, boolean testMode) {
|
||||
public ServerState(List<GameTypeView> gameTypes, List<TournamentTypeView> tournamentTypes, String[] playerTypes, String[] deckTypes, boolean testMode) {
|
||||
this.gameTypes = gameTypes;
|
||||
this.tournamentTypes = tournamentTypes;
|
||||
this.playerTypes = playerTypes;
|
||||
this.deckTypes = deckTypes;
|
||||
this.testMode = testMode;
|
||||
|
@ -54,6 +57,10 @@ public class ServerState implements Serializable {
|
|||
return gameTypes;
|
||||
}
|
||||
|
||||
public List<TournamentTypeView> getTournamentTypes() {
|
||||
return tournamentTypes;
|
||||
}
|
||||
|
||||
public String[] getPlayerTypes() {
|
||||
return playerTypes;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,10 @@ public class ClientCallback implements Serializable {
|
|||
this.data = data;
|
||||
}
|
||||
|
||||
public ClientCallback(String method) {
|
||||
this(method, null);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
method = null;
|
||||
data = null;
|
||||
|
|
|
@ -29,7 +29,11 @@
|
|||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import mage.game.Game;
|
||||
import mage.game.tournament.Round;
|
||||
import mage.game.tournament.TournamentPairing;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -38,8 +42,20 @@ import mage.game.tournament.Round;
|
|||
public class RoundView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public RoundView(Round round) {
|
||||
List<TournamentGameView> games = new ArrayList<TournamentGameView>();
|
||||
|
||||
public RoundView(Round round) {
|
||||
for (TournamentPairing pair: round.getPairs()) {
|
||||
if (pair.getMatch() != null) {
|
||||
for (Game game: pair.getMatch().getGames()) {
|
||||
games.add(new TournamentGameView(round.getRoundNumber(), pair, game));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<TournamentGameView> getGames() {
|
||||
return games;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
89
Mage.Common/src/mage/view/TournamentGameView.java
Normal file
89
Mage.Common/src/mage/view/TournamentGameView.java
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* 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;
|
||||
import java.util.UUID;
|
||||
import mage.game.Game;
|
||||
import mage.game.tournament.TournamentPairing;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
||||
public class TournamentGameView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int roundNum;
|
||||
private UUID matchId;
|
||||
private UUID gameId;
|
||||
private String state;
|
||||
private String result;
|
||||
private String players;
|
||||
|
||||
TournamentGameView(int roundNum, TournamentPairing pair, Game game) {
|
||||
this.roundNum = roundNum;
|
||||
this.matchId = pair.getMatch().getId();
|
||||
this.gameId = game.getId();
|
||||
this.players = pair.getPlayer1().getPlayer().getName() + " " + pair.getPlayer2().getPlayer().getName();
|
||||
if (game.isGameOver()) {
|
||||
this.state = "Finished";
|
||||
this.result = game.getWinner();
|
||||
}
|
||||
else {
|
||||
this.state = "Dueling";
|
||||
this.result = "";
|
||||
}
|
||||
}
|
||||
|
||||
public int getRoundNum() {
|
||||
return roundNum;
|
||||
}
|
||||
|
||||
public UUID getMatchId() {
|
||||
return this.matchId;
|
||||
}
|
||||
|
||||
public UUID getGameId() {
|
||||
return this.gameId;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public String getPlayers() {
|
||||
return this.players;
|
||||
}
|
||||
}
|
|
@ -29,6 +29,10 @@
|
|||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.game.tournament.Round;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentPairing;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -37,4 +41,25 @@ import java.io.Serializable;
|
|||
public class TournamentPlayerView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String name;
|
||||
private String results;
|
||||
private int points;
|
||||
|
||||
TournamentPlayerView(TournamentPlayer player) {
|
||||
this.name = player.getPlayer().getName();
|
||||
this.points = player.getPoints();
|
||||
this.results = player.getResults();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return this.points;
|
||||
}
|
||||
|
||||
public String getResults() {
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
|
79
Mage.Common/src/mage/view/TournamentTypeView.java
Normal file
79
Mage.Common/src/mage/view/TournamentTypeView.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* 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;
|
||||
import mage.game.tournament.TournamentType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentTypeView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String name;
|
||||
private int minPlayers;
|
||||
private int maxPlayers;
|
||||
private int numBoosters;
|
||||
private boolean draft;
|
||||
|
||||
public TournamentTypeView(TournamentType tournamentType) {
|
||||
this.name = tournamentType.getName();
|
||||
this.minPlayers = tournamentType.getMinPlayers();
|
||||
this.maxPlayers = tournamentType.getMaxPlayers();
|
||||
this.numBoosters = tournamentType.getNumBoosters();
|
||||
this.draft = tournamentType.isDraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getMinPlayers() {
|
||||
return minPlayers;
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
public int getNumBoosters() {
|
||||
return numBoosters;
|
||||
}
|
||||
|
||||
public boolean isDraft() {
|
||||
return draft;
|
||||
}
|
||||
}
|
|
@ -31,7 +31,9 @@ package mage.view;
|
|||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import mage.game.tournament.Round;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -41,8 +43,22 @@ public class TournamentView implements Serializable {
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
List<RoundView> rounds = new ArrayList<RoundView>();
|
||||
List<TournamentPlayerView> players = new ArrayList<TournamentPlayerView>();
|
||||
|
||||
public TournamentView(Tournament tournament) {
|
||||
for (TournamentPlayer player: tournament.getPlayers()) {
|
||||
players.add(new TournamentPlayerView(player));
|
||||
}
|
||||
for (Round round: tournament.getRounds()) {
|
||||
rounds.add(new RoundView(round));
|
||||
}
|
||||
}
|
||||
|
||||
public List<TournamentPlayerView> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
public List<RoundView> getRounds() {
|
||||
return rounds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import mage.game.match.MatchOptions;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class FreeForAllMatch extends MatchImpl<FreeForAll> {
|
||||
public class FreeForAllMatch extends MatchImpl {
|
||||
|
||||
public FreeForAllMatch(MatchOptions options) {
|
||||
super(options);
|
||||
|
|
|
@ -35,7 +35,7 @@ import mage.game.match.MatchOptions;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TwoPlayerMatch extends MatchImpl<TwoPlayerDuel> {
|
||||
public class TwoPlayerMatch extends MatchImpl {
|
||||
|
||||
public TwoPlayerMatch(MatchOptions options) {
|
||||
super(options);
|
||||
|
|
51
Mage.Server.Plugins/Mage.Tournament.BoosterDraft/pom.xml
Normal file
51
Mage.Server.Plugins/Mage.Tournament.BoosterDraft/pom.xml
Normal file
|
@ -0,0 +1,51 @@
|
|||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.mage</groupId>
|
||||
<artifactId>Mage-Server-Plugins</artifactId>
|
||||
<version>0.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Mage-Tournament-BoosterDraft</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Mage Tournament Booster Draft</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>Mage</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
<finalName>mage-tournament-booster-draft</finalName>
|
||||
</build>
|
||||
|
||||
<properties/>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.tournament;
|
||||
|
||||
import mage.game.draft.BoosterDraft;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.events.TableEvent.EventType;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
import mage.game.tournament.TournamentSingleElimination;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class BoosterDraftEliminationTournament extends TournamentSingleElimination {
|
||||
|
||||
protected enum TournamentStep {
|
||||
START, DRAFT, CONSTRUCT, COMPETE, WINNERS
|
||||
}
|
||||
|
||||
protected TournamentStep currentStep;
|
||||
|
||||
public BoosterDraftEliminationTournament(TournamentOptions options) {
|
||||
super(options);
|
||||
currentStep = TournamentStep.START;
|
||||
}
|
||||
|
||||
protected void draft() {
|
||||
Draft draft = new BoosterDraft(options.getDraftOptions());
|
||||
for (TournamentPlayer player: players.values()) {
|
||||
draft.addPlayer(player.getPlayer());
|
||||
}
|
||||
tableEventSource.fireTableEvent(EventType.START_DRAFT, null, draft);
|
||||
}
|
||||
|
||||
protected void winners() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextStep() {
|
||||
switch (currentStep) {
|
||||
case START:
|
||||
currentStep = TournamentStep.DRAFT;
|
||||
draft();
|
||||
break;
|
||||
case DRAFT:
|
||||
currentStep = TournamentStep.CONSTRUCT;
|
||||
construct();
|
||||
break;
|
||||
case CONSTRUCT:
|
||||
currentStep = TournamentStep.COMPETE;
|
||||
runTournament();
|
||||
break;
|
||||
case COMPETE:
|
||||
currentStep = TournamentStep.WINNERS;
|
||||
winners();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.tournament;
|
||||
|
||||
import mage.game.tournament.TournamentType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class BoosterDraftEliminationTournamentType extends TournamentType<BoosterDraftEliminationTournamentType> {
|
||||
|
||||
public BoosterDraftEliminationTournamentType() {
|
||||
this.name = "Elimination Booster Draft";
|
||||
this.maxPlayers = 16;
|
||||
this.minPlayers = 4;
|
||||
this.numBoosters = 3;
|
||||
this.draft = true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#Generated by Maven
|
||||
#Sun Feb 06 08:07:38 EST 2011
|
||||
version=0.6
|
||||
groupId=org.mage
|
||||
artifactId=Mage-Tournament-BoosterDraft
|
|
@ -22,7 +22,7 @@
|
|||
<module>Mage.Player.AI</module>
|
||||
<module>Mage.Player.AIMinimax</module>
|
||||
<module>Mage.Player.Human</module>
|
||||
<module>Mage.Draft.8PlayerBooster</module>
|
||||
<module>Mage.Tournament.BoosterDraft</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -12,9 +12,9 @@
|
|||
<gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/>
|
||||
<gameType name="Free For All" jar="mage-game-freeforall.jar" className="mage.game.FreeForAllMatch" typeName="mage.game.FreeForAllType"/>
|
||||
</gameTypes>
|
||||
<draftTypes>
|
||||
<draftType name="8 Player Booster" jar="mage-draft-8playerbooster.jar" className="mage.draft.BoosterDraft"/>
|
||||
</draftTypes>
|
||||
<tournamentTypes>
|
||||
<tournamentType name="Elimination Booster Draft" jar="mage-tournament-booster-draft.jar" className="mage.tournament.BoosterDraftEliminationTournament" typeName="mage.tournament.BoosterDraftEliminationTournamentType"/>
|
||||
</tournamentTypes>
|
||||
<deckTypes>
|
||||
<deckType name="Constructed" jar="mage-deck-constructed.jar" className="mage.deck.Constructed"/>
|
||||
<deckType name="Limited" jar="mage-deck-limited.jar" className="mage.deck.Limited"/>
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Mage.Server/plugins/mage-tournament-booster-draft.jar
Normal file
BIN
Mage.Server/plugins/mage-tournament-booster-draft.jar
Normal file
Binary file not shown.
|
@ -34,7 +34,6 @@ import java.util.Calendar;
|
|||
import java.util.GregorianCalendar;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.util.Logging;
|
||||
|
|
|
@ -36,10 +36,11 @@ import java.net.InetAddress;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.game.match.MatchType;
|
||||
import mage.game.tournament.TournamentType;
|
||||
import mage.server.game.DeckValidatorFactory;
|
||||
import mage.server.game.DraftFactory;
|
||||
import mage.server.game.GameFactory;
|
||||
import mage.server.game.PlayerFactory;
|
||||
import mage.server.tournament.TournamentFactory;
|
||||
import mage.server.util.ConfigSettings;
|
||||
import mage.server.util.config.Plugin;
|
||||
import mage.server.util.config.GamePlugin;
|
||||
|
@ -73,8 +74,8 @@ public class Main {
|
|||
for (GamePlugin plugin: config.getGameTypes()) {
|
||||
GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
|
||||
}
|
||||
for (Plugin plugin: config.getDraftTypes()) {
|
||||
DraftFactory.getInstance().addDraftType(plugin.getName(), loadPlugin(plugin));
|
||||
for (GamePlugin plugin: config.getTournamentTypes()) {
|
||||
TournamentFactory.getInstance().addTournamentType(plugin.getName(), loadTournamentType(plugin), loadPlugin(plugin));
|
||||
}
|
||||
for (Plugin plugin: config.getPlayerTypes()) {
|
||||
PlayerFactory.getInstance().addPlayerType(plugin.getName(), loadPlugin(plugin));
|
||||
|
@ -136,6 +137,19 @@ public class Main {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static TournamentType loadTournamentType(GamePlugin plugin) {
|
||||
try {
|
||||
classLoader.addURL(new File(pluginFolder + "/" + plugin.getJar()).toURI().toURL());
|
||||
logger.info("Loading tournament type: " + plugin.getClassName());
|
||||
return (TournamentType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
||||
} catch (ClassNotFoundException ex) {
|
||||
logger.log(Level.SEVERE, "Tournament type not found:" + plugin.getJar() + " - check plugin folder");
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, "Error loading game type " + plugin.getJar(), ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void deleteSavedGames() {
|
||||
File directory = new File("saved/");
|
||||
if (!directory.exists())
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.game;
|
||||
package mage.server;
|
||||
|
||||
import java.rmi.Remote;
|
||||
import java.util.UUID;
|
|
@ -26,7 +26,7 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.game;
|
||||
package mage.server;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.server.ChatManager;
|
|
@ -41,25 +41,27 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.interfaces.MageException;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.Server;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.game.DeckValidatorFactory;
|
||||
import mage.server.game.DraftManager;
|
||||
import mage.server.draft.DraftManager;
|
||||
import mage.server.game.GameFactory;
|
||||
import mage.server.game.GameManager;
|
||||
import mage.server.game.GamesRoomManager;
|
||||
import mage.server.game.PlayerFactory;
|
||||
import mage.server.game.ReplayManager;
|
||||
import mage.server.game.TableManager;
|
||||
import mage.server.tournament.TournamentFactory;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.util.Logging;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
import mage.view.GameView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -130,10 +132,10 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TableView createDraftTable(UUID sessionId, UUID roomId, DraftOptions options) throws MageException {
|
||||
public TableView createTournamentTable(UUID sessionId, UUID roomId, TournamentOptions options) throws MageException {
|
||||
try {
|
||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createDraftTable(sessionId, options);
|
||||
logger.info("Draft table " + table.getTableId() + " created");
|
||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(sessionId, options);
|
||||
logger.log(Level.INFO, "Tournament table {0} created", table.getTableId());
|
||||
return table;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
@ -175,9 +177,9 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinDraftTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws MageException, GameException {
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws MageException, GameException {
|
||||
try {
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinDraftTable(sessionId, tableId, name);
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name);
|
||||
logger.info("Session " + sessionId + " joined table " + tableId);
|
||||
return ret;
|
||||
}
|
||||
|
@ -262,13 +264,13 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startDraft(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public void startTournament(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TableManager.getInstance().startDraft(sessionId, roomId, tableId);
|
||||
TableManager.getInstance().startTournament(sessionId, roomId, tableId);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -278,6 +280,17 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TournamentView getTournament(UUID tournamentId) throws RemoteException, MageException {
|
||||
try {
|
||||
return TournamentManager.getInstance().getTournamentView(tournamentId);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChatMessage(final UUID chatId, final String userName, final String message) throws MageException {
|
||||
try {
|
||||
|
@ -441,6 +454,23 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinTournament(final UUID tournamentId, final UUID sessionId) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TournamentManager.getInstance().joinTournament(tournamentId, sessionId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getGameChatId(UUID gameId) throws MageException {
|
||||
try {
|
||||
|
@ -452,6 +482,17 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getTournamentChatId(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return TournamentManager.getInstance().getChatId(tournamentId);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayerUUID(final UUID gameId, final UUID sessionId, final UUID data) throws MageException {
|
||||
try {
|
||||
|
@ -683,6 +724,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
try {
|
||||
return new ServerState(
|
||||
GameFactory.getInstance().getGameTypes(),
|
||||
TournamentFactory.getInstance().getTournamentTypes(),
|
||||
PlayerFactory.getInstance().getPlayerTypes().toArray(new String[0]),
|
||||
DeckValidatorFactory.getInstance().getDeckTypes().toArray(new String[0]),
|
||||
testMode);
|
||||
|
@ -722,7 +764,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
|
||||
public void handleException(Exception ex) throws MageException {
|
||||
logger.log(Level.SEVERE, "", ex);
|
||||
throw new MageException("Server error");
|
||||
throw new MageException("Server error: " + ex.getMessage());
|
||||
}
|
||||
|
||||
public GameView getGameView(final UUID gameId, final UUID sessionId, final UUID playerId) {
|
||||
|
|
|
@ -35,7 +35,6 @@ import mage.cards.decks.Deck;
|
|||
import mage.interfaces.callback.CallbackServerSession;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.game.GameManager;
|
||||
import mage.server.game.TableManager;
|
||||
import mage.util.Logging;
|
||||
import mage.view.TableClientMessage;
|
||||
|
||||
|
@ -99,6 +98,10 @@ public class Session {
|
|||
fireCallback(new ClientCallback("startDraft", new TableClientMessage(draftId, playerId)));
|
||||
}
|
||||
|
||||
public void tournamentStarted(final UUID tournamentId, final UUID playerId) {
|
||||
fireCallback(new ClientCallback("startTournament", new TableClientMessage(tournamentId, playerId)));
|
||||
}
|
||||
|
||||
public void sideboard(final Deck deck, final UUID tableId) {
|
||||
fireCallback(new ClientCallback("sideboard", new TableClientMessage(deck, tableId)));
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ package mage.server;
|
|||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.interfaces.MageException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -49,15 +50,25 @@ public class SessionManager {
|
|||
return sessions.get(sessionId);
|
||||
}
|
||||
|
||||
public UUID createSession(String userName, UUID clientId) {
|
||||
Session session = new Session(userName, clientId);
|
||||
sessions.put(session.getId(), session);
|
||||
return session.getId();
|
||||
public UUID createSession(String userName, UUID clientId) throws MageException {
|
||||
if (!isNameUsed(userName)) {
|
||||
Session session = new Session(userName, clientId);
|
||||
sessions.put(session.getId(), session);
|
||||
return session.getId();
|
||||
}
|
||||
throw new MageException("User name already in use");
|
||||
}
|
||||
|
||||
public void removeSession(UUID sessionId) {
|
||||
sessions.remove(sessionId);
|
||||
}
|
||||
|
||||
private boolean isNameUsed(String name) {
|
||||
for (Session session: sessions.values()) {
|
||||
if (session.getUsername().equals(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,8 +26,11 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.game;
|
||||
package mage.server;
|
||||
|
||||
import mage.server.draft.DraftManager;
|
||||
import mage.server.tournament.TournamentFactory;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import mage.game.Table;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
|
@ -56,16 +59,24 @@ import mage.game.GameStates;
|
|||
import mage.game.match.Match;
|
||||
import mage.game.Seat;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.game.draft.DraftPlayer;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
import mage.players.Player;
|
||||
import mage.server.ChatManager;
|
||||
import mage.server.Main;
|
||||
import mage.server.SessionManager;
|
||||
import mage.server.game.DeckValidatorFactory;
|
||||
import mage.server.game.GameFactory;
|
||||
import mage.server.game.GameManager;
|
||||
import mage.server.game.GameReplay;
|
||||
import mage.server.game.PlayerFactory;
|
||||
import mage.server.game.ReplayManager;
|
||||
import mage.util.CopierObjectInputStream;
|
||||
import mage.util.Logging;
|
||||
|
||||
|
@ -82,8 +93,8 @@ public class TableController {
|
|||
private Table table;
|
||||
private Match match;
|
||||
private MatchOptions options;
|
||||
private Draft draft;
|
||||
private DraftOptions draftOptions;
|
||||
private Tournament tournament;
|
||||
private TournamentOptions tournamentOptions;
|
||||
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
|
||||
|
||||
public TableController(UUID sessionId, MatchOptions options) {
|
||||
|
@ -95,12 +106,12 @@ public class TableController {
|
|||
init();
|
||||
}
|
||||
|
||||
public TableController(UUID sessionId, DraftOptions options) {
|
||||
public TableController(UUID sessionId, TournamentOptions options) {
|
||||
this.sessionId = sessionId;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.draftOptions = options;
|
||||
draft = DraftFactory.getInstance().createDraft(options.getDraftType(), options);
|
||||
table = new Table(options.getDraftType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator("Limited"), options.getPlayerTypes());
|
||||
this.tournamentOptions = options;
|
||||
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
|
||||
table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes());
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -125,7 +136,7 @@ public class TableController {
|
|||
);
|
||||
}
|
||||
|
||||
public synchronized boolean joinDraft(UUID sessionId, String name) throws GameException {
|
||||
public synchronized boolean joinTournament(UUID sessionId, String name) throws GameException {
|
||||
if (table.getState() != TableState.WAITING) {
|
||||
return false;
|
||||
}
|
||||
|
@ -134,7 +145,7 @@ public class TableController {
|
|||
throw new GameException("No available seats.");
|
||||
}
|
||||
Player player = createPlayer(name, seat.getPlayerType());
|
||||
draft.addPlayer(player);
|
||||
tournament.addPlayer(player, seat.getPlayerType());
|
||||
table.joinTable(player, seat);
|
||||
logger.info("player joined " + player.getId());
|
||||
//only add human players to sessionPlayerMap
|
||||
|
@ -170,6 +181,21 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void addPlayer(UUID sessionId, Player player, Deck deck) throws GameException {
|
||||
if (table.getState() != TableState.WAITING) {
|
||||
return;
|
||||
}
|
||||
Seat seat = table.getNextAvailableSeat();
|
||||
if (seat == null) {
|
||||
throw new GameException("No available seats.");
|
||||
}
|
||||
match.addPlayer(player, deck);
|
||||
table.joinTable(player, seat);
|
||||
if (player.isHuman()) {
|
||||
sessionPlayerMap.put(sessionId, player.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean submitDeck(UUID sessionId, DeckCardLists deckList) throws GameException {
|
||||
if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
|
||||
return false;
|
||||
|
@ -180,7 +206,7 @@ public class TableController {
|
|||
playerName = player.getPlayer().getName();
|
||||
}
|
||||
else {
|
||||
DraftPlayer player = draft.getPlayer(sessionPlayerMap.get(sessionId));
|
||||
TournamentPlayer player = tournament.getPlayer(sessionPlayerMap.get(sessionId));
|
||||
playerName = player.getPlayer().getName();
|
||||
}
|
||||
Deck deck = Deck.load(deckList);
|
||||
|
@ -196,9 +222,8 @@ public class TableController {
|
|||
MatchPlayer player = match.getPlayer(playerId);
|
||||
player.submitDeck(deck);
|
||||
}
|
||||
else if (table.getState() == TableState.CONSTRUCTING) {
|
||||
DraftPlayer player = draft.getPlayer(playerId);
|
||||
player.submitDeck(deck);
|
||||
else {
|
||||
tournament.submitDeck(playerId, deck);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -267,17 +292,25 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void startDraft(UUID sessionId) {
|
||||
public synchronized void startTournament(UUID sessionId) {
|
||||
if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) {
|
||||
table.initDraft();
|
||||
DraftManager.getInstance().createDraftSession(draft, sessionPlayerMap, table.getId());
|
||||
TournamentManager.getInstance().createTournamentSession(tournament, sessionPlayerMap, table.getId());
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
sessionManager.getSession(entry.getKey()).draftStarted(draft.getId(), entry.getValue());
|
||||
sessionManager.getSession(entry.getKey()).tournamentStarted(tournament.getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startDraft(Draft draft) {
|
||||
table.initDraft();
|
||||
DraftManager.getInstance().createDraftSession(draft, sessionPlayerMap, table.getId());
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
sessionManager.getSession(entry.getKey()).draftStarted(draft.getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void sideboard() {
|
||||
table.sideboard();
|
||||
for (MatchPlayer player: match.getPlayers()) {
|
||||
|
@ -297,13 +330,12 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
private void construct() {
|
||||
public void construct() {
|
||||
table.construct();
|
||||
for (DraftPlayer player: draft.getPlayers()) {
|
||||
for (TournamentPlayer player: tournament.getPlayers()) {
|
||||
player.setConstructing();
|
||||
player.getPlayer().construct(table, player.getDeck());
|
||||
}
|
||||
while (!draft.isDoneConstructing()){}
|
||||
}
|
||||
|
||||
private void construct(UUID playerId, Deck deck) {
|
||||
|
@ -332,9 +364,11 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
public void endDraft() {
|
||||
construct();
|
||||
|
||||
public void endDraft(Draft draft) {
|
||||
for (DraftPlayer player: draft.getPlayers()) {
|
||||
tournament.getPlayer(player.getPlayer().getId()).setDeck(player.getDeck());
|
||||
}
|
||||
tournament.nextStep();
|
||||
}
|
||||
|
||||
public void swapSeats(int seatNum1, int seatNum2) {
|
||||
|
@ -405,4 +439,7 @@ public class TableController {
|
|||
return chatId;
|
||||
}
|
||||
|
||||
public Match getMatch() {
|
||||
return match;
|
||||
}
|
||||
}
|
|
@ -26,17 +26,22 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.game;
|
||||
package mage.server;
|
||||
|
||||
import mage.game.Table;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.players.Player;
|
||||
import mage.server.game.GameReplay;
|
||||
import mage.util.Logging;
|
||||
|
||||
/**
|
||||
|
@ -62,7 +67,7 @@ public class TableManager {
|
|||
return tableController.getTable();
|
||||
}
|
||||
|
||||
public Table createDraftTable(UUID sessionId, DraftOptions options) {
|
||||
public Table createTournamentTable(UUID sessionId, TournamentOptions options) {
|
||||
TableController tableController = new TableController(sessionId, options);
|
||||
controllers.put(tableController.getTable().getId(), tableController);
|
||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||
|
@ -73,6 +78,10 @@ public class TableManager {
|
|||
return tables.get(tableId);
|
||||
}
|
||||
|
||||
public Match getMatch(UUID tableId) {
|
||||
return controllers.get(tableId).getMatch();
|
||||
}
|
||||
|
||||
public Collection<Table> getTables() {
|
||||
return tables.values();
|
||||
}
|
||||
|
@ -81,8 +90,8 @@ public class TableManager {
|
|||
return controllers.get(tableId).joinTable(sessionId, name, deckList);
|
||||
}
|
||||
|
||||
public boolean joinDraft(UUID sessionId, UUID tableId, String name) throws GameException {
|
||||
return controllers.get(tableId).joinDraft(sessionId, name);
|
||||
public boolean joinTournament(UUID sessionId, UUID tableId, String name) throws GameException {
|
||||
return controllers.get(tableId).joinTournament(sessionId, name);
|
||||
}
|
||||
|
||||
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws GameException {
|
||||
|
@ -118,8 +127,12 @@ public class TableManager {
|
|||
controllers.get(tableId).startMatch(sessionId);
|
||||
}
|
||||
|
||||
public void startDraft(UUID sessionId, UUID roomId, UUID tableId) {
|
||||
controllers.get(tableId).startDraft(sessionId);
|
||||
public void startTournament(UUID sessionId, UUID roomId, UUID tableId) {
|
||||
controllers.get(tableId).startTournament(sessionId);
|
||||
}
|
||||
|
||||
public void startDraft(UUID tableId, Draft draft) {
|
||||
controllers.get(tableId).startDraft(draft);
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID sessionId, UUID tableId) {
|
||||
|
@ -129,13 +142,13 @@ public class TableManager {
|
|||
public boolean replayTable(UUID sessionId, UUID tableId) {
|
||||
return controllers.get(tableId).replayTable(sessionId);
|
||||
}
|
||||
|
||||
|
||||
public void endGame(UUID tableId) {
|
||||
controllers.get(tableId).endGame();
|
||||
}
|
||||
|
||||
public void endDraft(UUID tableId) {
|
||||
controllers.get(tableId).endDraft();
|
||||
public void endDraft(UUID tableId, Draft draft) {
|
||||
controllers.get(tableId).endDraft(draft);
|
||||
}
|
||||
|
||||
public GameReplay createReplay(UUID tableId) {
|
||||
|
@ -147,4 +160,12 @@ public class TableManager {
|
|||
controllers.get(tableId).swapSeats(seatNum1, seatNum2);
|
||||
}
|
||||
}
|
||||
|
||||
public void construct(UUID tableId) {
|
||||
controllers.get(tableId).construct();
|
||||
}
|
||||
|
||||
public void addPlayer(UUID sessionId, UUID tableId, Player player, Deck deck) throws GameException {
|
||||
controllers.get(tableId).addPlayer(sessionId, player, deck);
|
||||
}
|
||||
}
|
|
@ -26,13 +26,12 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.game;
|
||||
package mage.server.draft;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import mage.game.draft.Draft;
|
||||
|
@ -40,11 +39,11 @@ import mage.game.draft.DraftPlayer;
|
|||
import mage.game.events.Listener;
|
||||
import mage.game.events.PlayerQueryEvent;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.server.ChatManager;
|
||||
import mage.server.game.GameController;
|
||||
import mage.server.TableManager;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.util.Logging;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
import mage.view.DraftView;
|
||||
|
||||
/**
|
||||
|
@ -60,13 +59,11 @@ public class DraftController {
|
|||
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap;
|
||||
private UUID draftSessionId;
|
||||
private Draft draft;
|
||||
private UUID chatId;
|
||||
private UUID tableId;
|
||||
|
||||
public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
|
||||
draftSessionId = UUID.randomUUID();
|
||||
this.sessionPlayerMap = sessionPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.draft = draft;
|
||||
this.tableId = tableId;
|
||||
init();
|
||||
|
@ -100,6 +97,13 @@ public class DraftController {
|
|||
}
|
||||
}
|
||||
);
|
||||
for (DraftPlayer player: draft.getPlayers()) {
|
||||
if (!player.getPlayer().isHuman()) {
|
||||
player.setJoined();
|
||||
logger.info("player " + player.getPlayer().getId() + " has joined draft " + draft.getId());
|
||||
}
|
||||
}
|
||||
checkStart();
|
||||
}
|
||||
|
||||
private UUID getPlayerId(UUID sessionId) {
|
||||
|
@ -111,16 +115,8 @@ public class DraftController {
|
|||
DraftSession draftSession = new DraftSession(draft, sessionId, playerId);
|
||||
draftSessions.put(playerId, draftSession);
|
||||
logger.info("player " + playerId + " has joined draft " + draft.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, "", draft.getPlayer(playerId).getPlayer().getName() + " has joined the draft", MessageColor.BLACK);
|
||||
if (allJoined()) {
|
||||
ThreadExecutor.getInstance().getRMIExecutor().execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startDraft();
|
||||
}
|
||||
});
|
||||
}
|
||||
draft.getPlayer(playerId).setJoined();
|
||||
checkStart();
|
||||
}
|
||||
|
||||
private synchronized void startDraft() {
|
||||
|
@ -134,7 +130,21 @@ public class DraftController {
|
|||
draft.start();
|
||||
}
|
||||
|
||||
private void checkStart() {
|
||||
if (allJoined()) {
|
||||
ThreadExecutor.getInstance().getRMIExecutor().execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startDraft();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allJoined() {
|
||||
if (!draft.allJoined())
|
||||
return false;
|
||||
for (DraftPlayer player: draft.getPlayers()) {
|
||||
if (player.getPlayer().isHuman() && draftSessions.get(player.getPlayer().getId()) == null) {
|
||||
return false;
|
||||
|
@ -148,7 +158,10 @@ public class DraftController {
|
|||
}
|
||||
|
||||
private void endDraft() {
|
||||
TableManager.getInstance().endDraft(tableId);
|
||||
for (final DraftSession draftSession: draftSessions.values()) {
|
||||
draftSession.draftOver();
|
||||
}
|
||||
TableManager.getInstance().endDraft(tableId, draft);
|
||||
}
|
||||
|
||||
public void kill(UUID sessionId) {
|
||||
|
@ -162,26 +175,15 @@ public class DraftController {
|
|||
|
||||
public void timeout(UUID sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
ChatManager.getInstance().broadcast(chatId, "", draft.getPlayer(sessionPlayerMap.get(sessionId)).getPlayer().getName() + " has timed out. Auto picking.", MessageColor.BLACK);
|
||||
// ChatManager.getInstance().broadcast(chatId, "", draft.getPlayer(sessionPlayerMap.get(sessionId)).getPlayer().getName() + " has timed out. Auto picking.", MessageColor.BLACK);
|
||||
draft.autoPick(sessionPlayerMap.get(sessionId));
|
||||
}
|
||||
}
|
||||
|
||||
public void endDraft(final String message) {
|
||||
for (final DraftSession draftSession: draftSessions.values()) {
|
||||
draftSession.gameOver(message);
|
||||
}
|
||||
TableManager.getInstance().endDraft(tableId);
|
||||
}
|
||||
|
||||
public UUID getSessionId() {
|
||||
return this.draftSessionId;
|
||||
}
|
||||
|
||||
public UUID getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
||||
public void sendCardPick(UUID sessionId, UUID cardId) {
|
||||
draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId);
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.game;
|
||||
package mage.server.draft;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -61,10 +61,6 @@ public class DraftManager {
|
|||
draftControllers.remove(gameId);
|
||||
}
|
||||
|
||||
public UUID getChatId(UUID draftId) {
|
||||
return draftControllers.get(draftId).getChatId();
|
||||
}
|
||||
|
||||
public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) {
|
||||
draftControllers.get(draftId).sendCardPick(sessionId, cardId);
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.game;
|
||||
package mage.server.draft;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.UUID;
|
||||
|
@ -44,7 +44,6 @@ import mage.util.Logging;
|
|||
import mage.view.DraftClientMessage;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.DraftView;
|
||||
import mage.view.GameClientMessage;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -52,7 +51,7 @@ import mage.view.GameClientMessage;
|
|||
*/
|
||||
public class DraftSession {
|
||||
|
||||
protected final static Logger logger = Logging.getLogger(GameWatcher.class.getName());
|
||||
protected final static Logger logger = Logging.getLogger(DraftSession.class.getName());
|
||||
|
||||
protected UUID sessionId;
|
||||
protected UUID playerId;
|
||||
|
@ -105,11 +104,11 @@ public class DraftSession {
|
|||
}
|
||||
}
|
||||
|
||||
public void gameOver(final String message) {
|
||||
public void draftOver() {
|
||||
if (!killed) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("gameOver", message));
|
||||
session.fireCallback(new ClientCallback("draftOver"));
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import mage.server.TableManager;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
@ -43,7 +44,6 @@ import java.util.regex.Pattern;
|
|||
import mage.Constants.Zone;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
@ -153,6 +153,12 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
}
|
||||
);
|
||||
for (Player player: game.getPlayers().values()) {
|
||||
if (!player.isHuman()) {
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getName() + " has joined the game", MessageColor.BLACK);
|
||||
}
|
||||
}
|
||||
checkStart();
|
||||
}
|
||||
|
||||
private UUID getPlayerId(UUID sessionId) {
|
||||
|
@ -165,15 +171,7 @@ public class GameController implements GameCallback {
|
|||
gameSessions.put(playerId, gameSession);
|
||||
logger.info("player " + playerId + " has joined game " + game.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getName() + " has joined the game", MessageColor.BLACK);
|
||||
if (allJoined()) {
|
||||
ThreadExecutor.getInstance().getRMIExecutor().execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startGame();
|
||||
}
|
||||
});
|
||||
}
|
||||
checkStart();
|
||||
}
|
||||
|
||||
private synchronized void startGame() {
|
||||
|
@ -190,6 +188,18 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkStart() {
|
||||
if (allJoined()) {
|
||||
ThreadExecutor.getInstance().getRMIExecutor().execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startGame();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allJoined() {
|
||||
for (Player player: game.getPlayers().values()) {
|
||||
if (player.isHuman() && gameSessions.get(player.getId()) == null) {
|
||||
|
|
|
@ -117,11 +117,11 @@ public class GameManager {
|
|||
return gameControllers.get(gameId).cheat(sessionId, playerId, cardName);
|
||||
}
|
||||
|
||||
void timeout(UUID gameId, UUID sessionId) {
|
||||
public void timeout(UUID gameId, UUID sessionId) {
|
||||
gameControllers.get(gameId).timeout(sessionId);
|
||||
}
|
||||
|
||||
void removeGame(UUID gameId) {
|
||||
public void removeGame(UUID gameId) {
|
||||
gameControllers.remove(gameId);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,12 +28,13 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import mage.server.Room;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.view.TableView;
|
||||
|
||||
/**
|
||||
|
@ -44,9 +45,9 @@ public interface GamesRoom extends Room {
|
|||
|
||||
public List<TableView> getTables();
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException;
|
||||
public boolean joinDraftTable(UUID sessionId, UUID tableId, String name) throws GameException;
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name) throws GameException;
|
||||
public TableView createTable(UUID sessionId, MatchOptions options);
|
||||
public TableView createDraftTable(UUID sessionId, DraftOptions options);
|
||||
public TableView createTournamentTable(UUID sessionId, TournamentOptions options);
|
||||
public void removeTable(UUID sessionId, UUID tableId);
|
||||
public TableView getTable(UUID tableId);
|
||||
public void leaveTable(UUID sessionId, UUID tableId);
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import mage.server.TableManager;
|
||||
import mage.server.RoomImpl;
|
||||
import mage.game.Table;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -39,6 +41,7 @@ import mage.cards.decks.DeckCardLists;
|
|||
import mage.game.GameException;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.util.Logging;
|
||||
import mage.view.TableView;
|
||||
|
||||
|
@ -78,17 +81,17 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinDraftTable(UUID sessionId, UUID tableId, String name) throws GameException {
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name) throws GameException {
|
||||
if (tables.containsKey(tableId)) {
|
||||
return TableManager.getInstance().joinDraft(sessionId, tableId, name);
|
||||
return TableManager.getInstance().joinTournament(sessionId, tableId, name);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableView createDraftTable(UUID sessionId, DraftOptions options) {
|
||||
Table table = TableManager.getInstance().createDraftTable(sessionId, options);
|
||||
public TableView createTournamentTable(UUID sessionId, TournamentOptions options) {
|
||||
Table table = TableManager.getInstance().createTournamentTable(sessionId, options);
|
||||
tables.put(table.getId(), table);
|
||||
return new TableView(table);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import mage.server.TableManager;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import mage.game.Game;
|
||||
|
|
|
@ -0,0 +1,214 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.tournament;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.game.GameException;
|
||||
import mage.game.Table;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentPairing;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
import mage.server.ChatManager;
|
||||
import mage.server.TableManager;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.util.Logging;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
import mage.view.TournamentView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentController {
|
||||
|
||||
private final static Logger logger = Logging.getLogger(TournamentController.class.getName());
|
||||
|
||||
private UUID sessionId;
|
||||
private UUID chatId;
|
||||
private UUID tableId;
|
||||
private Tournament tournament;
|
||||
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
|
||||
private ConcurrentHashMap<UUID, TournamentSession> tournamentSessions = new ConcurrentHashMap<UUID, TournamentSession>();
|
||||
|
||||
public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
|
||||
sessionId = UUID.randomUUID();
|
||||
this.sessionPlayerMap = sessionPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.tournament = tournament;
|
||||
this.tableId = tableId;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
tournament.addTableEventListener(
|
||||
new Listener<TableEvent> () {
|
||||
@Override
|
||||
public void event(TableEvent event) {
|
||||
switch (event.getEventType()) {
|
||||
case INFO:
|
||||
ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK);
|
||||
logger.finest(tournament.getId() + " " + event.getMessage());
|
||||
break;
|
||||
case CONSTRUCT:
|
||||
construct();
|
||||
break;
|
||||
case START_DRAFT:
|
||||
startDraft(event.getDraft());
|
||||
break;
|
||||
case START_MATCH:
|
||||
startMatch(event.getPair(), event.getMatchOptions());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
for (TournamentPlayer player: tournament.getPlayers()) {
|
||||
if (!player.getPlayer().isHuman()) {
|
||||
player.setJoined();
|
||||
logger.info("player " + player.getPlayer().getId() + " has joined tournament " + tournament.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getName() + " has joined the tournament", MessageColor.BLACK);
|
||||
}
|
||||
}
|
||||
checkStart();
|
||||
}
|
||||
|
||||
public void join(UUID sessionId) {
|
||||
UUID playerId = sessionPlayerMap.get(sessionId);
|
||||
TournamentSession tournamentSession = new TournamentSession(tournament, sessionId, playerId);
|
||||
tournamentSessions.put(playerId, tournamentSession);
|
||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
player.setJoined();
|
||||
logger.info("player " + playerId + " has joined tournament " + tournament.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getName() + " has joined the tournament", MessageColor.BLACK);
|
||||
checkStart();
|
||||
}
|
||||
|
||||
private void checkStart() {
|
||||
if (allJoined()) {
|
||||
ThreadExecutor.getInstance().getRMIExecutor().execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startTournament();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allJoined() {
|
||||
if (!tournament.allJoined())
|
||||
return false;
|
||||
for (TournamentPlayer player: tournament.getPlayers()) {
|
||||
if (player.getPlayer().isHuman() && tournamentSessions.get(player.getPlayer().getId()) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private synchronized void startTournament() {
|
||||
for (final Entry<UUID, TournamentSession> entry: tournamentSessions.entrySet()) {
|
||||
if (!entry.getValue().init(getTournamentView())) {
|
||||
logger.severe("Unable to initialize client");
|
||||
//TODO: generate client error message
|
||||
return;
|
||||
}
|
||||
}
|
||||
tournament.nextStep();
|
||||
}
|
||||
|
||||
private void startMatch(TournamentPairing pair, MatchOptions matchOptions) {
|
||||
try {
|
||||
TableManager tableManager = TableManager.getInstance();
|
||||
Table table = tableManager.createTable(sessionId, matchOptions);
|
||||
TournamentPlayer player1 = pair.getPlayer1();
|
||||
TournamentPlayer player2 = pair.getPlayer2();
|
||||
tableManager.addPlayer(getPlayerSessionId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getDeck());
|
||||
tableManager.addPlayer(getPlayerSessionId(player2.getPlayer().getId()), table.getId(), player2.getPlayer(), player2.getDeck());
|
||||
tableManager.startMatch(sessionId, null, table.getId());
|
||||
pair.setMatch(tableManager.getMatch(table.getId()));
|
||||
} catch (GameException ex) {
|
||||
Logger.getLogger(TournamentController.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void startDraft(Draft draft) {
|
||||
TableManager.getInstance().startDraft(tableId, draft);
|
||||
}
|
||||
|
||||
private void construct() {
|
||||
TableManager.getInstance().construct(tableId);
|
||||
}
|
||||
|
||||
public UUID getSessionId() {
|
||||
return this.sessionId;
|
||||
}
|
||||
|
||||
public UUID getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
||||
public void kill(UUID sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
tournamentSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
|
||||
tournamentSessions.remove(sessionPlayerMap.get(sessionId));
|
||||
leave(sessionId);
|
||||
sessionPlayerMap.remove(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
private void leave(UUID sessionId) {
|
||||
tournament.leave(getPlayerId(sessionId));
|
||||
}
|
||||
|
||||
private UUID getPlayerId(UUID sessionId) {
|
||||
return sessionPlayerMap.get(sessionId);
|
||||
}
|
||||
|
||||
private UUID getPlayerSessionId(UUID playerId) {
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId))
|
||||
return entry.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TournamentView getTournamentView() {
|
||||
return new TournamentView(tournament);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.tournament;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.game.tournament.TournamentType;
|
||||
import mage.util.Logging;
|
||||
import mage.view.TournamentTypeView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentFactory {
|
||||
private final static TournamentFactory INSTANCE = new TournamentFactory();
|
||||
private final static Logger logger = Logging.getLogger(TournamentFactory.class.getName());
|
||||
|
||||
private Map<String, Class<Tournament>> tournaments = new HashMap<String, Class<Tournament>>();
|
||||
private Map<String, TournamentType> tournamentTypes = new HashMap<String, TournamentType>();
|
||||
private List<TournamentTypeView> tournamentTypeViews = new ArrayList<TournamentTypeView>();
|
||||
|
||||
public static TournamentFactory getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private TournamentFactory() {}
|
||||
|
||||
public Tournament createTournament(String tournamentType, TournamentOptions options) {
|
||||
|
||||
Tournament tournament;
|
||||
Constructor<Tournament> con;
|
||||
try {
|
||||
con = tournaments.get(tournamentType).getConstructor(new Class[]{TournamentOptions.class});
|
||||
tournament = con.newInstance(new Object[] {options});
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
return null;
|
||||
}
|
||||
logger.info("Tournament created: " + tournamentType); // + game.getId().toString());
|
||||
|
||||
return tournament;
|
||||
}
|
||||
|
||||
public List<TournamentTypeView> getTournamentTypes() {
|
||||
return tournamentTypeViews;
|
||||
}
|
||||
|
||||
|
||||
public void addTournamentType(String name, TournamentType tournamentType, Class tournament) {
|
||||
if (tournament != null) {
|
||||
this.tournaments.put(name, tournament);
|
||||
this.tournamentTypes.put(name, tournamentType);
|
||||
this.tournamentTypeViews.add(new TournamentTypeView(tournamentType));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
|
@ -26,54 +26,47 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.game;
|
||||
package mage.server.tournament;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.util.Logging;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.view.TournamentView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class DraftFactory {
|
||||
public class TournamentManager {
|
||||
|
||||
private final static DraftFactory INSTANCE = new DraftFactory();
|
||||
private final static Logger logger = Logging.getLogger(DraftFactory.class.getName());
|
||||
private final static TournamentManager INSTANCE = new TournamentManager();
|
||||
|
||||
private Map<String, Class<Draft>> drafts = new HashMap<String, Class<Draft>>();
|
||||
private ConcurrentHashMap<UUID, TournamentController> controllers = new ConcurrentHashMap<UUID, TournamentController>();
|
||||
|
||||
public static DraftFactory getInstance() {
|
||||
public static TournamentManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private DraftFactory() {}
|
||||
|
||||
public Draft createDraft(String draftType, DraftOptions options) {
|
||||
|
||||
Draft draft;
|
||||
Constructor<Draft> con;
|
||||
try {
|
||||
con = drafts.get(draftType).getConstructor(new Class[]{DraftOptions.class});
|
||||
draft = con.newInstance(new Object[] {options});
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
return null;
|
||||
}
|
||||
logger.info("Draft created: " + draftType); // + game.getId().toString());
|
||||
|
||||
return draft;
|
||||
public UUID createTournamentSession(Tournament tournament, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
|
||||
TournamentController tournamentController = new TournamentController(tournament, sessionPlayerMap, tableId);
|
||||
controllers.put(tournament.getId(), tournamentController);
|
||||
return tournamentController.getSessionId();
|
||||
}
|
||||
|
||||
public void addDraftType(String name, Class draft) {
|
||||
if (draft != null) {
|
||||
this.drafts.put(name, draft);
|
||||
}
|
||||
public void joinTournament(UUID tournamentId, UUID sessionId) {
|
||||
controllers.get(tournamentId).join(sessionId);
|
||||
}
|
||||
|
||||
public void kill(UUID tournamentId, UUID sessionId) {
|
||||
controllers.get(tournamentId).kill(sessionId);
|
||||
}
|
||||
|
||||
public TournamentView getTournamentView(UUID tournamentId) {
|
||||
return controllers.get(tournamentId).getTournamentView();
|
||||
}
|
||||
|
||||
public UUID getChatId(UUID tournamentId) {
|
||||
return controllers.get(tournamentId).getChatId();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.tournament;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
import mage.util.Logging;
|
||||
import mage.view.TournamentView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentSession {
|
||||
protected final static Logger logger = Logging.getLogger(TournamentSession.class.getName());
|
||||
|
||||
protected UUID sessionId;
|
||||
protected UUID playerId;
|
||||
protected Tournament tournament;
|
||||
protected boolean killed = false;
|
||||
|
||||
public TournamentSession(Tournament tournament, UUID sessionId, UUID playerId) {
|
||||
this.sessionId = sessionId;
|
||||
this.tournament = tournament;
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
public boolean init(final TournamentView tournamentView) {
|
||||
if (!killed) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
session.clearAck();
|
||||
session.fireCallback(new ClientCallback("tournamentInit", tournamentView));
|
||||
if (waitForAck("tournamentInit"))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean waitForAck(String message) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
do {
|
||||
//TODO: add timeout
|
||||
} while (!session.getAckMessage().equals(message) && !killed);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void update(final TournamentView tournamentView) {
|
||||
if (!killed) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("tournamentUpdate", tournamentView));
|
||||
}
|
||||
}
|
||||
|
||||
public void gameOver(final String message) {
|
||||
if (!killed) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("tournamentOver", message));
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleRemoteException(RemoteException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
TournamentManager.getInstance().kill(tournament.getId(), sessionId);
|
||||
}
|
||||
|
||||
public void setKilled() {
|
||||
killed = true;
|
||||
}
|
||||
|
||||
}
|
|
@ -92,8 +92,8 @@ public class ConfigSettings {
|
|||
return config.getGameTypes().getGameType();
|
||||
}
|
||||
|
||||
public List<Plugin> getDraftTypes() {
|
||||
return config.getDraftTypes().getDraftType();
|
||||
public List<GamePlugin> getTournamentTypes() {
|
||||
return config.getTournamentTypes().getTournamentType();
|
||||
}
|
||||
|
||||
public List<Plugin> getDeckTypes() {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<xs:element ref="server"/>
|
||||
<xs:element ref="playerTypes"/>
|
||||
<xs:element ref="gameTypes"/>
|
||||
<xs:element ref="draftTypes"/>
|
||||
<xs:element ref="tournamentTypes"/>
|
||||
<xs:element ref="deckTypes"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
@ -54,10 +54,10 @@
|
|||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="draftTypes">
|
||||
<xs:element name="tournamentTypes">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="draftType" type="plugin" maxOccurs="unbounded"/>
|
||||
<xs:element name="tournamentType" type="gamePlugin" maxOccurs="unbounded"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
<gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/>
|
||||
<gameType name="Free For All" jar="mage-game-freeforall.jar" className="mage.game.FreeForAllMatch" typeName="mage.game.FreeForAllType"/>
|
||||
</gameTypes>
|
||||
<draftTypes>
|
||||
<draftType name="8 Player Booster" jar="mage-draft-8playerbooster.jar" className="mage.draft.BoosterDraft"/>
|
||||
</draftTypes>
|
||||
<tournamentTypes>
|
||||
<tournamentType name="Booster Draft" jar="mage-tournament-booster-draft.jar" className="mage.tournament.BoosterDraftEliminationTournament" typeName="mage.tournament.BoosterDraftEliminationTournamentType"/>
|
||||
</tournamentTypes>
|
||||
<deckTypes>
|
||||
<deckType name="Constructed" jar="mage-deck-constructed.jar" className="mage.deck.Constructed"/>
|
||||
<deckType name="Limited" jar="mage-deck-limited.jar" className="mage.deck.Limited"/>
|
||||
|
|
|
@ -26,10 +26,7 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.draft;
|
||||
|
||||
import mage.game.draft.DraftImpl;
|
||||
import mage.game.draft.DraftOptions;
|
||||
package mage.game.draft;
|
||||
|
||||
/**
|
||||
*
|
|
@ -53,9 +53,9 @@ public interface Draft extends MageItem, Serializable {
|
|||
public int getCardNum();
|
||||
public void addPick(UUID playerId, UUID cardId);
|
||||
public void start();
|
||||
public boolean allJoined();
|
||||
public void leave(UUID playerId);
|
||||
public void autoPick(UUID playerId);
|
||||
public boolean isDoneConstructing();
|
||||
|
||||
public void addTableEventListener(Listener<TableEvent> listener);
|
||||
public void fireUpdatePlayersEvent();
|
||||
|
|
|
@ -33,8 +33,6 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.game.draft.DraftOptions.TimingOption;
|
||||
|
@ -177,12 +175,11 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
|||
player.setPicking();
|
||||
player.getPlayer().pickCard(player.getBooster(), player.getDeck(), this);
|
||||
}
|
||||
while (!donePicking()) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(DraftImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
break;
|
||||
synchronized(this) {
|
||||
while (!donePicking()) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException ex) { }
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -190,7 +187,16 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
|||
|
||||
protected boolean donePicking() {
|
||||
for (DraftPlayer player: players.values()) {
|
||||
if (player.picking)
|
||||
if (player.isPicking())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allJoined() {
|
||||
for (DraftPlayer player: this.players.values()) {
|
||||
if (!player.isJoined())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -235,19 +241,9 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void startTournament() {
|
||||
//TODO: implement this
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDoneConstructing() {
|
||||
for (DraftPlayer player: this.players.values()) {
|
||||
if (!player.isDoneConstructing())
|
||||
return false;
|
||||
synchronized(this) {
|
||||
this.notifyAll();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,10 +39,8 @@ import mage.cards.ExpansionSet;
|
|||
*/
|
||||
public class DraftOptions implements Serializable {
|
||||
|
||||
protected String name;
|
||||
protected String draftType;
|
||||
protected List<ExpansionSet> sets = new ArrayList<ExpansionSet>();
|
||||
protected List<String> playerTypes = new ArrayList<String>();
|
||||
protected TimingOption timing;
|
||||
|
||||
public enum TimingOption {
|
||||
|
@ -61,22 +59,10 @@ public class DraftOptions implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public DraftOptions(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<ExpansionSet> getSets() {
|
||||
return sets;
|
||||
}
|
||||
|
||||
public List<String> getPlayerTypes() {
|
||||
return playerTypes;
|
||||
}
|
||||
|
||||
public String getDraftType() {
|
||||
return draftType;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class DraftPlayer {
|
|||
protected Deck deck;
|
||||
protected List<Card> booster;
|
||||
protected boolean picking;
|
||||
protected boolean doneConstructing;
|
||||
protected boolean joined = false;
|
||||
|
||||
public DraftPlayer(Player player) {
|
||||
id = UUID.randomUUID();
|
||||
|
@ -92,17 +92,12 @@ public class DraftPlayer {
|
|||
return picking;
|
||||
}
|
||||
|
||||
public void setConstructing() {
|
||||
this.doneConstructing = false;
|
||||
public boolean isJoined() {
|
||||
return joined;
|
||||
}
|
||||
|
||||
public void submitDeck(Deck deck) {
|
||||
this.deck = deck;
|
||||
this.doneConstructing = true;
|
||||
}
|
||||
|
||||
public boolean isDoneConstructing() {
|
||||
return this.doneConstructing;
|
||||
public void setJoined() {
|
||||
this.joined = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ import mage.cards.Cards;
|
|||
import mage.cards.decks.Deck;
|
||||
import mage.game.Game;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentPairing;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -43,8 +45,7 @@ import mage.game.draft.Draft;
|
|||
public class TableEvent extends EventObject implements ExternalEvent, Serializable {
|
||||
|
||||
public enum EventType {
|
||||
UPDATE, INFO, REVEAL, LOOK, SIDEBOARD, CONSTRUCT, SUBMIT_DECK, END
|
||||
}
|
||||
UPDATE, INFO, REVEAL, LOOK, START_DRAFT, START_MATCH, SIDEBOARD, CONSTRUCT, SUBMIT_DECK, END}
|
||||
|
||||
private Game game;
|
||||
private Draft draft;
|
||||
|
@ -53,6 +54,13 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
|
|||
private Cards cards;
|
||||
private UUID playerId;
|
||||
private Deck deck;
|
||||
private TournamentPairing pair;
|
||||
private MatchOptions options;
|
||||
|
||||
public TableEvent(EventType eventType) {
|
||||
super(eventType);
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
public TableEvent(EventType eventType, String message, Cards cards, Game game) {
|
||||
super(game);
|
||||
|
@ -76,6 +84,13 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
|
|||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
public TableEvent(EventType eventType, TournamentPairing pair, MatchOptions options) {
|
||||
super(options);
|
||||
this.pair = pair;
|
||||
this.options = options;
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
@ -103,4 +118,12 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
|
|||
public Deck getDeck() {
|
||||
return deck;
|
||||
}
|
||||
|
||||
public TournamentPairing getPair() {
|
||||
return pair;
|
||||
}
|
||||
|
||||
public MatchOptions getMatchOptions() {
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ import mage.cards.decks.Deck;
|
|||
import mage.game.Game;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.events.TableEvent.EventType;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentPairing;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -49,6 +51,10 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
|
|||
dispatcher.addListener(listener);
|
||||
}
|
||||
|
||||
public void fireTableEvent(EventType eventType) {
|
||||
dispatcher.fireEvent(new TableEvent(eventType));
|
||||
}
|
||||
|
||||
public void fireTableEvent(EventType eventType, String message, Game game) {
|
||||
dispatcher.fireEvent(new TableEvent(eventType, message, null, game));
|
||||
}
|
||||
|
@ -64,4 +70,8 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
|
|||
public void fireTableEvent(EventType eventType, UUID playerId, Deck deck) {
|
||||
dispatcher.fireEvent(new TableEvent(eventType, playerId, deck));
|
||||
}
|
||||
|
||||
public void fireTableEvent(EventType eventType, TournamentPairing pair, MatchOptions options) {
|
||||
dispatcher.fireEvent(new TableEvent(eventType, pair, options));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,8 @@ public interface Match {
|
|||
public void startGame() throws GameException;
|
||||
public void endGame();
|
||||
public Game getGame();
|
||||
public List<Game> getGames();
|
||||
public int getWinsNeeded();
|
||||
public int getNumGames();
|
||||
public boolean isDoneSideboarding();
|
||||
public UUID getChooser();
|
||||
|
|
|
@ -31,20 +31,24 @@ package mage.game.match;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameException;
|
||||
import mage.players.Player;
|
||||
import mage.util.Logging;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public abstract class MatchImpl<T extends Game> implements Match {
|
||||
public abstract class MatchImpl implements Match {
|
||||
|
||||
private final static Logger logger = Logging.getLogger(MatchImpl.class.getName());
|
||||
|
||||
protected UUID id = UUID.randomUUID();
|
||||
protected List<MatchPlayer> players = new ArrayList<MatchPlayer>();
|
||||
protected List<T> games = new ArrayList<T>();
|
||||
protected List<Game> games = new ArrayList<Game>();
|
||||
protected MatchOptions options;
|
||||
|
||||
public MatchImpl(MatchOptions options) {
|
||||
|
@ -92,15 +96,25 @@ public abstract class MatchImpl<T extends Game> implements Match {
|
|||
}
|
||||
|
||||
@Override
|
||||
public T getGame() {
|
||||
public Game getGame() {
|
||||
return games.get(games.size() -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Game> getGames() {
|
||||
return games;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumGames() {
|
||||
return games.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWinsNeeded() {
|
||||
return options.getWinsNeeded();
|
||||
}
|
||||
|
||||
protected void initGame(Game game) throws GameException {
|
||||
for (MatchPlayer matchPlayer: this.players) {
|
||||
game.loadCards(matchPlayer.getDeck().getCards(), matchPlayer.getPlayer().getId());
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
package mage.game.match;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.Constants.MultiplayerAttackOption;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -30,8 +30,7 @@ package mage.game.tournament;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import mage.game.match.Match;
|
||||
import mage.players.Player;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -40,15 +39,39 @@ import mage.players.Player;
|
|||
public class Round {
|
||||
|
||||
private int roundNum;
|
||||
private List<Match> matches = new ArrayList<Match>();
|
||||
private List<TournamentPairing> pairs = new ArrayList<TournamentPairing>();
|
||||
|
||||
public Round(int roundNum, List<Player> players) {
|
||||
public Round(int roundNum) {
|
||||
this.roundNum = roundNum;
|
||||
|
||||
}
|
||||
|
||||
public List<Match> getMatches() {
|
||||
return matches;
|
||||
public void addPairing(TournamentPairing match) {
|
||||
this.pairs.add(match);
|
||||
}
|
||||
|
||||
public TournamentPairing getPairing(UUID pairId) {
|
||||
for (TournamentPairing pair: pairs) {
|
||||
if (pair.getId().equals(pairId)) {
|
||||
return pair;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<TournamentPairing> getPairs() {
|
||||
return pairs;
|
||||
}
|
||||
|
||||
public int getRoundNumber() {
|
||||
return this.roundNum;
|
||||
}
|
||||
|
||||
public boolean isRoundOver() {
|
||||
for (TournamentPairing pair: pairs) {
|
||||
if (!pair.getMatch().isMatchOver()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,12 +28,30 @@
|
|||
|
||||
package mage.game.tournament;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface Tournament {
|
||||
|
||||
public void playRound();
|
||||
public UUID getId();
|
||||
public void addPlayer(Player player, String playerType);
|
||||
public TournamentPlayer getPlayer(UUID playerId);
|
||||
public Collection<TournamentPlayer> getPlayers();
|
||||
public Collection<Round> getRounds();
|
||||
public void submitDeck(UUID playerId, Deck deck);
|
||||
public boolean allJoined();
|
||||
public boolean isDoneConstructing();
|
||||
public void leave(UUID playerId);
|
||||
public void nextStep();
|
||||
|
||||
public void addTableEventListener(Listener<TableEvent> listener);
|
||||
|
||||
}
|
||||
|
|
|
@ -29,24 +29,191 @@
|
|||
package mage.game.tournament;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.events.TableEvent.EventType;
|
||||
import mage.game.events.TableEventSource;
|
||||
import mage.game.match.Match;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentImpl implements Tournament {
|
||||
public abstract class TournamentImpl implements Tournament {
|
||||
|
||||
List<Round> rounds = new ArrayList<Round>();
|
||||
List<Player> players = new ArrayList<Player>();
|
||||
protected UUID id = UUID.randomUUID();
|
||||
protected List<Round> rounds = new CopyOnWriteArrayList<Round>();
|
||||
protected Map<UUID, TournamentPlayer> players = new HashMap<UUID, TournamentPlayer>();
|
||||
protected static Random rnd = new Random();
|
||||
protected String matchName;
|
||||
protected TournamentOptions options;
|
||||
|
||||
protected transient TableEventSource tableEventSource = new TableEventSource();
|
||||
|
||||
public TournamentImpl(TournamentOptions options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playRound() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
protected void createRound() {
|
||||
@Override
|
||||
public void addPlayer(Player player, String playerType) {
|
||||
players.put(player.getId(), new TournamentPlayer(player, playerType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TournamentPlayer getPlayer(UUID playerId) {
|
||||
return players.get(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<TournamentPlayer> getPlayers() {
|
||||
return players.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Round> getRounds() {
|
||||
return rounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leave(UUID playerId) {
|
||||
//TODO: implement this
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitDeck(UUID playerId, Deck deck) {
|
||||
if (players.containsKey(playerId)) {
|
||||
players.get(playerId).submitDeck(deck);
|
||||
}
|
||||
synchronized (this) {
|
||||
this.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
protected Round createRoundRandom() {
|
||||
Round round = new Round(rounds.size() + 1);
|
||||
rounds.add(round);
|
||||
List<TournamentPlayer> roundPlayers = getActivePlayers();
|
||||
while (roundPlayers.size() > 1) {
|
||||
int i = rnd.nextInt(roundPlayers.size());
|
||||
TournamentPlayer player1 = roundPlayers.get(i);
|
||||
roundPlayers.remove(i);
|
||||
i = rnd.nextInt(roundPlayers.size());
|
||||
TournamentPlayer player2 = roundPlayers.get(i);
|
||||
roundPlayers.remove(i);
|
||||
round.addPairing(new TournamentPairing(player1, player2));
|
||||
}
|
||||
return round;
|
||||
}
|
||||
|
||||
protected void playRound(Round round) {
|
||||
for (TournamentPairing pair: round.getPairs()) {
|
||||
playMatch(pair);
|
||||
}
|
||||
|
||||
while (!round.isRoundOver()) {
|
||||
try {
|
||||
//TODO: improve this
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(TournamentImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
updateResults();
|
||||
}
|
||||
|
||||
protected List<TournamentPlayer> getActivePlayers() {
|
||||
List<TournamentPlayer> activePlayers = new ArrayList<TournamentPlayer>();
|
||||
for (TournamentPlayer player: players.values()) {
|
||||
if (!player.getEliminated()) {
|
||||
activePlayers.add(player);
|
||||
}
|
||||
}
|
||||
return activePlayers;
|
||||
}
|
||||
|
||||
protected void updateResults() {
|
||||
for (TournamentPlayer player: players.values()) {
|
||||
player.setResults("");
|
||||
}
|
||||
for (Round round: rounds) {
|
||||
for (TournamentPairing pair: round.getPairs()) {
|
||||
UUID player1Id = pair.getPlayer1().getPlayer().getId();
|
||||
UUID player2Id = pair.getPlayer2().getPlayer().getId();
|
||||
Match match = pair.getMatch();
|
||||
StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults());
|
||||
StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults());
|
||||
sb1.append(pair.getPlayer2().getPlayer().getName());
|
||||
sb1.append(" (").append(match.getPlayer(player1Id).getWins());
|
||||
sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(") ");
|
||||
sb2.append(pair.getPlayer1().getPlayer().getName());
|
||||
sb2.append(" (").append(match.getPlayer(player2Id).getWins());
|
||||
sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") ");
|
||||
players.get(player1Id).setResults(sb1.toString());
|
||||
players.get(player2Id).setResults(sb2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDoneConstructing() {
|
||||
for (TournamentPlayer player: this.players.values()) {
|
||||
if (!player.isDoneConstructing())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allJoined() {
|
||||
for (TournamentPlayer player: this.players.values()) {
|
||||
if (!player.isJoined())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTableEventListener(Listener<TableEvent> listener) {
|
||||
tableEventSource.addListener(listener);
|
||||
}
|
||||
|
||||
public void construct() {
|
||||
tableEventSource.fireTableEvent(EventType.CONSTRUCT);
|
||||
synchronized(this) {
|
||||
while (!isDoneConstructing()) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException ex) { }
|
||||
}
|
||||
}
|
||||
nextStep();
|
||||
}
|
||||
|
||||
public void playMatch(TournamentPairing pair) {
|
||||
options.getMatchOptions().getPlayerTypes().clear();
|
||||
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer1().getPlayerType());
|
||||
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer2().getPlayerType());
|
||||
tableEventSource.fireTableEvent(EventType.START_MATCH, pair, options.getMatchOptions());
|
||||
}
|
||||
|
||||
protected abstract void runTournament();
|
||||
|
||||
}
|
||||
|
|
77
Mage/src/mage/game/tournament/TournamentOptions.java
Normal file
77
Mage/src/mage/game/tournament/TournamentOptions.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* 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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import mage.game.draft.DraftOptions;
|
||||
import mage.game.match.MatchOptions;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentOptions implements Serializable {
|
||||
|
||||
protected String name;
|
||||
protected String tournamentType;
|
||||
protected List<String> playerTypes = new ArrayList<String>();
|
||||
protected MatchOptions matchOptions = new MatchOptions("", "Two Player Duel");
|
||||
protected DraftOptions draftOptions = new DraftOptions();
|
||||
|
||||
public TournamentOptions(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getTournamentType() {
|
||||
return tournamentType;
|
||||
}
|
||||
|
||||
public void setTournamentType(String tournamentType) {
|
||||
this.tournamentType = tournamentType;
|
||||
}
|
||||
|
||||
public List<String> getPlayerTypes() {
|
||||
return playerTypes;
|
||||
}
|
||||
|
||||
public MatchOptions getMatchOptions() {
|
||||
return matchOptions;
|
||||
}
|
||||
|
||||
public DraftOptions getDraftOptions() {
|
||||
return draftOptions;
|
||||
}
|
||||
|
||||
}
|
78
Mage/src/mage/game/tournament/TournamentPairing.java
Normal file
78
Mage/src/mage/game/tournament/TournamentPairing.java
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* 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.util.UUID;
|
||||
import mage.game.match.Match;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentPairing {
|
||||
|
||||
UUID id = UUID.randomUUID();
|
||||
Match match;
|
||||
TournamentPlayer player1;
|
||||
TournamentPlayer player2;
|
||||
|
||||
public TournamentPairing(TournamentPlayer player1, TournamentPlayer player2) {
|
||||
this.player1 = player1;
|
||||
this.player2 = player2;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public TournamentPlayer getPlayer1() {
|
||||
return this.player1;
|
||||
}
|
||||
|
||||
public TournamentPlayer getPlayer2() {
|
||||
return this.player2;
|
||||
}
|
||||
|
||||
public Match getMatch() {
|
||||
return match;
|
||||
}
|
||||
|
||||
public void setMatch(Match match) {
|
||||
this.match = match;
|
||||
}
|
||||
|
||||
public void eliminatePlayers() {
|
||||
if (match.getPlayer(player1.getPlayer().getId()).getWins() < match.getWinsNeeded()) {
|
||||
player1.setEliminated();
|
||||
}
|
||||
if (match.getPlayer(player2.getPlayer().getId()).getWins() < match.getWinsNeeded()) {
|
||||
player2.setEliminated();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.game.tournament;
|
||||
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
|
@ -38,16 +39,31 @@ public class TournamentPlayer {
|
|||
|
||||
protected int points;
|
||||
protected String name;
|
||||
protected String playerType;
|
||||
protected Player player;
|
||||
protected Deck deck;
|
||||
protected String results = "";
|
||||
protected boolean eliminated = false;
|
||||
protected boolean doneConstructing;
|
||||
protected boolean joined = false;
|
||||
|
||||
public TournamentPlayer(Player player) {
|
||||
public TournamentPlayer(Player player, String playerType) {
|
||||
this.player = player;
|
||||
this.playerType = playerType;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getPlayerType() {
|
||||
return playerType;
|
||||
}
|
||||
|
||||
public Deck getDeck() {
|
||||
return deck;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
@ -56,4 +72,44 @@ public class TournamentPlayer {
|
|||
this.points = points;
|
||||
}
|
||||
|
||||
public boolean getEliminated() {
|
||||
return eliminated;
|
||||
}
|
||||
|
||||
public void setEliminated() {
|
||||
this.eliminated = true;
|
||||
}
|
||||
|
||||
public boolean isJoined() {
|
||||
return joined;
|
||||
}
|
||||
|
||||
public void setJoined() {
|
||||
this.joined = true;
|
||||
}
|
||||
|
||||
public void setConstructing() {
|
||||
this.doneConstructing = false;
|
||||
}
|
||||
|
||||
public void submitDeck(Deck deck) {
|
||||
this.deck = deck;
|
||||
this.doneConstructing = true;
|
||||
}
|
||||
|
||||
public boolean isDoneConstructing() {
|
||||
return this.doneConstructing;
|
||||
}
|
||||
|
||||
public void setDeck(Deck deck) {
|
||||
this.deck = deck;
|
||||
}
|
||||
|
||||
public String getResults() {
|
||||
return this.results;
|
||||
}
|
||||
|
||||
public void setResults(String results) {
|
||||
this.results = results;
|
||||
}
|
||||
}
|
||||
|
|
41
Mage/src/mage/game/tournament/TournamentSealedOptions.java
Normal file
41
Mage/src/mage/game/tournament/TournamentSealedOptions.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.game.tournament;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentSealedOptions extends TournamentOptions {
|
||||
|
||||
public TournamentSealedOptions(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.game.tournament;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public abstract class TournamentSingleElimination extends TournamentImpl {
|
||||
|
||||
public TournamentSingleElimination(TournamentOptions options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTournament() {
|
||||
while (this.getActivePlayers().size() > 1) {
|
||||
Round round = createRoundRandom();
|
||||
playRound(round);
|
||||
eliminatePlayers(round);
|
||||
}
|
||||
nextStep();
|
||||
}
|
||||
|
||||
private void eliminatePlayers(Round round) {
|
||||
for (TournamentPairing pair: round.getPairs()) {
|
||||
pair.eliminatePlayers();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
45
Mage/src/mage/game/tournament/TournamentSwiss.java
Normal file
45
Mage/src/mage/game/tournament/TournamentSwiss.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.game.tournament;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public abstract class TournamentSwiss extends TournamentImpl {
|
||||
|
||||
public TournamentSwiss(TournamentOptions options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTournament() {
|
||||
//TODO: implement this
|
||||
}
|
||||
|
||||
}
|
72
Mage/src/mage/game/tournament/TournamentType.java
Normal file
72
Mage/src/mage/game/tournament/TournamentType.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentType <T extends TournamentType<T>> implements Serializable {
|
||||
|
||||
protected String name;
|
||||
protected int minPlayers;
|
||||
protected int maxPlayers;
|
||||
protected int numBoosters;
|
||||
protected boolean draft;
|
||||
|
||||
protected TournamentType() {}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getMinPlayers() {
|
||||
return minPlayers;
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
public int getNumBoosters() {
|
||||
return numBoosters;
|
||||
}
|
||||
|
||||
public boolean isDraft() {
|
||||
return draft;
|
||||
}
|
||||
|
||||
}
|
219
src/mage/game/tournament/TournamentImpl.java
Normal file
219
src/mage/game/tournament/TournamentImpl.java
Normal file
|
@ -0,0 +1,219 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* 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.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.events.TableEvent.EventType;
|
||||
import mage.game.events.TableEventSource;
|
||||
import mage.game.match.Match;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public abstract class TournamentImpl implements Tournament {
|
||||
|
||||
protected UUID id = UUID.randomUUID();
|
||||
protected List<Round> rounds = new CopyOnWriteArrayList<Round>();
|
||||
protected Map<UUID, TournamentPlayer> players = new HashMap<UUID, TournamentPlayer>();
|
||||
protected static Random rnd = new Random();
|
||||
protected String matchName;
|
||||
protected TournamentOptions options;
|
||||
|
||||
protected transient TableEventSource tableEventSource = new TableEventSource();
|
||||
|
||||
public TournamentImpl(TournamentOptions options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(Player player, String playerType) {
|
||||
players.put(player.getId(), new TournamentPlayer(player, playerType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TournamentPlayer getPlayer(UUID playerId) {
|
||||
return players.get(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<TournamentPlayer> getPlayers() {
|
||||
return players.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Round> getRounds() {
|
||||
return rounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leave(UUID playerId) {
|
||||
//TODO: implement this
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitDeck(UUID playerId, Deck deck) {
|
||||
if (players.containsKey(playerId)) {
|
||||
players.get(playerId).submitDeck(deck);
|
||||
}
|
||||
synchronized (this) {
|
||||
this.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
protected Round createRoundRandom() {
|
||||
Round round = new Round(rounds.size() + 1);
|
||||
rounds.add(round);
|
||||
List<TournamentPlayer> roundPlayers = getActivePlayers();
|
||||
while (roundPlayers.size() > 1) {
|
||||
int i = rnd.nextInt(roundPlayers.size());
|
||||
TournamentPlayer player1 = roundPlayers.get(i);
|
||||
roundPlayers.remove(i);
|
||||
i = rnd.nextInt(roundPlayers.size());
|
||||
TournamentPlayer player2 = roundPlayers.get(i);
|
||||
roundPlayers.remove(i);
|
||||
round.addPairing(new TournamentPairing(player1, player2));
|
||||
}
|
||||
return round;
|
||||
}
|
||||
|
||||
protected void playRound(Round round) {
|
||||
for (TournamentPairing pair: round.getPairs()) {
|
||||
playMatch(pair);
|
||||
}
|
||||
|
||||
while (!round.isRoundOver()) {
|
||||
try {
|
||||
//TODO: improve this
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(TournamentImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
updateResults();
|
||||
}
|
||||
|
||||
protected List<TournamentPlayer> getActivePlayers() {
|
||||
List<TournamentPlayer> activePlayers = new ArrayList<TournamentPlayer>();
|
||||
for (TournamentPlayer player: players.values()) {
|
||||
if (!player.getEliminated()) {
|
||||
activePlayers.add(player);
|
||||
}
|
||||
}
|
||||
return activePlayers;
|
||||
}
|
||||
|
||||
protected void updateResults() {
|
||||
for (TournamentPlayer player: players.values()) {
|
||||
player.setResults("");
|
||||
}
|
||||
for (Round round: rounds) {
|
||||
for (TournamentPairing pair: round.getPairs()) {
|
||||
UUID player1Id = pair.getPlayer1().getPlayer().getId();
|
||||
UUID player2Id = pair.getPlayer2().getPlayer().getId();
|
||||
Match match = pair.getMatch();
|
||||
StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults());
|
||||
StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults());
|
||||
sb1.append(pair.getPlayer2().getPlayer().getName());
|
||||
sb1.append(" (").append(match.getPlayer(player1Id).getWins());
|
||||
sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(")");
|
||||
sb2.append(pair.getPlayer1().getPlayer().getName());
|
||||
sb2.append(" (").append(match.getPlayer(player2Id).getWins());
|
||||
sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") ");
|
||||
players.get(player1Id).setResults(sb1.toString());
|
||||
players.get(player2Id).setResults(sb2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDoneConstructing() {
|
||||
for (TournamentPlayer player: this.players.values()) {
|
||||
if (!player.isDoneConstructing())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allJoined() {
|
||||
for (TournamentPlayer player: this.players.values()) {
|
||||
if (!player.isJoined())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTableEventListener(Listener<TableEvent> listener) {
|
||||
tableEventSource.addListener(listener);
|
||||
}
|
||||
|
||||
public void construct() {
|
||||
tableEventSource.fireTableEvent(EventType.CONSTRUCT);
|
||||
synchronized(this) {
|
||||
while (!isDoneConstructing()) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException ex) { }
|
||||
}
|
||||
}
|
||||
nextStep();
|
||||
}
|
||||
|
||||
public void playMatch(TournamentPairing pair) {
|
||||
options.getMatchOptions().getPlayerTypes().clear();
|
||||
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer1().getPlayerType());
|
||||
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer2().getPlayerType());
|
||||
tableEventSource.fireTableEvent(EventType.START_MATCH, pair, options.getMatchOptions());
|
||||
}
|
||||
|
||||
protected abstract void runTournament();
|
||||
|
||||
}
|
115
src/mage/game/tournament/TournamentPlayer.java
Normal file
115
src/mage/game/tournament/TournamentPlayer.java
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.game.tournament;
|
||||
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentPlayer {
|
||||
|
||||
protected int points;
|
||||
protected String name;
|
||||
protected String playerType;
|
||||
protected Player player;
|
||||
protected Deck deck;
|
||||
protected String results = "";
|
||||
protected boolean eliminated = false;
|
||||
protected boolean doneConstructing;
|
||||
protected boolean joined = false;
|
||||
|
||||
public TournamentPlayer(Player player, String playerType) {
|
||||
this.player = player;
|
||||
this.playerType = playerType;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getPlayerType() {
|
||||
return playerType;
|
||||
}
|
||||
|
||||
public Deck getDeck() {
|
||||
return deck;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public void setPoints(int points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public boolean getEliminated() {
|
||||
return eliminated;
|
||||
}
|
||||
|
||||
public void setEliminated() {
|
||||
this.eliminated = true;
|
||||
}
|
||||
|
||||
public boolean isJoined() {
|
||||
return joined;
|
||||
}
|
||||
|
||||
public void setJoined() {
|
||||
this.joined = true;
|
||||
}
|
||||
|
||||
public void setConstructing() {
|
||||
this.doneConstructing = false;
|
||||
}
|
||||
|
||||
public void submitDeck(Deck deck) {
|
||||
this.deck = deck;
|
||||
this.doneConstructing = true;
|
||||
}
|
||||
|
||||
public boolean isDoneConstructing() {
|
||||
return this.doneConstructing;
|
||||
}
|
||||
|
||||
public void setDeck(Deck deck) {
|
||||
this.deck = deck;
|
||||
}
|
||||
|
||||
public String getResults() {
|
||||
return this.results;
|
||||
}
|
||||
|
||||
public void setResults(String results) {
|
||||
this.results = results;
|
||||
}
|
||||
}
|
58
src/mage/game/tournament/TournamentSingleElimination.java
Normal file
58
src/mage/game/tournament/TournamentSingleElimination.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.game.tournament;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public abstract class TournamentSingleElimination extends TournamentImpl {
|
||||
|
||||
public TournamentSingleElimination(TournamentOptions options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTournament() {
|
||||
while (this.getActivePlayers().size() > 1) {
|
||||
Round round = createRoundRandom();
|
||||
playRound(round);
|
||||
eliminatePlayers(round);
|
||||
}
|
||||
nextStep();
|
||||
}
|
||||
|
||||
private void eliminatePlayers(Round round) {
|
||||
for (TournamentPairing pair: round.getPairs()) {
|
||||
pair.eliminatePlayers();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue