more draft/sealed fixes

This commit is contained in:
BetaSteward 2011-02-13 08:20:14 -05:00
parent e189543699
commit fabcc28e46
16 changed files with 171 additions and 86 deletions

View file

@ -276,7 +276,7 @@ public class NewTournamentDialog extends MageDialog {
tOptions.setTournamentType(tournamentType.getName()); tOptions.setTournamentType(tournamentType.getName());
tOptions.getPlayerTypes().add("Human"); tOptions.getPlayerTypes().add("Human");
for (TournamentPlayerPanel player: players) { for (TournamentPlayerPanel player: players) {
tOptions.getPlayerTypes().add(player.getPlayerType()); tOptions.getPlayerTypes().add((String) player.getPlayerType().getSelectedItem());
} }
if (tournamentType.isDraft()) { if (tournamentType.isDraft()) {
DraftOptions options = new DraftOptions(); DraftOptions options = new DraftOptions();
@ -347,12 +347,33 @@ public class NewTournamentDialog extends MageDialog {
pack.setModel(new DefaultComboBoxModel(Sets.getInstance().values().toArray())); pack.setModel(new DefaultComboBoxModel(Sets.getInstance().values().toArray()));
pnlPacks.add(pack); pnlPacks.add(pack);
packs.add(pack); packs.add(pack);
pack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
packActionPerformed(evt);
}
});
} }
this.pack(); this.pack();
this.revalidate(); this.revalidate();
this.repaint(); this.repaint();
} }
private void packActionPerformed(java.awt.event.ActionEvent evt) {
boolean start = false;
int selectedIndex = 0;
for (JComboBox pack: packs) {
if (!start) {
if (evt.getSource().equals(pack)) {
start = true;
selectedIndex = pack.getSelectedIndex();
}
}
else {
pack.setSelectedIndex(selectedIndex);
}
}
}
private void createPlayers(int numPlayers) { private void createPlayers(int numPlayers) {
if (numPlayers > players.size()) { if (numPlayers > players.size()) {
while (players.size() != numPlayers) { while (players.size() != numPlayers) {
@ -373,12 +394,33 @@ public class NewTournamentDialog extends MageDialog {
this.pnlOtherPlayers.removeAll(); this.pnlOtherPlayers.removeAll();
for (TournamentPlayerPanel panel: players) { for (TournamentPlayerPanel panel: players) {
this.pnlOtherPlayers.add(panel); this.pnlOtherPlayers.add(panel);
panel.getPlayerType().addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
playerActionPerformed(evt);
}
});
} }
this.pack(); this.pack();
this.revalidate(); this.revalidate();
this.repaint(); this.repaint();
} }
private void playerActionPerformed(java.awt.event.ActionEvent evt) {
boolean start = false;
int selectedIndex = 0;
for (TournamentPlayerPanel player: players) {
if (!start) {
if (evt.getSource().equals(player.getPlayerType())) {
start = true;
selectedIndex = player.getPlayerType().getSelectedIndex();
}
}
else {
player.getPlayerType().setSelectedIndex(selectedIndex);
}
}
}
public TableView getTable() { public TableView getTable() {
return table; return table;
} }

View file

@ -36,6 +36,7 @@ package mage.client.table;
import java.util.UUID; import java.util.UUID;
import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.remote.Session; import mage.client.remote.Session;
@ -59,8 +60,8 @@ public class TournamentPlayerPanel extends javax.swing.JPanel {
this.lblPlayerNum.setText("Player " + playerNum); this.lblPlayerNum.setText("Player " + playerNum);
} }
public String getPlayerType() { public JComboBox getPlayerType() {
return (String) this.cbPlayerType.getSelectedItem(); return this.cbPlayerType;
} }
public boolean joinTournamentTable(UUID roomId, UUID tableId) { public boolean joinTournamentTable(UUID roomId, UUID tableId) {

View file

@ -57,6 +57,7 @@ import mage.choices.ChoiceImpl;
import mage.filter.common.FilterCreatureForCombat; import mage.filter.common.FilterCreatureForCombat;
import mage.game.Game; import mage.game.Game;
import mage.game.Table; import mage.game.Table;
import mage.game.match.Match;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.tournament.Tournament; import mage.game.tournament.Tournament;
import mage.target.Target; import mage.target.Target;
@ -482,8 +483,8 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
} }
@Override @Override
public void sideboard(Table table, Deck deck) { public void sideboard(Match match, Deck deck) {
table.fireSideboardEvent(playerId, deck); match.fireSideboardEvent(playerId, deck);
} }
@Override @Override

View file

@ -1,5 +0,0 @@
#Generated by Maven
#Sat Feb 12 11:24:53 MSK 2011
version=0.6
groupId=org.mage
artifactId=Mage-Tournament-BoosterDraft

View file

@ -66,7 +66,6 @@ import mage.game.match.MatchOptions;
import mage.game.match.MatchPlayer; import mage.game.match.MatchPlayer;
import mage.game.tournament.Tournament; import mage.game.tournament.Tournament;
import mage.game.tournament.TournamentOptions; import mage.game.tournament.TournamentOptions;
import mage.game.tournament.TournamentPlayer;
import mage.players.Player; import mage.players.Player;
import mage.server.game.DeckValidatorFactory; import mage.server.game.DeckValidatorFactory;
import mage.server.game.GameFactory; import mage.server.game.GameFactory;
@ -85,15 +84,12 @@ public class TableController {
private final static Logger logger = Logging.getLogger(TableController.class.getName()); private final static Logger logger = Logging.getLogger(TableController.class.getName());
private static final int SIDEBOARD_TIME = 180;
private UUID sessionId; private UUID sessionId;
private UUID chatId; private UUID chatId;
private Table table; private Table table;
private Match match; private Match match;
private MatchOptions options; private MatchOptions options;
private Tournament tournament; private Tournament tournament;
private TournamentOptions tournamentOptions;
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>(); private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
public TableController(UUID sessionId, MatchOptions options) { public TableController(UUID sessionId, MatchOptions options) {
@ -108,24 +104,19 @@ public class TableController {
public TableController(UUID sessionId, TournamentOptions options) { public TableController(UUID sessionId, TournamentOptions options) {
this.sessionId = sessionId; this.sessionId = sessionId;
chatId = ChatManager.getInstance().createChatSession(); chatId = ChatManager.getInstance().createChatSession();
this.tournamentOptions = options;
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options); tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), true); table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), true);
init();
} }
private void init() { private void init() {
table.addTableEventListener( match.addTableEventListener(
new Listener<TableEvent> () { new Listener<TableEvent> () {
@Override @Override
public void event(TableEvent event) { public void event(TableEvent event) {
switch (event.getEventType()) { switch (event.getEventType()) {
case SIDEBOARD: case SIDEBOARD:
sideboard(event.getPlayerId(), event.getDeck()); sideboard(event.getPlayerId(), event.getDeck(), event.getTimeout());
break; break;
// case CONSTRUCT:
// construct(event.getPlayerId(), event.getDeck());
// break;
case SUBMIT_DECK: case SUBMIT_DECK:
submitDeck(event.getPlayerId(), event.getDeck()); submitDeck(event.getPlayerId(), event.getDeck());
break; break;
@ -209,8 +200,7 @@ public class TableController {
private void submitDeck(UUID sessionId, Deck deck) { private void submitDeck(UUID sessionId, Deck deck) {
if (table.getState() == TableState.SIDEBOARDING) { if (table.getState() == TableState.SIDEBOARDING) {
MatchPlayer player = match.getPlayer(sessionPlayerMap.get(sessionId)); match.submitDeck(sessionPlayerMap.get(sessionId), deck);
player.submitDeck(deck);
} }
else { else {
TournamentManager.getInstance().submitDeck(tournament.getId(), sessionId, deck); TournamentManager.getInstance().submitDeck(tournament.getId(), sessionId, deck);
@ -262,7 +252,13 @@ public class TableController {
} }
public synchronized void startMatch(UUID sessionId) { public synchronized void startMatch(UUID sessionId) {
if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) { if (sessionId.equals(this.sessionId)) {
startMatch();
}
}
public synchronized void startMatch() {
if (table.getState() == TableState.STARTING) {
try { try {
match.startMatch(); match.startMatch();
startGame(null); startGame(null);
@ -284,7 +280,6 @@ public class TableController {
public synchronized void startTournament(UUID sessionId) { public synchronized void startTournament(UUID sessionId) {
if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) { if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) {
table.initTournament();
TournamentManager.getInstance().createTournamentSession(tournament, sessionPlayerMap, table.getId()); TournamentManager.getInstance().createTournamentSession(tournament, sessionPlayerMap, table.getId());
SessionManager sessionManager = SessionManager.getInstance(); SessionManager sessionManager = SessionManager.getInstance();
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) { for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
@ -302,42 +297,19 @@ public class TableController {
} }
} }
private void sideboard() { private void sideboard(UUID playerId, Deck deck, int timeout) {
table.sideboard();
for (MatchPlayer player: match.getPlayers()) {
player.setSideboarding();
player.getPlayer().sideboard(table, player.getDeck());
}
while (!match.isDoneSideboarding()){}
}
private void sideboard(UUID playerId, Deck deck) {
SessionManager sessionManager = SessionManager.getInstance(); SessionManager sessionManager = SessionManager.getInstance();
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) { for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
if (entry.getValue().equals(playerId)) { if (entry.getValue().equals(playerId)) {
sessionManager.getSession(entry.getKey()).sideboard(deck, table.getId(), SIDEBOARD_TIME); sessionManager.getSession(entry.getKey()).sideboard(deck, table.getId(), timeout);
break; break;
} }
} }
} }
// public void construct() { public void construct() {
// table.construct(); table.construct();
// for (TournamentPlayer player: tournament.getPlayers()) { }
// player.setConstructing();
// player.getPlayer().construct(table, player.getDeck());
// }
// }
// 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(), CONSTRUCT_TIME);
// break;
// }
// }
// }
public void endGame() { public void endGame() {
UUID choosingPlayerId = match.getChooser(); UUID choosingPlayerId = match.getChooser();
@ -347,7 +319,8 @@ public class TableController {
GameManager.getInstance().removeGame(match.getGame().getId()); GameManager.getInstance().removeGame(match.getGame().getId());
try { try {
if (!match.isMatchOver()) { if (!match.isMatchOver()) {
sideboard(); table.sideboard();
match.sideboard();
startGame(choosingPlayerId); startGame(choosingPlayerId);
} }
} catch (GameException ex) { } catch (GameException ex) {
@ -433,4 +406,5 @@ public class TableController {
public Match getMatch() { public Match getMatch() {
return match; return match;
} }
} }

View file

@ -67,6 +67,13 @@ public class TableManager {
return tableController.getTable(); return tableController.getTable();
} }
public Table createTable(MatchOptions options) {
TableController tableController = new TableController(UUID.randomUUID(), options);
controllers.put(tableController.getTable().getId(), tableController);
tables.put(tableController.getTable().getId(), tableController.getTable());
return tableController.getTable();
}
public Table createTournamentTable(UUID sessionId, TournamentOptions options) { public Table createTournamentTable(UUID sessionId, TournamentOptions options) {
TableController tableController = new TableController(sessionId, options); TableController tableController = new TableController(sessionId, options);
controllers.put(tableController.getTable().getId(), tableController); controllers.put(tableController.getTable().getId(), tableController);
@ -127,6 +134,10 @@ public class TableManager {
controllers.get(tableId).startMatch(sessionId); controllers.get(tableId).startMatch(sessionId);
} }
public void startMatch(UUID roomId, UUID tableId) {
controllers.get(tableId).startMatch();
}
public void startTournament(UUID sessionId, UUID roomId, UUID tableId) { public void startTournament(UUID sessionId, UUID roomId, UUID tableId) {
controllers.get(tableId).startTournament(sessionId); controllers.get(tableId).startTournament(sessionId);
} }
@ -161,11 +172,12 @@ public class TableManager {
} }
} }
// public void construct(UUID tableId) { public void construct(UUID tableId) {
// controllers.get(tableId).construct(); controllers.get(tableId).construct();
// } }
public void addPlayer(UUID sessionId, UUID tableId, Player player, String playerType, Deck deck) throws GameException { public void addPlayer(UUID sessionId, UUID tableId, Player player, String playerType, Deck deck) throws GameException {
controllers.get(tableId).addPlayer(sessionId, player, playerType, deck); controllers.get(tableId).addPlayer(sessionId, player, playerType, deck);
} }
} }

View file

@ -66,8 +66,6 @@ public class TournamentController {
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>(); private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
private ConcurrentHashMap<UUID, TournamentSession> tournamentSessions = new ConcurrentHashMap<UUID, TournamentSession>(); private ConcurrentHashMap<UUID, TournamentSession> tournamentSessions = new ConcurrentHashMap<UUID, TournamentSession>();
private static final int CONSTRUCT_TIME = 600;
public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) { public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
sessionId = UUID.randomUUID(); sessionId = UUID.randomUUID();
this.sessionPlayerMap = sessionPlayerMap; this.sessionPlayerMap = sessionPlayerMap;
@ -96,6 +94,9 @@ public class TournamentController {
case SUBMIT_DECK: case SUBMIT_DECK:
submitDeck(event.getPlayerId(), event.getDeck()); submitDeck(event.getPlayerId(), event.getDeck());
break; break;
case CONSTRUCT:
construct();
break;
} }
} }
} }
@ -170,12 +171,12 @@ public class TournamentController {
private void startMatch(TournamentPairing pair, MatchOptions matchOptions) { private void startMatch(TournamentPairing pair, MatchOptions matchOptions) {
try { try {
TableManager tableManager = TableManager.getInstance(); TableManager tableManager = TableManager.getInstance();
Table table = tableManager.createTable(sessionId, matchOptions); Table table = tableManager.createTable(matchOptions);
TournamentPlayer player1 = pair.getPlayer1(); TournamentPlayer player1 = pair.getPlayer1();
TournamentPlayer player2 = pair.getPlayer2(); TournamentPlayer player2 = pair.getPlayer2();
tableManager.addPlayer(getPlayerSessionId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getPlayerType(), player1.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.addPlayer(getPlayerSessionId(player2.getPlayer().getId()), table.getId(), player2.getPlayer(), player2.getPlayerType(), player2.getDeck());
tableManager.startMatch(sessionId, null, table.getId()); tableManager.startMatch(null, table.getId());
pair.setMatch(tableManager.getMatch(table.getId())); pair.setMatch(tableManager.getMatch(table.getId()));
} catch (GameException ex) { } catch (GameException ex) {
Logger.getLogger(TournamentController.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(TournamentController.class.getName()).log(Level.SEVERE, null, ex);
@ -186,12 +187,15 @@ public class TournamentController {
TableManager.getInstance().startDraft(tableId, draft); TableManager.getInstance().startDraft(tableId, draft);
} }
private void construct() {
TableManager.getInstance().construct(tableId);
}
private synchronized void construct(UUID sessionId, Deck deck, int timeout) { private synchronized void construct(UUID sessionId, Deck deck, int timeout) {
if (tournamentSessions.containsKey(sessionId)) if (tournamentSessions.containsKey(sessionId))
tournamentSessions.get(sessionId).construct(deck, timeout); tournamentSessions.get(sessionId).construct(deck, timeout);
} }
public void submitDeck(UUID sessionId, Deck deck) { public void submitDeck(UUID sessionId, Deck deck) {
tournamentSessions.get(sessionPlayerMap.get(sessionId)).submitDeck(deck); tournamentSessions.get(sessionPlayerMap.get(sessionId)).submitDeck(deck);
} }

View file

@ -84,10 +84,18 @@ public class Table implements Serializable {
state = TableState.DUELING; state = TableState.DUELING;
} }
public void initTournament() {
state = TableState.DUELING;
}
public void initDraft() { public void initDraft() {
state = TableState.DRAFTING; state = TableState.DRAFTING;
} }
public void construct() {
state = TableState.CONSTRUCTING;
}
public void endGame() { public void endGame() {
state = TableState.FINISHED; state = TableState.FINISHED;
} }
@ -157,24 +165,8 @@ public class Table implements Serializable {
return this.name; return this.name;
} }
public void fireSideboardEvent(UUID playerId, Deck deck) {
tableEventSource.fireTableEvent(EventType.SIDEBOARD, playerId, deck);
}
public void fireConstructEvent(UUID playerId, Deck deck) {
tableEventSource.fireTableEvent(EventType.CONSTRUCT, playerId, deck);
}
public void fireSubmitDeckEvent(UUID playerId, Deck deck) {
tableEventSource.fireTableEvent(EventType.SUBMIT_DECK, playerId, deck);
}
public void addTableEventListener(Listener<TableEvent> listener) { public void addTableEventListener(Listener<TableEvent> listener) {
tableEventSource.addListener(listener); tableEventSource.addListener(listener);
} }
public void initTournament() {
state = TableState.CONSTRUCTING;
}
} }

View file

@ -56,6 +56,7 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
private Deck deck; private Deck deck;
private TournamentPairing pair; private TournamentPairing pair;
private MatchOptions options; private MatchOptions options;
private int timeout;
public TableEvent(EventType eventType) { public TableEvent(EventType eventType) {
super(eventType); super(eventType);
@ -70,11 +71,12 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
this.eventType = eventType; this.eventType = eventType;
} }
public TableEvent(EventType eventType, UUID playerId, Deck deck) { public TableEvent(EventType eventType, UUID playerId, Deck deck, int timeout) {
super(playerId); super(playerId);
this.playerId = playerId; this.playerId = playerId;
this.deck = deck; this.deck = deck;
this.eventType = eventType; this.eventType = eventType;
this.timeout = timeout;
} }
public TableEvent(EventType eventType, String message, Draft draft) { public TableEvent(EventType eventType, String message, Draft draft) {
@ -126,4 +128,8 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
public MatchOptions getMatchOptions() { public MatchOptions getMatchOptions() {
return options; return options;
} }
public int getTimeout() {
return timeout;
}
} }

View file

@ -67,8 +67,8 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
dispatcher.fireEvent(new TableEvent(eventType, message, cards, game)); dispatcher.fireEvent(new TableEvent(eventType, message, cards, game));
} }
public void fireTableEvent(EventType eventType, UUID playerId, Deck deck) { public void fireTableEvent(EventType eventType, UUID playerId, Deck deck, int timeout) {
dispatcher.fireEvent(new TableEvent(eventType, playerId, deck)); dispatcher.fireEvent(new TableEvent(eventType, playerId, deck, timeout));
} }
public void fireTableEvent(EventType eventType, TournamentPairing pair, MatchOptions options) { public void fireTableEvent(EventType eventType, TournamentPairing pair, MatchOptions options) {

View file

@ -33,6 +33,8 @@ import java.util.UUID;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.game.Game; import mage.game.Game;
import mage.game.GameException; import mage.game.GameException;
import mage.game.events.Listener;
import mage.game.events.TableEvent;
import mage.players.Player; import mage.players.Player;
/** /**
@ -46,8 +48,10 @@ public interface Match {
public List<MatchPlayer> getPlayers(); public List<MatchPlayer> getPlayers();
public MatchPlayer getPlayer(UUID playerId); public MatchPlayer getPlayer(UUID playerId);
public void addPlayer(Player player, Deck deck); public void addPlayer(Player player, Deck deck);
public void submitDeck(UUID playerId, Deck deck);
public void startMatch() throws GameException; public void startMatch() throws GameException;
public void startGame() throws GameException; public void startGame() throws GameException;
public void sideboard();
public void endGame(); public void endGame();
public Game getGame(); public Game getGame();
public List<Game> getGames(); public List<Game> getGames();
@ -56,4 +60,7 @@ public interface Match {
public boolean isDoneSideboarding(); public boolean isDoneSideboarding();
public UUID getChooser(); public UUID getChooser();
public void addTableEventListener(Listener<TableEvent> listener);
public void fireSideboardEvent(UUID playerId, Deck deck);
} }

View file

@ -35,6 +35,10 @@ import java.util.logging.Logger;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.game.Game; import mage.game.Game;
import mage.game.GameException; import mage.game.GameException;
import mage.game.events.Listener;
import mage.game.events.TableEvent;
import mage.game.events.TableEvent.EventType;
import mage.game.events.TableEventSource;
import mage.players.Player; import mage.players.Player;
import mage.util.Logging; import mage.util.Logging;
@ -45,12 +49,15 @@ import mage.util.Logging;
public abstract class MatchImpl implements Match { public abstract class MatchImpl implements Match {
private final static Logger logger = Logging.getLogger(MatchImpl.class.getName()); private final static Logger logger = Logging.getLogger(MatchImpl.class.getName());
private static final int SIDEBOARD_TIME = 180;
protected UUID id = UUID.randomUUID(); protected UUID id = UUID.randomUUID();
protected List<MatchPlayer> players = new ArrayList<MatchPlayer>(); protected List<MatchPlayer> players = new ArrayList<MatchPlayer>();
protected List<Game> games = new ArrayList<Game>(); protected List<Game> games = new ArrayList<Game>();
protected MatchOptions options; protected MatchOptions options;
protected TableEventSource tableEventSource = new TableEventSource();
public MatchImpl(MatchOptions options) { public MatchImpl(MatchOptions options) {
this.options = options; this.options = options;
} }
@ -151,6 +158,26 @@ public abstract class MatchImpl implements Match {
return loserId; return loserId;
} }
@Override
public void addTableEventListener(Listener<TableEvent> listener) {
tableEventSource.addListener(listener);
}
@Override
public void sideboard() {
for (MatchPlayer player: this.players) {
player.setSideboarding();
player.getPlayer().sideboard(this, player.getDeck());
}
synchronized(this) {
while (!isDoneSideboarding()) {
try {
this.wait();
} catch (InterruptedException ex) { }
}
}
}
@Override @Override
public boolean isDoneSideboarding() { public boolean isDoneSideboarding() {
for (MatchPlayer player: this.players) { for (MatchPlayer player: this.players) {
@ -160,4 +187,23 @@ public abstract class MatchImpl implements Match {
return true; return true;
} }
@Override
public void fireSideboardEvent(UUID playerId, Deck deck) {
MatchPlayer player = getPlayer(playerId);
if (player != null) {
tableEventSource.fireTableEvent(EventType.SIDEBOARD, playerId, deck, SIDEBOARD_TIME);
}
}
@Override
public void submitDeck(UUID playerId, Deck deck) {
MatchPlayer player = getPlayer(playerId);
if (player != null) {
player.submitDeck(deck);
}
synchronized (this) {
this.notifyAll();
}
}
} }

View file

@ -41,6 +41,7 @@ import java.util.logging.Logger;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.ExpansionSet; import mage.cards.ExpansionSet;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.game.Table;
import mage.game.events.Listener; import mage.game.events.Listener;
import mage.game.events.PlayerQueryEvent; import mage.game.events.PlayerQueryEvent;
import mage.game.events.PlayerQueryEventSource; import mage.game.events.PlayerQueryEventSource;
@ -63,8 +64,10 @@ public abstract class TournamentImpl implements Tournament {
protected String matchName; protected String matchName;
protected TournamentOptions options; protected TournamentOptions options;
protected transient TableEventSource tableEventSource = new TableEventSource(); protected TableEventSource tableEventSource = new TableEventSource();
protected transient PlayerQueryEventSource playerQueryEventSource = new PlayerQueryEventSource(); protected PlayerQueryEventSource playerQueryEventSource = new PlayerQueryEventSource();
private static final int CONSTRUCT_TIME = 600;
public TournamentImpl(TournamentOptions options) { public TournamentImpl(TournamentOptions options) {
this.options = options; this.options = options;
@ -209,7 +212,7 @@ public abstract class TournamentImpl implements Tournament {
@Override @Override
public void fireSubmitDeckEvent(UUID playerId, Deck deck) { public void fireSubmitDeckEvent(UUID playerId, Deck deck) {
tableEventSource.fireTableEvent(EventType.SUBMIT_DECK, playerId, deck); tableEventSource.fireTableEvent(EventType.SUBMIT_DECK, playerId, deck, 0);
} }
@Override @Override
@ -220,10 +223,11 @@ public abstract class TournamentImpl implements Tournament {
@Override @Override
public void fireConstructEvent(UUID playerId, Deck deck) { public void fireConstructEvent(UUID playerId, Deck deck) {
TournamentPlayer player = players.get(playerId); TournamentPlayer player = players.get(playerId);
playerQueryEventSource.construct(playerId, "Construct", deck, 600); playerQueryEventSource.construct(playerId, "Construct", deck, CONSTRUCT_TIME);
} }
public void construct() { public void construct() {
tableEventSource.fireTableEvent(EventType.CONSTRUCT);
for (TournamentPlayer player: players.values()) { for (TournamentPlayer player: players.values()) {
player.setConstructing(); player.setConstructing();
player.getPlayer().construct(this, player.getDeck()); player.getPlayer().construct(this, player.getDeck());

View file

@ -56,6 +56,7 @@ import mage.game.events.GameEvent;
import mage.game.Game; import mage.game.Game;
import mage.game.Table; import mage.game.Table;
import mage.game.draft.Draft; import mage.game.draft.Draft;
import mage.game.match.Match;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.tournament.Tournament; import mage.game.tournament.Tournament;
import mage.target.Target; import mage.target.Target;
@ -154,7 +155,7 @@ public interface Player extends MageItem, Copyable<Player> {
public abstract void selectBlockers(Game game); public abstract void selectBlockers(Game game);
public abstract void assignDamage(int damage, List<UUID> targets, UUID sourceId, Game game); public abstract void assignDamage(int damage, List<UUID> targets, UUID sourceId, Game game);
public abstract int getAmount(int min, int max, String message, Game game); public abstract int getAmount(int min, int max, String message, Game game);
public abstract void sideboard(Table table, Deck deck); public abstract void sideboard(Match match, Deck deck);
public abstract void construct(Tournament tournament, Deck deck); public abstract void construct(Tournament tournament, Deck deck);
public abstract void pickCard(List<Card> cards, Deck deck, Draft draft); public abstract void pickCard(List<Card> cards, Deck deck, Draft draft);