1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-07 13:01:06 -09:00

added draft timing

This commit is contained in:
BetaSteward 2011-01-12 23:44:04 -05:00
parent 982ee064a6
commit cb73d4a25d
11 changed files with 419 additions and 31 deletions
Mage.Client/src/main/java/mage/client
Mage.Common/src/mage/view
Mage.Server/src/main/java/mage/server/game
Mage/src/mage/game/draft

View file

@ -34,7 +34,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="draftPicks" pref="123" max="32767" attributes="0"/>
<Component id="draftPicks" pref="103" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="draftBooster" min="-2" max="-2" attributes="0"/>
</Group>
@ -55,12 +55,71 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="bigCard" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="lblCardNo" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Group type="102" alignment="0" attributes="1">
<Component id="lblPack2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtPack2" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="lblPack1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtPack1" min="-2" pref="112" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="lblPack3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtCardNo" alignment="0" pref="112" max="32767" attributes="0"/>
<Component id="txtPack3" alignment="0" max="32767" attributes="0"/>
<Component id="txtTimeRemaining" alignment="0" pref="112" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="chkPack3" min="-2" max="-2" attributes="0"/>
<Component id="chkPack2" min="-2" max="-2" attributes="0"/>
<Component id="chkPack1" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="186" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblPack1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtPack1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="chkPack1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblPack2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtPack2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="chkPack2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblPack3" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtPack3" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="chkPack3" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblCardNo" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtCardNo" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="txtTimeRemaining" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="41" max="32767" attributes="0"/>
<Component id="bigCard" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
@ -69,6 +128,82 @@
<SubComponents>
<Component class="mage.client.cards.BigCard" name="bigCard">
</Component>
<Component class="javax.swing.JLabel" name="lblCardNo">
<Properties>
<Property name="text" type="java.lang.String" value="Card #:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblPack1">
<Properties>
<Property name="text" type="java.lang.String" value="Pack 1:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblPack2">
<Properties>
<Property name="text" type="java.lang.String" value="Pack 2:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblPack3">
<Properties>
<Property name="text" type="java.lang.String" value="Pack 3:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtPack1">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtPack1ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="txtPack2">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtPack3">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtPack3ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="txtCardNo">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtCardNoActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="chkPack1">
</Component>
<Component class="javax.swing.JCheckBox" name="chkPack2">
</Component>
<Component class="javax.swing.JCheckBox" name="chkPack3">
</Component>
<Component class="javax.swing.JTextField" name="txtTimeRemaining">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" id="red" palette="1" red="ff" type="palette"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.BevelBorderInfo">
<BevelBorder/>
</Border>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtTimeRemainingActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="mage.client.cards.DraftGrid" name="draftBooster">
@ -88,7 +223,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="432" max="32767" attributes="0"/>
<EmptySpace min="0" pref="452" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>

View file

@ -34,12 +34,16 @@
package mage.client.draft;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.UUID;
import javax.swing.Timer;
import mage.client.MageFrame;
import mage.client.remote.Session;
import mage.client.util.Event;
import mage.client.util.Listener;
import mage.view.DraftPickView;
import mage.view.DraftView;
/**
*
@ -49,11 +53,26 @@ public class DraftPanel extends javax.swing.JPanel {
private UUID draftId;
private Session session;
private Timer countdown;
private int timeout;
/** Creates new form DraftPanel */
public DraftPanel() {
initComponents();
countdown = new Timer(1000,
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (--timeout > 0) {
setTimeout(Integer.toString(timeout));
}
else {
setTimeout("0");
countdown.stop();
}
}
}
);
}
public synchronized void showDraft(UUID draftId) {
@ -64,6 +83,16 @@ public class DraftPanel extends javax.swing.JPanel {
hideDraft();
}
public void updateDraft(DraftView draftView) {
this.txtPack1.setText(draftView.getSets().get(0));
this.txtPack2.setText(draftView.getSets().get(1));
this.txtPack3.setText(draftView.getSets().get(2));
this.chkPack1.setSelected(draftView.getBoosterNum() > 0);
this.chkPack2.setSelected(draftView.getBoosterNum() > 1);
this.chkPack3.setSelected(draftView.getBoosterNum() > 2);
this.txtCardNo.setText(Integer.toString(draftView.getCardNum()));
}
public void loadBooster(DraftPickView draftPickView) {
draftBooster.loadBooster(draftPickView.getBooster(), bigCard);
draftPicks.loadCards(draftPickView.getPicks(), bigCard, null);
@ -73,11 +102,21 @@ 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());
}
}
}
);
this.timeout = draftPickView.getTimeout();
setTimeout(Integer.toString(timeout));
if (timeout != 0) {
countdown.start();
}
}
private void setTimeout(String text) {
this.txtTimeRemaining.setText(text);
}
public void hideDraft() {
@ -96,21 +135,125 @@ public class DraftPanel extends javax.swing.JPanel {
jSeparator1 = new javax.swing.JSeparator();
jPanel1 = new javax.swing.JPanel();
bigCard = new mage.client.cards.BigCard();
lblCardNo = new javax.swing.JLabel();
lblPack1 = new javax.swing.JLabel();
lblPack2 = new javax.swing.JLabel();
lblPack3 = new javax.swing.JLabel();
txtPack1 = new javax.swing.JTextField();
txtPack2 = new javax.swing.JTextField();
txtPack3 = new javax.swing.JTextField();
txtCardNo = new javax.swing.JTextField();
chkPack1 = new javax.swing.JCheckBox();
chkPack2 = new javax.swing.JCheckBox();
chkPack3 = new javax.swing.JCheckBox();
txtTimeRemaining = new javax.swing.JTextField();
draftBooster = new mage.client.cards.DraftGrid();
draftPicks = new mage.client.cards.CardGrid();
jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
lblCardNo.setText("Card #:");
lblPack1.setText("Pack 1:");
lblPack2.setText("Pack 2:");
lblPack3.setText("Pack 3:");
txtPack1.setEditable(false);
txtPack1.setEnabled(false);
txtPack1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtPack1ActionPerformed(evt);
}
});
txtPack2.setEditable(false);
txtPack2.setEnabled(false);
txtPack3.setEditable(false);
txtPack3.setEnabled(false);
txtPack3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtPack3ActionPerformed(evt);
}
});
txtCardNo.setEditable(false);
txtCardNo.setEnabled(false);
txtCardNo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtCardNoActionPerformed(evt);
}
});
txtTimeRemaining.setEditable(false);
txtTimeRemaining.setForeground(java.awt.Color.red);
txtTimeRemaining.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtTimeRemaining.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
txtTimeRemaining.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtTimeRemainingActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblCardNo))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(lblPack2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPack2))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(lblPack1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPack1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(lblPack3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtCardNo, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
.addComponent(txtPack3)
.addComponent(txtTimeRemaining, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(chkPack3)
.addComponent(chkPack2)
.addComponent(chkPack1)))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(186, Short.MAX_VALUE)
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblPack1)
.addComponent(txtPack1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chkPack1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblPack2)
.addComponent(txtPack2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chkPack2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblPack3)
.addComponent(txtPack3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chkPack3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblCardNo)
.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)
.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
@ -124,7 +267,7 @@ public class DraftPanel extends javax.swing.JPanel {
);
draftBoosterLayout.setVerticalGroup(
draftBoosterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 432, Short.MAX_VALUE)
.addGap(0, 452, Short.MAX_VALUE)
);
draftPicks.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
@ -144,19 +287,47 @@ public class DraftPanel extends javax.swing.JPanel {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(draftPicks, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
.addComponent(draftPicks, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
.addGap(0, 0, 0)
.addComponent(draftBooster, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
}// </editor-fold>//GEN-END:initComponents
private void txtPack1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPack1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtPack1ActionPerformed
private void txtPack3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPack3ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtPack3ActionPerformed
private void txtCardNoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCardNoActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtCardNoActionPerformed
private void txtTimeRemainingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTimeRemainingActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtTimeRemainingActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private mage.client.cards.BigCard bigCard;
private javax.swing.JCheckBox chkPack1;
private javax.swing.JCheckBox chkPack2;
private javax.swing.JCheckBox chkPack3;
private mage.client.cards.DraftGrid draftBooster;
private mage.client.cards.CardGrid draftPicks;
private javax.swing.JPanel jPanel1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JLabel lblCardNo;
private javax.swing.JLabel lblPack1;
private javax.swing.JLabel lblPack2;
private javax.swing.JLabel lblPack3;
private javax.swing.JTextField txtCardNo;
private javax.swing.JTextField txtPack1;
private javax.swing.JTextField txtPack2;
private javax.swing.JTextField txtPack3;
private javax.swing.JTextField txtTimeRemaining;
// End of variables declaration//GEN-END:variables
}

View file

@ -45,6 +45,7 @@ import mage.util.Logging;
import mage.view.AbilityPickerView;
import mage.view.ChatMessage;
import mage.view.DraftClientMessage;
import mage.view.DraftView;
import mage.view.GameClientMessage;
import mage.view.GameView;
import mage.view.TableClientMessage;
@ -174,6 +175,9 @@ public class Client implements CallbackClient {
DraftClientMessage message = (DraftClientMessage) callback.getData();
session.getDraft().loadBooster(message.getDraftPickView());
}
else if (callback.getMethod().equals("draftUpdate")) {
session.getDraft().updateDraft((DraftView) callback.getData());
}
else if (callback.getMethod().equals("draftInform")) {
if (callback.getMessageId() > messageId) {
DraftClientMessage message = (DraftClientMessage) callback.getData();

View file

@ -322,6 +322,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
private void btnNewDraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewDraftActionPerformed
DraftOptions options = new DraftOptions("testDraft");
options.setDraftType("8 Player Booster");
options.setTiming(DraftOptions.TimingOption.REGULAR);
options.getPlayerTypes().add("Human");
options.getPlayerTypes().add("Computer - default");
options.getPlayerTypes().add("Computer - default");

View file

@ -39,10 +39,12 @@ public class DraftPickView implements Serializable {
protected CardsView booster;
protected CardsView picks;
protected int timeout;
public DraftPickView(DraftPlayer player) {
public DraftPickView(DraftPlayer player, int timeout) {
this.booster = new CardsView(player.getBooster());
this.picks = new CardsView(player.getDeck().getSideboard());
this.timeout = timeout;
}
public CardsView getBooster() {
@ -52,4 +54,8 @@ public class DraftPickView implements Serializable {
public CardsView getPicks() {
return picks;
}
public int getTimeout() {
return timeout;
}
}

View file

@ -31,6 +31,7 @@ package mage.view;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import mage.cards.ExpansionSet;
import mage.game.draft.Draft;
/**
@ -39,11 +40,27 @@ import mage.game.draft.Draft;
*/
public class DraftView implements Serializable {
private List<TournamentPlayerView> players = new ArrayList<TournamentPlayerView>();
private List<String> sets = new ArrayList<String>();
private int boosterNum;
private int cardNum;
public DraftView(Draft draft) {
for (ExpansionSet set: draft.getSets()) {
sets.add(set.getName());
}
this.boosterNum = draft.getBoosterNum();
this.cardNum = draft.getCardNum();
}
public List<String> getSets() {
return sets;
}
public int getBoosterNum() {
return boosterNum;
}
public int getCardNum() {
return cardNum;
}
}

View file

@ -108,7 +108,7 @@ public class DraftController {
public void join(UUID sessionId) {
UUID playerId = sessionPlayerMap.get(sessionId);
DraftSession draftSession = new DraftSession(sessionId, draft.getId());
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);
@ -183,7 +183,7 @@ public class DraftController {
}
public void sendCardPick(UUID sessionId, UUID cardId) {
draft.addPick(sessionPlayerMap.get(sessionId), cardId);
draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId);
}
private synchronized void updateDraft() {
@ -194,15 +194,15 @@ public class DraftController {
private synchronized void pickCard(UUID playerId, int timeout) {
if (draftSessions.containsKey(playerId))
draftSessions.get(playerId).pickCard(getDraftPickView(playerId), timeout);
draftSessions.get(playerId).pickCard(getDraftPickView(playerId, timeout), timeout);
}
private DraftView getDraftView() {
return new DraftView(draft);
}
private DraftPickView getDraftPickView(UUID playerId) {
return new DraftPickView(draft.getPlayer(playerId));
private DraftPickView getDraftPickView(UUID playerId, int timeout) {
return new DraftPickView(draft.getPlayer(playerId), timeout);
}
}

View file

@ -35,6 +35,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.draft.Draft;
import mage.interfaces.callback.ClientCallback;
import mage.server.Session;
import mage.server.SessionManager;
@ -54,15 +55,17 @@ public class DraftSession {
protected final static Logger logger = Logging.getLogger(GameWatcher.class.getName());
protected UUID sessionId;
protected UUID draftId;
protected UUID playerId;
protected Draft draft;
protected boolean killed = false;
private ScheduledFuture<?> futureTimeout;
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
public DraftSession(UUID sessionId, UUID draftId) {
public DraftSession(Draft draft, UUID sessionId, UUID playerId) {
this.sessionId = sessionId;
this.draftId = draftId;
this.draft = draft;
this.playerId = playerId;
}
public boolean init(final DraftView draftView) {
@ -121,15 +124,17 @@ public class DraftSession {
private synchronized void setupTimeout(int seconds) {
cancelTimeout();
futureTimeout = timeoutExecutor.schedule(
new Runnable() {
@Override
public void run() {
DraftManager.getInstance().timeout(draftId, sessionId);
}
},
seconds, TimeUnit.SECONDS
);
if (seconds > 0) {
futureTimeout = timeoutExecutor.schedule(
new Runnable() {
@Override
public void run() {
DraftManager.getInstance().timeout(draft.getId(), sessionId);
}
},
seconds, TimeUnit.SECONDS
);
}
}
private synchronized void cancelTimeout() {
@ -140,11 +145,16 @@ public class DraftSession {
protected void handleRemoteException(RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
DraftManager.getInstance().kill(draftId, sessionId);
DraftManager.getInstance().kill(draft.getId(), sessionId);
}
public void setKilled() {
killed = true;
}
public void sendCardPick(UUID cardId) {
cancelTimeout();
draft.addPick(playerId, cardId);
}
}

View file

@ -30,8 +30,10 @@ package mage.game.draft;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import mage.MageItem;
import mage.cards.ExpansionSet;
import mage.game.events.Listener;
import mage.game.events.PlayerQueryEvent;
import mage.game.events.TableEvent;
@ -46,6 +48,9 @@ public interface Draft extends MageItem, Serializable {
public void addPlayer(Player player);
public Collection<DraftPlayer> getPlayers();
public DraftPlayer getPlayer(UUID playerId);
public List<ExpansionSet> getSets();
public int getBoosterNum();
public int getCardNum();
public void addPick(UUID playerId, UUID cardId);
public void start();
public void leave(UUID playerId);

View file

@ -37,6 +37,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.game.draft.DraftOptions.TimingOption;
import mage.game.events.Listener;
import mage.game.events.PlayerQueryEvent;
import mage.game.events.PlayerQueryEventSource;
@ -57,6 +58,9 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
protected PlayerList table = new PlayerList();
protected List<ExpansionSet> sets;
protected int boosterNum = 0;
protected int cardNum = 0;
protected TimingOption timing;
protected int[] times = {40, 40, 35, 30, 25, 25, 20, 20, 15, 10, 10, 5, 5, 5, 5};
protected transient TableEventSource tableEventSource = new TableEventSource();
protected transient PlayerQueryEventSource playerQueryEventSource = new PlayerQueryEventSource();
@ -64,6 +68,7 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
public DraftImpl(DraftOptions options) {
id = UUID.randomUUID();
this.sets = options.getSets();
this.timing = options.getTiming();
}
@Override
@ -88,6 +93,21 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
return players.get(playerId);
}
@Override
public List<ExpansionSet> getSets() {
return sets;
}
@Override
public int getBoosterNum() {
return boosterNum;
}
@Override
public int getCardNum() {
return cardNum;
}
@Override
public void leave(UUID playerId) {
//TODO: implement this
@ -95,7 +115,7 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
@Override
public void autoPick(UUID playerId) {
//TODO: implement this
this.addPick(playerId, players.get(playerId).getBooster().get(0).getId());
}
protected void passLeft() {
@ -145,9 +165,12 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
}
}
boosterNum++;
cardNum = 1;
fireUpdatePlayersEvent();
}
protected boolean pickCards() {
cardNum++;
for (DraftPlayer player: players.values()) {
if (player.getBooster().size() == 0)
return false;
@ -195,7 +218,11 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
@Override
public void firePickCardEvent(UUID playerId) {
playerQueryEventSource.pickCard(playerId, "Pick card", players.get(playerId).booster, 20);
DraftPlayer player = players.get(playerId);
if (cardNum > 15)
cardNum = 15;
int time = times[cardNum - 1] * timing.getFactor();
playerQueryEventSource.pickCard(playerId, "Pick card", player.getBooster(), time);
}
@Override

View file

@ -46,7 +46,19 @@ public class DraftOptions implements Serializable {
protected TimingOption timing;
public enum TimingOption {
REGULAR, BEGINNER, NONE
REGULAR (1),
BEGINNER (2),
NONE (0);
private int factor;
TimingOption(int factor) {
this.factor = factor;
}
public int getFactor() {
return this.factor;
}
}
public DraftOptions(String name) {