draft stuff

This commit is contained in:
BetaSteward 2011-01-08 23:54:32 -05:00
parent 2e13136101
commit 03e3be90d6
34 changed files with 1238 additions and 743 deletions

View file

@ -69,6 +69,7 @@ import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import mage.client.draft.DraftPane;
/**
* @author BetaSteward_at_googlemail.com
@ -141,6 +142,14 @@ public class MageFrame extends javax.swing.JFrame {
desktopPane.add(pickNumber, JLayeredPane.POPUP_LAYER);
session.getUI().addComponent(MageComponents.DESKTOP_PANE, desktopPane);
draftPane = new DraftPane();
desktopPane.add(draftPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
try {
draftPane.setMaximum(true);
} catch (java.beans.PropertyVetoException e1) {
e1.printStackTrace();
}
addTooltipContainer();
setBackground();
addMageLabel();
@ -301,6 +310,7 @@ public class MageFrame extends javax.swing.JFrame {
public void showGame(UUID gameId, UUID playerId) {
this.tablesPane.hideTables();
this.tablesPane.setVisible(false);
this.draftPane.setVisible(false);
this.gamePane.setVisible(true);
this.gamePane.showGame(gameId, playerId);
}
@ -308,6 +318,7 @@ public class MageFrame extends javax.swing.JFrame {
public void watchGame(UUID gameId) {
this.tablesPane.hideTables();
this.tablesPane.setVisible(false);
this.draftPane.setVisible(false);
this.gamePane.setVisible(true);
this.gamePane.watchGame(gameId);
}
@ -315,10 +326,19 @@ public class MageFrame extends javax.swing.JFrame {
public void replayGame() {
this.tablesPane.hideTables();
this.tablesPane.setVisible(false);
this.draftPane.setVisible(false);
this.gamePane.setVisible(true);
this.gamePane.replayGame();
}
public void showDraft(UUID draftId) {
this.tablesPane.hideTables();
this.tablesPane.setVisible(false);
this.gamePane.setVisible(false);
this.draftPane.setVisible(true);
this.draftPane.showDraft(draftId);
}
public static boolean connect(String userName, String serverName, int port) {
return session.connect(userName, serverName, port);
}
@ -524,6 +544,7 @@ public class MageFrame extends javax.swing.JFrame {
private void btnDeckEditorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeckEditorActionPerformed
this.gamePane.setVisible(false);
this.tablesPane.setVisible(false);
this.draftPane.setVisible(false);
this.collectionViewerPane.setVisible(false);
showDeckEditor(DeckEditorMode.Constructed, null, null);
}//GEN-LAST:event_btnDeckEditorActionPerformed
@ -589,6 +610,7 @@ public class MageFrame extends javax.swing.JFrame {
this.tablesPane.setVisible(false);
this.gamePane.setVisible(false);
this.deckEditorPane.setVisible(false);
this.draftPane.setVisible(false);
this.collectionViewerPane.setVisible(false);
}
@ -667,6 +689,7 @@ public class MageFrame extends javax.swing.JFrame {
private static final long serialVersionUID = -9104885239063142218L;
private ImagePanel backgroundPane;
private DraftPane draftPane;
public void setStatusText(String status) {
this.lblStatus.setText(status);

View file

@ -0,0 +1,29 @@
<?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"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

View file

@ -0,0 +1,126 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* DraftGrid.java
*
* Created on 7-Jan-2011, 6:23:39 PM
*/
package mage.client.cards;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.UUID;
import mage.cards.MageCard;
import mage.client.MageFrame;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
import mage.view.CardView;
import mage.view.CardsView;
import mage.client.util.Event;
import mage.client.util.Listener;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class DraftGrid extends javax.swing.JPanel implements MouseListener {
protected CardEventSource cardEventSource = new CardEventSource();
protected BigCard bigCard;
/** Creates new form DraftGrid */
public DraftGrid() {
initComponents();
}
public void loadBooster(CardsView booster, BigCard bigCard) {
this.bigCard = bigCard;
this.removeAll();
int numColumns = 5;
int curColumn = 0;
int curRow = 0;
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
for (CardView card: booster.values()) {
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, Config.dimensions, null);
cardImg.addMouseListener(this);
add(cardImg);
cardImg.update(card);
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * Config.dimensions.frameHeight);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
curRow++;
}
}
}
public void addCardEventListener(Listener<Event> listener) {
cardEventSource.addListener(listener);
}
public void clearCardEventListeners() {
cardEventSource.clearListeners();
}
/** 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() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
@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
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

View file

@ -34,6 +34,7 @@
package mage.client.draft;
import java.util.UUID;
import mage.client.MagePane;
/**
@ -47,6 +48,10 @@ public class DraftPane extends MagePane {
initComponents();
}
public void showDraft(UUID draftId) {
this.draftPanel1.showDraft(draftId);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is

View file

@ -1,6 +1,10 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
<Component class="javax.swing.JSeparator" name="jSeparator1">
</Component>
</NonVisualComponents>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
@ -18,13 +22,22 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="465" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="draftBooster" max="32767" attributes="0"/>
<Component id="draftPicks" alignment="0" pref="570" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<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"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="draftBooster" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
@ -47,7 +60,7 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="85" max="32767" attributes="0"/>
<EmptySpace pref="186" max="32767" attributes="0"/>
<Component id="bigCard" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
@ -58,5 +71,38 @@
</Component>
</SubComponents>
</Container>
<Container class="mage.client.cards.DraftGrid" name="draftBooster">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="568" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="432" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
<Container class="mage.client.cards.CardGrid" name="draftPicks">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout"/>
</Container>
</SubComponents>
</Form>

View file

@ -35,8 +35,11 @@
package mage.client.draft;
import java.util.UUID;
import mage.client.cards.BigCard;
import mage.view.CardsView;
import mage.client.MageFrame;
import mage.client.remote.Session;
import mage.client.util.Event;
import mage.client.util.Listener;
import mage.view.DraftPickView;
/**
*
@ -44,14 +47,41 @@ import mage.view.CardsView;
*/
public class DraftPanel extends javax.swing.JPanel {
private UUID draftId;
private Session session;
/** Creates new form DraftPanel */
public DraftPanel() {
initComponents();
}
public void loadBooster(CardsView cards, UUID draftId) {
public synchronized void showDraft(UUID draftId) {
this.draftId = draftId;
session = MageFrame.getSession();
session.setDraft(this);
if (!session.joinDraft(draftId))
hideDraft();
}
public void loadBooster(DraftPickView draftPickView) {
draftBooster.loadBooster(draftPickView.getBooster(), bigCard);
draftPicks.loadCards(draftPickView.getPicks(), bigCard, null);
this.draftBooster.clearCardEventListeners();
this.draftBooster.addCardEventListener(
new Listener<Event> () {
@Override
public void event(Event event) {
if (event.getEventName().equals("double-click")) {
session.sendCardPick(draftId, (UUID)event.getSource());
}
}
}
);
}
public void hideDraft() {
this.setVisible(false);
}
/** This method is called from within the constructor to
@ -63,8 +93,11 @@ public class DraftPanel extends javax.swing.JPanel {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jSeparator1 = new javax.swing.JSeparator();
jPanel1 = new javax.swing.JPanel();
bigCard = new mage.client.cards.BigCard();
draftBooster = new mage.client.cards.DraftGrid();
draftPicks = new mage.client.cards.CardGrid();
jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
@ -77,28 +110,53 @@ public class DraftPanel extends javax.swing.JPanel {
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(85, Short.MAX_VALUE)
.addContainerGap(186, Short.MAX_VALUE)
.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
draftBooster.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
javax.swing.GroupLayout draftBoosterLayout = new javax.swing.GroupLayout(draftBooster);
draftBooster.setLayout(draftBoosterLayout);
draftBoosterLayout.setHorizontalGroup(
draftBoosterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 568, Short.MAX_VALUE)
);
draftBoosterLayout.setVerticalGroup(
draftBoosterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 432, Short.MAX_VALUE)
);
draftPicks.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
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(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(465, Short.MAX_VALUE))
.addGap(0, 0, 0)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(draftBooster, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(draftPicks, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 570, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
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)
.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
// Variables declaration - do not modify//GEN-BEGIN:variables
private mage.client.cards.BigCard bigCard;
private mage.client.cards.DraftGrid draftBooster;
private mage.client.cards.CardGrid draftPicks;
private javax.swing.JPanel jPanel1;
private javax.swing.JSeparator jSeparator1;
// End of variables declaration//GEN-END:variables
}

View file

@ -83,7 +83,7 @@ public class Client implements CallbackClient {
}
else if(callback.getMethod().equals("startDraft")) {
TableClientMessage message = (TableClientMessage) callback.getData();
//TODO: add code to start draft
draftStarted(message.getGameId(), message.getPlayerId());
}
else if (callback.getMethod().equals("replayGame")) {
replayGame();
@ -166,9 +166,13 @@ public class Client implements CallbackClient {
TableClientMessage message = (TableClientMessage) callback.getData();
sideboard(message.getDeck(), message.getTableId());
}
else if (callback.getMethod().equals("construct")) {
TableClientMessage message = (TableClientMessage) callback.getData();
construct(message.getDeck(), message.getTableId());
}
else if (callback.getMethod().equals("draftPick")) {
DraftClientMessage message = (DraftClientMessage) callback.getData();
session.getDraft().loadBooster(message.getDraftPickView());
}
else if (callback.getMethod().equals("draftInform")) {
if (callback.getMessageId() > messageId) {
@ -179,7 +183,7 @@ public class Client implements CallbackClient {
}
}
else if (callback.getMethod().equals("draftInit")) {
session.ack("draftInit");
}
messageId = callback.getMessageId();
}
@ -206,6 +210,16 @@ public class Client implements CallbackClient {
}
}
protected void draftStarted(UUID draftId, UUID playerId) {
try {
frame.showDraft(draftId);
logger.info("Draft " + draftId + " started for player " + playerId);
}
catch (Exception ex) {
handleException(ex);
}
}
protected void watchGame(UUID gameId) {
try {
frame.watchGame(gameId);
@ -230,6 +244,10 @@ public class Client implements CallbackClient {
frame.showDeckEditor(DeckEditorMode.Sideboard, deck, tableId);
}
protected void construct(Deck deck, UUID tableId) {
frame.showDeckEditor(DeckEditorMode.Limited, deck, tableId);
}
private void handleException(Exception ex) {
logger.log(Level.SEVERE, "Client error\n", ex);
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Unrecoverable client error. Disconnecting", "Error", JOptionPane.ERROR_MESSAGE);

View file

@ -44,6 +44,7 @@ import mage.cards.decks.DeckCardLists;
import mage.client.MageFrame;
import mage.client.chat.ChatPanel;
import mage.client.components.MageUI;
import mage.client.draft.DraftPanel;
import mage.client.game.GamePanel;
import mage.client.util.Config;
import mage.game.GameException;
@ -73,6 +74,7 @@ public class Session {
private ServerState serverState;
private Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
private GamePanel game;
private DraftPanel draft;
private CallbackClientDaemon callbackDaemon;
private MageUI ui = new MageUI();
@ -170,6 +172,14 @@ public class Session {
game = gamePanel;
}
public DraftPanel getDraft() {
return draft;
}
public void setDraft(DraftPanel draftPanel) {
draft = draftPanel;
}
public UUID getMainRoomId() {
try {
return server.getMainRoomId();
@ -337,7 +347,7 @@ public class Session {
public boolean sendCardPick(UUID draftId, UUID cardId) {
try {
server.sendPlayerUUID(draftId, sessionId, cardId);
server.sendCardPick(draftId, sessionId, cardId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
@ -397,6 +407,18 @@ public class Session {
return false;
}
public boolean joinDraft(UUID draftId) {
try {
server.joinDraft(draftId, 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);

View file

@ -321,6 +321,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.getPlayerTypes().add("Human");
options.getPlayerTypes().add("Computer - default");
options.getPlayerTypes().add("Computer - default");

View file

@ -53,4 +53,11 @@ public class DraftClientMessage implements Serializable {
this.draftView = draftView;
}
public DraftPickView getDraftPickView() {
return draftPickView;
}
public DraftView getDraftView() {
return draftView;
}
}

View file

@ -28,17 +28,21 @@
package mage.view;
import java.io.Serializable;
import mage.game.draft.DraftPlayer;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class DraftPickView {
public class DraftPickView implements Serializable {
protected CardsView booster;
protected CardsView picks;
public DraftPickView() {
public DraftPickView(DraftPlayer player) {
this.booster = new CardsView(player.getBooster());
this.picks = new CardsView(player.getDeck().getSideboard());
}
public CardsView getBooster() {

View file

@ -28,6 +28,7 @@
package mage.view;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import mage.game.draft.Draft;
@ -36,7 +37,7 @@ import mage.game.draft.Draft;
*
* @author BetaSteward_at_googlemail.com
*/
public class DraftView {
public class DraftView implements Serializable {
private List<TournamentPlayerView> players = new ArrayList<TournamentPlayerView>();

View file

@ -28,13 +28,14 @@
package mage.view;
import java.io.Serializable;
import mage.game.tournament.Round;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class RoundView {
public class RoundView implements Serializable {
public RoundView(Round round) {

View file

@ -28,10 +28,12 @@
package mage.view;
import java.io.Serializable;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPlayerView {
public class TournamentPlayerView implements Serializable {
}

View file

@ -28,6 +28,7 @@
package mage.view;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import mage.game.tournament.Tournament;
@ -36,7 +37,7 @@ import mage.game.tournament.Tournament;
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentView {
public class TournamentView implements Serializable {
List<RoundView> rounds = new ArrayList<RoundView>();

View file

@ -0,0 +1,49 @@
<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-root</artifactId>
<version>0.5.1</version>
</parent>
<artifactId>Mage-Draft-8PlayerBooster</artifactId>
<packaging>jar</packaging>
<name>Mage Draft 8 Player Booster</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-draft-8playerbooster</finalName>
</build>
<properties/>
</project>

View file

@ -0,0 +1,59 @@
/*
* 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.draft;
import mage.game.draft.DraftImpl;
import mage.game.draft.DraftOptions;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class BoosterDraft extends DraftImpl<BoosterDraft> {
public BoosterDraft(DraftOptions options) {
super(options);
}
@Override
public void start() {
while (boosterNum < sets.size()) {
openBooster();
while (pickCards()) {
if (boosterNum % 2 == 1)
passLeft();
else
passRight();
fireUpdatePlayersEvent();
}
}
startTournament();
}
}

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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>
@ -23,6 +22,7 @@
<module>Mage.Player.AI</module>
<module>Mage.Player.AIMinimax</module>
<module>Mage.Player.Human</module>
<module>Mage.Draft.8PlayerBooster</module>
</modules>
</project>

View file

@ -12,6 +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>
<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.

View file

@ -37,6 +37,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.match.MatchType;
import mage.server.game.DeckValidatorFactory;
import mage.server.game.DraftFactory;
import mage.server.game.GameFactory;
import mage.server.game.PlayerFactory;
import mage.server.util.ConfigSettings;
@ -72,6 +73,9 @@ 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 (Plugin plugin: config.getPlayerTypes()) {
PlayerFactory.getInstance().addPlayerType(plugin.getName(), loadPlugin(plugin));
}

View file

@ -103,6 +103,10 @@ public class Session {
fireCallback(new ClientCallback("sideboard", new TableClientMessage(deck, tableId)));
}
public void construct(final Deck deck, final UUID tableId) {
fireCallback(new ClientCallback("construct", new TableClientMessage(deck, tableId)));
}
public void watchGame(final UUID gameId) {
fireCallback(new ClientCallback("watchGame", gameId));
}

View file

@ -93,7 +93,7 @@ public class DraftController {
public void event(PlayerQueryEvent event) {
switch (event.getQueryType()) {
case PICK_CARD:
pickCard(event.getPlayerId());
pickCard(event.getPlayerId(), event.getMax());
break;
}
}
@ -130,6 +130,7 @@ public class DraftController {
return;
}
}
draft.start();
}
private boolean allJoined() {
@ -186,9 +187,9 @@ public class DraftController {
}
}
private synchronized void pickCard(UUID playerId) {
private synchronized void pickCard(UUID playerId, int timeout) {
if (draftSessions.containsKey(playerId))
draftSessions.get(playerId).pickCard(getDraftPickView(playerId));
draftSessions.get(playerId).pickCard(getDraftPickView(playerId), timeout);
}
private DraftView getDraftView() {
@ -196,7 +197,7 @@ public class DraftController {
}
private DraftPickView getDraftPickView(UUID playerId) {
return new DraftPickView();
return new DraftPickView(draft.getPlayer(playerId));
}
}

View file

@ -110,9 +110,9 @@ public class DraftSession {
}
}
public void pickCard(final DraftPickView draftPickView) {
public void pickCard(final DraftPickView draftPickView, int timeout) {
if (!killed) {
setupTimeout(20);
setupTimeout(timeout);
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("draftPick", new DraftClientMessage(draftPickView)));

View file

@ -46,6 +46,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import mage.Constants.RangeOfInfluence;
import mage.Constants.TableState;
import mage.cards.decks.Deck;
import mage.cards.decks.DeckCardLists;
@ -212,7 +213,13 @@ public class TableController {
}
private Player createPlayer(String name, String playerType) {
Player player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange());
Player player;
if (options == null) {
player = PlayerFactory.getInstance().createPlayer(playerType, name, RangeOfInfluence.ALL);
}
else {
player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange());
}
logger.info("Player created " + player.getId());
return player;
}
@ -245,7 +252,6 @@ public class TableController {
public synchronized void startDraft(UUID sessionId) {
if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) {
draft.start();
table.initDraft();
DraftManager.getInstance().createDraftSession(draft, sessionPlayerMap, table.getId());
SessionManager sessionManager = SessionManager.getInstance();
@ -274,6 +280,16 @@ public class TableController {
}
}
private void construct(UUID playerId, Deck deck) {
SessionManager sessionManager = SessionManager.getInstance();
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
if (entry.getValue().equals(playerId)) {
sessionManager.getSession(entry.getKey()).construct(deck, table.getId());
break;
}
}
}
public void endGame() {
UUID choosingPlayerId = match.getChooser();
match.endGame();

View file

@ -8,6 +8,7 @@
<xs:element ref="server"/>
<xs:element ref="playerTypes"/>
<xs:element ref="gameTypes"/>
<xs:element ref="draftTypes"/>
<xs:element ref="deckTypes"/>
</xs:sequence>
</xs:complexType>
@ -23,18 +24,24 @@
</xs:complexType>
</xs:element>
<xs:element name="plugin">
<xs:complexType>
<xs:complexType name="plugin">
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="jar" type="xs:string"/>
<xs:attribute name="className" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:complexType name="gamePlugin">
<xs:complexContent>
<xs:extension base="plugin">
<xs:attribute name="typeName" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="playerTypes">
<xs:complexType>
<xs:sequence>
<xs:element ref="plugin" maxOccurs="unbounded"/>
<xs:element name="playerType" type="plugin" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@ -42,7 +49,15 @@
<xs:element name="gameTypes">
<xs:complexType>
<xs:sequence>
<xs:element ref="plugin" maxOccurs="unbounded"/>
<xs:element name="gameType" type="gamePlugin" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="draftTypes">
<xs:complexType>
<xs:sequence>
<xs:element name="draftType" type="plugin" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@ -50,7 +65,7 @@
<xs:element name="deckTypes">
<xs:complexType>
<xs:sequence>
<xs:element ref="plugin" maxOccurs="unbounded"/>
<xs:element name="deckType" type="plugin" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

View file

@ -92,6 +92,10 @@ public class ConfigSettings {
return config.getGameTypes().getGameType();
}
public List<Plugin> getDraftTypes() {
return config.getDraftTypes().getDraftType();
}
public List<Plugin> getDeckTypes() {
return config.getDeckTypes().getDeckType();
}

View file

@ -8,6 +8,7 @@
<xs:element ref="server"/>
<xs:element ref="playerTypes"/>
<xs:element ref="gameTypes"/>
<xs:element ref="draftTypes"/>
<xs:element ref="deckTypes"/>
</xs:sequence>
</xs:complexType>
@ -53,6 +54,14 @@
</xs:complexType>
</xs:element>
<xs:element name="draftTypes">
<xs:complexType>
<xs:sequence>
<xs:element name="draftType" type="plugin" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="deckTypes">
<xs:complexType>
<xs:sequence>

View file

@ -50,7 +50,7 @@ import mage.players.PlayerList;
*
* @author BetaSteward_at_googlemail.com
*/
public class DraftImpl<T extends DraftImpl<T>> implements Draft {
public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
protected final UUID id;
protected Map<UUID, DraftPlayer> players = new HashMap<UUID, DraftPlayer>();
@ -74,8 +74,8 @@ public class DraftImpl<T extends DraftImpl<T>> implements Draft {
@Override
public void addPlayer(Player player) {
DraftPlayer draftPlayer = new DraftPlayer(player);
players.put(draftPlayer.getId(), draftPlayer);
table.add(draftPlayer.getId());
players.put(player.getId(), draftPlayer);
table.add(player.getId());
}
@Override
@ -139,7 +139,7 @@ public class DraftImpl<T extends DraftImpl<T>> implements Draft {
}
protected void openBooster() {
if (sets.size() < boosterNum) {
if (boosterNum < sets.size()) {
for (DraftPlayer player: players.values()) {
player.setBooster(sets.get(boosterNum).createBooster());
}
@ -151,8 +151,8 @@ public class DraftImpl<T extends DraftImpl<T>> implements Draft {
for (DraftPlayer player: players.values()) {
if (player.getBooster().size() == 0)
return false;
player.getPlayer().pickCard(player.getBooster(), player.getDeck(), this);
player.setPicking();
player.getPlayer().pickCard(player.getBooster(), player.getDeck(), this);
}
while (!donePicking()) {
try {
@ -173,21 +173,6 @@ public class DraftImpl<T extends DraftImpl<T>> implements Draft {
return true;
}
@Override
public void start() {
while (boosterNum < sets.size()) {
openBooster();
while (pickCards()) {
if (boosterNum % 2 == 1)
passLeft();
else
passRight();
fireUpdatePlayersEvent();
}
}
startTournament();
}
@Override
public void addTableEventListener(Listener<TableEvent> listener) {
tableEventSource.addListener(listener);
@ -205,7 +190,7 @@ public class DraftImpl<T extends DraftImpl<T>> implements Draft {
@Override
public void firePickCardEvent(UUID playerId) {
playerQueryEventSource.pickCard(playerId, "Pick card", players.get(playerId).booster);
playerQueryEventSource.pickCard(playerId, "Pick card", players.get(playerId).booster, 20);
}
@Override
@ -214,6 +199,7 @@ public class DraftImpl<T extends DraftImpl<T>> implements Draft {
for (Card card: player.booster) {
if (card.getId().equals(cardId)) {
player.addPick(card);
player.booster.remove(card);
break;
}
}

View file

@ -41,7 +41,7 @@ public class DraftOptions implements Serializable {
protected String name;
protected String draftType;
protected List<ExpansionSet> sets;
protected List<ExpansionSet> sets = new ArrayList<ExpansionSet>();
protected List<String> playerTypes = new ArrayList<String>();
protected TimingOption timing;

View file

@ -76,12 +76,13 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
this.max = max;
}
private PlayerQueryEvent(UUID playerId, String message, List<Card> booster, QueryType queryType) {
private PlayerQueryEvent(UUID playerId, String message, List<Card> booster, QueryType queryType, int time) {
super(playerId);
this.queryType = queryType;
this.message = message;
this.playerId = playerId;
this.booster = booster;
this.max = time;
}
public static PlayerQueryEvent askEvent(UUID playerId, String message) {
@ -127,8 +128,8 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
return new PlayerQueryEvent(playerId, message, null, null, null, cards, QueryType.LOOK, 0, 0, false);
}
public static PlayerQueryEvent pickCard(UUID playerId, String message, List<Card> booster) {
return new PlayerQueryEvent(playerId, message, booster, QueryType.PICK_CARD);
public static PlayerQueryEvent pickCard(UUID playerId, String message, List<Card> booster, int time) {
return new PlayerQueryEvent(playerId, message, booster, QueryType.PICK_CARD, time);
}
public String getMessage() {

View file

@ -95,8 +95,8 @@ public class PlayerQueryEventSource implements EventSource<PlayerQueryEvent>, Se
dispatcher.fireEvent(PlayerQueryEvent.playXManaEvent(playerId, message));
}
public void pickCard(UUID playerId, String message, List<Card> booster) {
dispatcher.fireEvent(PlayerQueryEvent.pickCard(playerId, message, booster));
public void pickCard(UUID playerId, String message, List<Card> booster, int time) {
dispatcher.fireEvent(PlayerQueryEvent.pickCard(playerId, message, booster, time));
}
}