fixed multi-human drafting

This commit is contained in:
BetaSteward 2011-02-08 11:34:28 -05:00
parent 5a785b9330
commit e2fd0299c7
31 changed files with 160 additions and 107 deletions

View file

@ -242,8 +242,10 @@ public class MageFrame extends javax.swing.JFrame {
public void run() {
if (autoConnect())
enableButtons();
else
else {
disableButtons();
connectDialog.showDialog();
}
}
});
}

View file

@ -449,8 +449,8 @@ public class DeckEditorPanel extends javax.swing.JPanel {
}//GEN-LAST:event_btnImportActionPerformed
private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {
MageFrame.getSession().submitDeck(tableId, deck.getDeckCardLists());
this.setVisible(false);
if (MageFrame.getSession().submitDeck(tableId, deck.getDeckCardLists()))
this.setVisible(false);
}
private void btnAddLandActionPerformed(java.awt.event.ActionEvent evt) {

View file

@ -40,9 +40,7 @@ import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import mage.cards.decks.DeckCardLists;
import mage.client.remote.Session;
import mage.client.util.PhaseManager;
import mage.sets.Sets;
import mage.util.Logging;
@ -138,7 +136,7 @@ public class JoinTableDialog extends MageDialog {
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
Session session = MageFrame.getSession();
try {
joined = session.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), Sets.loadDeck(this.newPlayerPanel.getDeckFile()));
joined = session.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), "Human", Sets.loadDeck(this.newPlayerPanel.getDeckFile()));
} catch (Exception ex) {
handleError(ex);
}

View file

@ -310,7 +310,7 @@ public class NewTableDialog extends MageDialog {
options.setWinsNeeded((Integer)this.spnNumWins.getValue());
table = session.createTable(roomId, options);
try {
if (session.joinTable(roomId, table.getTableId(), this.player1Panel.getPlayerName(), Sets.loadDeck(this.player1Panel.getDeckFile()))) {
if (session.joinTable(roomId, table.getTableId(), this.player1Panel.getPlayerName(), "Human", Sets.loadDeck(this.player1Panel.getDeckFile()))) {
for (TablePlayerPanel player: players) {
if (!player.getPlayerType().equals("Human")) {
if (!player.joinTable(roomId, table.getTableId())) {

View file

@ -59,7 +59,7 @@
<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"/>
<Component id="pnlPacks" pref="49" 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"/>
@ -164,7 +164,7 @@
<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"/>
<Component id="pnlOtherPlayers" pref="60" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>

View file

@ -259,7 +259,7 @@ public class NewTournamentDialog extends MageDialog {
tOptions.getMatchOptions().setAttackOption(MultiplayerAttackOption.LEFT);
tOptions.getMatchOptions().setRange(RangeOfInfluence.ALL);
table = session.createTournamentTable(roomId, tOptions);
if (session.joinTournamentTable(roomId, table.getTableId(), this.txtPlayer1Name.getText())) {
if (session.joinTournamentTable(roomId, table.getTableId(), this.txtPlayer1Name.getText(), "Human")) {
for (TournamentPlayerPanel player: players) {
if (!player.getPlayerType().equals("Human")) {
if (!player.joinTournamentTable(roomId, table.getTableId())) {

View file

@ -87,14 +87,14 @@ public class TableWaitingDialog extends MageDialog implements Observer {
this.btnMoveDown.setEnabled(true);
this.btnMoveUp.setEnabled(true);
break;
case DUELING:
closeDialog();
return;
default:
case WAITING:
this.btnStart.setEnabled(false);
this.btnMoveDown.setEnabled(false);
this.btnMoveUp.setEnabled(false);
break;
default:
closeDialog();
return;
}
int row = this.tableSeats.getSelectedRow();
tableWaitModel.loadData(table);

View file

@ -89,6 +89,11 @@
<Component id="chkPack1" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="lblMessage" pref="236" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -119,7 +124,9 @@
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="txtTimeRemaining" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="41" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblMessage" pref="29" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="bigCard" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
@ -192,6 +199,11 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblMessage">
<Properties>
<Property name="horizontalAlignment" type="int" value="0"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="mage.client.cards.DraftGrid" name="draftBooster">

View file

@ -56,6 +56,7 @@ public class DraftPanel extends javax.swing.JPanel {
private Session session;
private Timer countdown;
private int timeout;
private boolean picked;
/** Creates new form DraftPanel */
public DraftPanel() {
@ -103,12 +104,18 @@ public class DraftPanel extends javax.swing.JPanel {
@Override
public void event(Event event) {
if (event.getEventName().equals("pick-a-card")) {
countdown.stop();
session.sendCardPick(draftId, (UUID)event.getSource());
DraftPickView view = session.sendCardPick(draftId, (UUID)event.getSource());
if (view != null) {
draftBooster.loadBooster(view.getBooster(), bigCard);
draftPicks.loadCards(view.getPicks(), bigCard, null);
setMessage("Waiting for other players");
}
}
}
}
);
setMessage("");
countdown.stop();
this.timeout = draftPickView.getTimeout();
setTimeout(Integer.toString(timeout));
if (timeout != 0) {
@ -129,6 +136,10 @@ public class DraftPanel extends javax.swing.JPanel {
c.setVisible(false);
}
protected void setMessage(String message) {
this.lblMessage.setText(message);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
@ -153,6 +164,7 @@ public class DraftPanel extends javax.swing.JPanel {
chkPack2 = new javax.swing.JCheckBox();
chkPack3 = new javax.swing.JCheckBox();
txtTimeRemaining = new javax.swing.JTextField();
lblMessage = new javax.swing.JLabel();
draftBooster = new mage.client.cards.DraftGrid();
draftPicks = new mage.client.cards.CardGrid();
@ -183,6 +195,8 @@ public class DraftPanel extends javax.swing.JPanel {
txtTimeRemaining.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtTimeRemaining.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
lblMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
@ -214,6 +228,10 @@ public class DraftPanel extends javax.swing.JPanel {
.addComponent(chkPack3)
.addComponent(chkPack2)
.addComponent(chkPack1)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -239,7 +257,9 @@ public class DraftPanel extends javax.swing.JPanel {
.addComponent(txtCardNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(txtTimeRemaining, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
@ -290,6 +310,7 @@ public class DraftPanel extends javax.swing.JPanel {
private javax.swing.JPanel jPanel1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JLabel lblCardNo;
private javax.swing.JLabel lblMessage;
private javax.swing.JLabel lblPack1;
private javax.swing.JLabel lblPack2;
private javax.swing.JLabel lblPack3;

View file

@ -56,6 +56,7 @@ import mage.interfaces.Server;
import mage.interfaces.ServerState;
import mage.interfaces.callback.CallbackClientDaemon;
import mage.util.Logging;
import mage.view.DraftPickView;
import mage.view.GameTypeView;
import mage.view.TableView;
import mage.view.TournamentTypeView;
@ -105,6 +106,7 @@ public class Session {
return true;
} catch (MageException ex) {
logger.log(Level.SEVERE, null, ex);
disconnect();
JOptionPane.showMessageDialog(frame, "Unable to connect to server. " + ex.getMessage());
} catch (RemoteException ex) {
logger.log(Level.SEVERE, "Unable to connect to server - ", ex);
@ -272,9 +274,9 @@ public class Session {
return false;
}
public boolean joinTable(UUID roomId, UUID tableId, String playerName, DeckCardLists deckList) {
public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, DeckCardLists deckList) {
try {
return server.joinTable(sessionId, roomId, tableId, playerName, deckList);
return server.joinTable(sessionId, roomId, tableId, playerName, playerType, deckList);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
@ -285,9 +287,9 @@ public class Session {
return false;
}
public boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName) {
public boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName, String playerType) {
try {
return server.joinTournamentTable(sessionId, roomId, tableId, playerName);
return server.joinTournamentTable(sessionId, roomId, tableId, playerName, playerType);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
@ -381,16 +383,15 @@ public class Session {
return false;
}
public boolean sendCardPick(UUID draftId, UUID cardId) {
public DraftPickView sendCardPick(UUID draftId, UUID cardId) {
try {
server.sendCardPick(draftId, sessionId, cardId);
return true;
return server.sendCardPick(draftId, sessionId, cardId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
return null;
}
public boolean joinChat(UUID chatId, ChatPanel chat) {
@ -586,8 +587,7 @@ public class Session {
public boolean submitDeck(UUID tableId, DeckCardLists deck) {
try {
server.submitDeck(sessionId, tableId, deck);
return true;
return server.submitDeck(sessionId, tableId, deck);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {

View file

@ -82,7 +82,7 @@ public class TablePlayerPanel extends javax.swing.JPanel {
public boolean joinTable(UUID roomId, UUID tableId) throws FileNotFoundException, IOException, ClassNotFoundException {
if (!this.cbPlayerType.getSelectedItem().equals("Human")) {
return session.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), Sets.loadDeck(this.newPlayerPanel.getDeckFile()));
return session.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), (String)this.cbPlayerType.getSelectedItem(), Sets.loadDeck(this.newPlayerPanel.getDeckFile()));
}
return true;
}

View file

@ -97,13 +97,20 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
int modelRow = Integer.valueOf( e.getActionCommand() );
UUID tableId = UUID.fromString((String)tableModel.getValueAt(modelRow, 0));
String state = (String)tableModel.getValueAt(modelRow, 4);
boolean isTournament = (Boolean)tableModel.getValueAt(modelRow, 5);
if (state.equals("Join")) {
logger.info("Joining table " + tableId);
joinTableDialog.showDialog(roomId, tableId);
if (joinTableDialog.isJoined())
tableWaitingDialog.showDialog(roomId, tableId, false);
if (isTournament) {
logger.info("Joining tournament " + tableId);
if (session.joinTournamentTable(roomId, tableId, session.getUserName(), "Human"))
tableWaitingDialog.showDialog(roomId, tableId, true);
}
else {
logger.info("Joining table " + tableId);
joinTableDialog.showDialog(roomId, tableId);
if (joinTableDialog.isJoined())
tableWaitingDialog.showDialog(roomId, tableId, false);
}
} else if (state.equals("Watch")) {
logger.info("Watching table " + tableId);
if (!session.watchTable(roomId, tableId))
@ -305,18 +312,8 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
options.setRange(RangeOfInfluence.ALL);
options.setWinsNeeded(1);
table = session.createTable(roomId, options);
session.joinTable(
roomId,
table.getTableId(),
"Human",
Sets.loadDeck("test.dck")
);
session.joinTable(
roomId,
table.getTableId(),
"Computer",
Sets.loadDeck("test.dck")
);
session.joinTable(roomId, table.getTableId(), "Human", "Human", Sets.loadDeck("test.dck"));
session.joinTable(roomId, table.getTableId(), "Computer", "Computer - default", Sets.loadDeck("test.dck"));
hideTables();
session.startGame(roomId, table.getTableId());
} catch (Exception ex) {
@ -392,6 +389,8 @@ class TableTableModel extends AbstractTableModel {
default:
return "";
}
case 5:
return tables[arg0].isTournament();
}
return "";
}

View file

@ -65,7 +65,7 @@ public class TournamentPlayerPanel extends javax.swing.JPanel {
public boolean joinTournamentTable(UUID roomId, UUID tableId) {
if (!this.cbPlayerType.getSelectedItem().equals("Human")) {
return session.joinTournamentTable(roomId, tableId, this.txtPlayerName.getText());
return session.joinTournamentTable(roomId, tableId, this.txtPlayerName.getText(), (String)this.cbPlayerType.getSelectedItem());
}
return true;
}

View file

@ -37,6 +37,7 @@ import mage.cards.decks.DeckCardLists;
import mage.game.GameException;
import mage.game.tournament.TournamentOptions;
import mage.interfaces.callback.CallbackServer;
import mage.view.DraftPickView;
import mage.view.TableView;
import mage.view.GameView;
import mage.view.TournamentView;
@ -56,8 +57,8 @@ public interface Server extends Remote, CallbackServer {
//table methods
public TableView createTable(UUID sessionId, UUID roomId, MatchOptions matchOptions) 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 joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws RemoteException, MageException, GameException;
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws RemoteException, MageException, GameException;
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType) 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;
@ -98,7 +99,7 @@ public interface Server extends Remote, CallbackServer {
//draft methods
public void joinDraft(UUID draftId, UUID sessionId) throws RemoteException, MageException;
public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) throws RemoteException, MageException;
public DraftPickView sendCardPick(UUID draftId, UUID sessionId, UUID cardId) throws RemoteException, MageException;
//replay methods
public void replayGame(UUID sessionId) throws RemoteException, MageException;

View file

@ -40,11 +40,13 @@ public class DraftPickView implements Serializable {
protected CardsView booster;
protected CardsView picks;
protected boolean picking;
protected int timeout;
public DraftPickView(DraftPlayer player, int timeout) {
this.booster = new CardsView(player.getBooster());
this.picks = new CardsView(player.getDeck().getSideboard());
this.picking = player.isPicking();
this.timeout = timeout;
}
@ -56,6 +58,10 @@ public class DraftPickView implements Serializable {
return picks;
}
public boolean isPicking() {
return this.picking;
}
public int getTimeout() {
return timeout;
}

View file

@ -47,6 +47,7 @@ public class TableView implements Serializable {
private String gameType;
private String deckType;
private TableState tableState;
private boolean isTournament;
private List<SeatView> seats = new ArrayList<SeatView>();
public TableView(Table table) {
@ -54,6 +55,7 @@ public class TableView implements Serializable {
this.gameType = table.getGameType();
this.deckType = table.getDeckType();
this.tableState = table.getState();
this.isTournament = table.isTournament();
for (Seat seat: table.getSeats()) {
seats.add(new SeatView(seat));
}
@ -79,5 +81,8 @@ public class TableView implements Serializable {
return seats;
}
public boolean isTournament() {
return this.isTournament;
}
}

View file

@ -59,6 +59,7 @@ import mage.server.tournament.TournamentManager;
import mage.server.util.ThreadExecutor;
import mage.util.Logging;
import mage.view.ChatMessage.MessageColor;
import mage.view.DraftPickView;
import mage.view.GameView;
import mage.view.TableView;
import mage.view.TournamentView;
@ -162,9 +163,9 @@ public class ServerImpl extends RemoteServer implements Server {
}
@Override
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, DeckCardLists deckList) throws MageException, GameException {
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws MageException, GameException {
try {
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, name, deckList);
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, name, playerType, deckList);
logger.info("Session " + sessionId + " joined table " + tableId);
return ret;
}
@ -177,9 +178,9 @@ public class ServerImpl extends RemoteServer implements Server {
}
@Override
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws MageException, GameException {
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType) throws MageException, GameException {
try {
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name);
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name, playerType);
logger.info("Session " + sessionId + " joined table " + tableId);
return ret;
}
@ -562,20 +563,14 @@ public class ServerImpl extends RemoteServer implements Server {
}
@Override
public void sendCardPick(final UUID draftId, final UUID sessionId, final UUID cardPick) throws MageException {
public DraftPickView sendCardPick(final UUID draftId, final UUID sessionId, final UUID cardPick) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
DraftManager.getInstance().sendCardPick(draftId, sessionId, cardPick);
}
}
);
return DraftManager.getInstance().sendCardPick(draftId, sessionId, cardPick);
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override

View file

@ -102,7 +102,7 @@ public class TableController {
chatId = ChatManager.getInstance().createChatSession();
this.options = options;
match = GameFactory.getInstance().createMatch(options.getGameType(), options);
table = new Table(options.getGameType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes());
table = new Table(options.getGameType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), false);
init();
}
@ -111,7 +111,7 @@ public class TableController {
chatId = ChatManager.getInstance().createChatSession();
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());
table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), true);
init();
}
@ -136,11 +136,11 @@ public class TableController {
);
}
public synchronized boolean joinTournament(UUID sessionId, String name) throws GameException {
public synchronized boolean joinTournament(UUID sessionId, String name, String playerType) throws GameException {
if (table.getState() != TableState.WAITING) {
return false;
}
Seat seat = table.getNextAvailableSeat();
Seat seat = table.getNextAvailableSeat(playerType);
if (seat == null) {
throw new GameException("No available seats.");
}
@ -156,11 +156,11 @@ public class TableController {
return true;
}
public synchronized boolean joinTable(UUID sessionId, String name, DeckCardLists deckList) throws GameException {
public synchronized boolean joinTable(UUID sessionId, String name, String playerType, DeckCardLists deckList) throws GameException {
if (table.getState() != TableState.WAITING) {
return false;
}
Seat seat = table.getNextAvailableSeat();
Seat seat = table.getNextAvailableSeat(playerType);
if (seat == null) {
throw new GameException("No available seats.");
}
@ -181,11 +181,11 @@ public class TableController {
return true;
}
public void addPlayer(UUID sessionId, Player player, Deck deck) throws GameException {
public void addPlayer(UUID sessionId, Player player, String playerType, Deck deck) throws GameException {
if (table.getState() != TableState.WAITING) {
return;
}
Seat seat = table.getNextAvailableSeat();
Seat seat = table.getNextAvailableSeat(playerType);
if (seat == null) {
throw new GameException("No available seats.");
}

View file

@ -86,12 +86,12 @@ public class TableManager {
return tables.values();
}
public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException {
return controllers.get(tableId).joinTable(sessionId, name, deckList);
public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws GameException {
return controllers.get(tableId).joinTable(sessionId, name, playerType, deckList);
}
public boolean joinTournament(UUID sessionId, UUID tableId, String name) throws GameException {
return controllers.get(tableId).joinTournament(sessionId, name);
public boolean joinTournament(UUID sessionId, UUID tableId, String name, String playerType) throws GameException {
return controllers.get(tableId).joinTournament(sessionId, name, playerType);
}
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws GameException {
@ -165,7 +165,7 @@ public class TableManager {
controllers.get(tableId).construct();
}
public void addPlayer(UUID sessionId, UUID tableId, Player player, Deck deck) throws GameException {
controllers.get(tableId).addPlayer(sessionId, player, deck);
public void addPlayer(UUID sessionId, UUID tableId, Player player, String playerType, Deck deck) throws GameException {
controllers.get(tableId).addPlayer(sessionId, player, playerType, deck);
}
}

View file

@ -184,8 +184,11 @@ public class DraftController {
return this.draftSessionId;
}
public void sendCardPick(UUID sessionId, UUID cardId) {
draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId);
public DraftPickView sendCardPick(UUID sessionId, UUID cardId) {
if (draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId)) {
return getDraftPickView(sessionPlayerMap.get(sessionId), 0);
}
return null;
}
private synchronized void updateDraft() {

View file

@ -31,6 +31,7 @@ package mage.server.draft;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.game.draft.Draft;
import mage.view.DraftPickView;
/**
*
@ -61,8 +62,8 @@ public class DraftManager {
draftControllers.remove(gameId);
}
public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) {
draftControllers.get(draftId).sendCardPick(sessionId, cardId);
public DraftPickView sendCardPick(UUID draftId, UUID sessionId, UUID cardId) {
return draftControllers.get(draftId).sendCardPick(sessionId, cardId);
}
public void removeSession(UUID sessionId) {

View file

@ -151,9 +151,10 @@ public class DraftSession {
killed = true;
}
public void sendCardPick(UUID cardId) {
public boolean sendCardPick(UUID cardId) {
cancelTimeout();
draft.addPick(playerId, cardId);
return draft.addPick(playerId, cardId);
}
}

View file

@ -44,8 +44,8 @@ import mage.view.TableView;
public interface GamesRoom extends Room {
public List<TableView> getTables();
public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException;
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name) throws GameException;
public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws GameException;
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType) throws GameException;
public TableView createTable(UUID sessionId, MatchOptions options);
public TableView createTournamentTable(UUID sessionId, TournamentOptions options);
public void removeTable(UUID sessionId, UUID tableId);

View file

@ -65,9 +65,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
}
@Override
public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException {
public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws GameException {
if (tables.containsKey(tableId)) {
return TableManager.getInstance().joinTable(sessionId, tableId, name, deckList);
return TableManager.getInstance().joinTable(sessionId, tableId, name, playerType, deckList);
} else {
return false;
}
@ -81,9 +81,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
}
@Override
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name) throws GameException {
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType) throws GameException {
if (tables.containsKey(tableId)) {
return TableManager.getInstance().joinTournament(sessionId, tableId, name);
return TableManager.getInstance().joinTournament(sessionId, tableId, name, playerType);
} else {
return false;
}

View file

@ -106,7 +106,7 @@ public class TournamentController {
checkStart();
}
public void join(UUID sessionId) {
public synchronized void join(UUID sessionId) {
UUID playerId = sessionPlayerMap.get(sessionId);
TournamentSession tournamentSession = new TournamentSession(tournament, sessionId, playerId);
tournamentSessions.put(playerId, tournamentSession);
@ -157,8 +157,8 @@ public class TournamentController {
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.addPlayer(getPlayerSessionId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getPlayerType(), player1.getDeck());
tableManager.addPlayer(getPlayerSessionId(player2.getPlayer().getId()), table.getId(), player2.getPlayer(), player2.getPlayerType(), player2.getDeck());
tableManager.startMatch(sessionId, null, table.getId());
pair.setMatch(tableManager.getMatch(table.getId()));
} catch (GameException ex) {

View file

@ -74,8 +74,8 @@ public class MageBase {
options.setWinsNeeded(1);
TableView table = server.createTable(sessionId, roomId, options);
System.out.println("Cards in the deck: " + Sets.loadDeck("UW Control.dck").getCards().size());
server.joinTable(sessionId, roomId, table.getTableId(), "Human", Sets.loadDeck("UW Control.dck"));
server.joinTable(sessionId, roomId, table.getTableId(), "Computer", Sets.loadDeck("UW Control.dck"));
server.joinTable(sessionId, roomId, table.getTableId(), "Human", "Human", Sets.loadDeck("UW Control.dck"));
server.joinTable(sessionId, roomId, table.getTableId(), "Computer", "Computer - default", Sets.loadDeck("UW Control.dck"));
server.startMatch(sessionId, roomId, table.getTableId());
synchronized (syncStart) {

View file

@ -51,16 +51,18 @@ public class Table implements Serializable {
private String gameType;
private Seat[] seats;
private int numSeats;
private boolean isTournament;
private DeckValidator validator;
private TableState state = TableState.WAITING;
protected TableEventSource tableEventSource = new TableEventSource();
public Table(String gameType, String name, DeckValidator validator, List<String> playerTypes) {
public Table(String gameType, String name, DeckValidator validator, List<String> playerTypes, boolean isTournament) {
tableId = UUID.randomUUID();
this.numSeats = playerTypes.size();
this.gameType = gameType;
this.name = name;
this.isTournament = isTournament;
createSeats(playerTypes);
this.validator = validator;
}
@ -98,6 +100,10 @@ public class Table implements Serializable {
return validator.getName();
}
public boolean isTournament() {
return this.isTournament;
}
public UUID joinTable(Player player, Seat seat) throws GameException {
if (seat.getPlayer() != null) {
throw new GameException("Seat is occupied.");
@ -120,9 +126,9 @@ public class Table implements Serializable {
return seats;
}
public Seat getNextAvailableSeat() {
public Seat getNextAvailableSeat(String playerType) {
for (int i = 0; i < numSeats; i++ ) {
if (seats[i].getPlayer() == null)
if (seats[i].getPlayer() == null && seats[i].getPlayerType().equals(playerType))
return seats[i];
}
return null;

View file

@ -51,7 +51,7 @@ public interface Draft extends MageItem, Serializable {
public List<ExpansionSet> getSets();
public int getBoosterNum();
public int getCardNum();
public void addPick(UUID playerId, UUID cardId);
public boolean addPick(UUID playerId, UUID cardId);
public void start();
public boolean allJoined();
public void leave(UUID playerId);

View file

@ -232,18 +232,21 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
}
@Override
public void addPick(UUID playerId, UUID cardId) {
public boolean addPick(UUID playerId, UUID cardId) {
DraftPlayer player = players.get(playerId);
for (Card card: player.booster) {
if (card.getId().equals(cardId)) {
player.addPick(card);
player.booster.remove(card);
break;
if (player.isPicking()) {
for (Card card: player.booster) {
if (card.getId().equals(cardId)) {
player.addPick(card);
player.booster.remove(card);
break;
}
}
synchronized(this) {
this.notifyAll();
}
}
synchronized(this) {
this.notifyAll();
}
return !player.isPicking();
}
}