diff --git a/Mage.Client/src/main/java/mage/client/remote/Client.java b/Mage.Client/src/main/java/mage/client/remote/Client.java index 37cde55fadb..c124397b663 100644 --- a/Mage.Client/src/main/java/mage/client/remote/Client.java +++ b/Mage.Client/src/main/java/mage/client/remote/Client.java @@ -80,6 +80,10 @@ public class Client implements CallbackClient { GameManager.getInstance().setCurrentPlayerUUID(message.getPlayerId()); gameStarted(message.getGameId(), message.getPlayerId()); } + else if(callback.getMethod().equals("startDraft")) { + TableClientMessage message = (TableClientMessage) callback.getData(); + //TODO: add code to start draft + } else if (callback.getMethod().equals("replayGame")) { replayGame(); } diff --git a/Mage.Common/src/mage/interfaces/Server.java b/Mage.Common/src/mage/interfaces/Server.java index a97162992c4..20ed0b0a377 100644 --- a/Mage.Common/src/mage/interfaces/Server.java +++ b/Mage.Common/src/mage/interfaces/Server.java @@ -54,6 +54,7 @@ public interface Server extends Remote, CallbackServer { //table methods public TableView createTable(UUID sessionId, UUID roomId, MatchOptions matchOptions) throws RemoteException, MageException; public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, DeckCardLists deckList) throws RemoteException, MageException, GameException; + public boolean joinDraftTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws RemoteException, MageException, GameException; public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws RemoteException, MageException, GameException; public boolean watchTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException; public boolean replayTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException; @@ -88,6 +89,7 @@ public interface Server extends Remote, CallbackServer { //draft methods public void startDraft(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException; + public void joinDraft(UUID draftId, UUID sessionId) throws RemoteException, MageException; public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) throws RemoteException, MageException; //replay methods diff --git a/Mage.Common/src/mage/view/DraftClientMessage.java b/Mage.Common/src/mage/view/DraftClientMessage.java new file mode 100644 index 00000000000..f868c3fd414 --- /dev/null +++ b/Mage.Common/src/mage/view/DraftClientMessage.java @@ -0,0 +1,56 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.view; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DraftClientMessage implements Serializable { + + private DraftView draftView; + private DraftPickView draftPickView; + private String message; + + public DraftClientMessage(DraftView draftView) { + this.draftView = draftView; + } + + public DraftClientMessage(DraftPickView draftPickView) { + this.draftPickView = draftPickView; + } + + public DraftClientMessage(DraftView draftView, String message) { + this.message = message; + this.draftView = draftView; + } + +} diff --git a/Mage.Common/src/mage/view/DraftPickView.java b/Mage.Common/src/mage/view/DraftPickView.java new file mode 100644 index 00000000000..f1c98330b09 --- /dev/null +++ b/Mage.Common/src/mage/view/DraftPickView.java @@ -0,0 +1,51 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.view; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DraftPickView { + + protected CardsView booster; + protected CardsView picks; + + public DraftPickView() { + + } + + public CardsView getBooster() { + return booster; + } + + public CardsView getPicks() { + return picks; + } +} diff --git a/Mage.Common/src/mage/view/DraftView.java b/Mage.Common/src/mage/view/DraftView.java new file mode 100644 index 00000000000..ebb0dc13faf --- /dev/null +++ b/Mage.Common/src/mage/view/DraftView.java @@ -0,0 +1,48 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.view; + +import java.util.ArrayList; +import java.util.List; +import mage.game.draft.Draft; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DraftView { + + private List players = new ArrayList(); + + public DraftView(Draft draft) { + + } + + +} diff --git a/Mage.Common/src/mage/view/RoundView.java b/Mage.Common/src/mage/view/RoundView.java new file mode 100644 index 00000000000..1c60ee211b9 --- /dev/null +++ b/Mage.Common/src/mage/view/RoundView.java @@ -0,0 +1,43 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.view; + +import mage.game.tournament.Round; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class RoundView { + + public RoundView(Round round) { + + } + +} diff --git a/Mage.Common/src/mage/view/TournamentPlayerView.java b/Mage.Common/src/mage/view/TournamentPlayerView.java new file mode 100644 index 00000000000..084dff7b9aa --- /dev/null +++ b/Mage.Common/src/mage/view/TournamentPlayerView.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.view; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TournamentPlayerView { + +} diff --git a/Mage.Common/src/mage/view/TournamentView.java b/Mage.Common/src/mage/view/TournamentView.java new file mode 100644 index 00000000000..2a44b1f42d8 --- /dev/null +++ b/Mage.Common/src/mage/view/TournamentView.java @@ -0,0 +1,46 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.view; + +import java.util.ArrayList; +import java.util.List; +import mage.game.tournament.Tournament; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TournamentView { + + List rounds = new ArrayList(); + + public TournamentView(Tournament tournament) { + + } +} diff --git a/Mage.Server/src/main/java/mage/server/ServerImpl.java b/Mage.Server/src/main/java/mage/server/ServerImpl.java index 67f5d161164..f35a27f1bfd 100644 --- a/Mage.Server/src/main/java/mage/server/ServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/ServerImpl.java @@ -47,6 +47,7 @@ import mage.interfaces.Server; import mage.interfaces.ServerState; import mage.interfaces.callback.ClientCallback; import mage.server.game.DeckValidatorFactory; +import mage.server.game.DraftManager; import mage.server.game.GameFactory; import mage.server.game.GameManager; import mage.server.game.GamesRoomManager; @@ -159,6 +160,21 @@ public class ServerImpl extends RemoteServer implements Server { return false; } + @Override + public boolean joinDraftTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws MageException, GameException { + try { + boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinDraftTable(sessionId, tableId, name); + logger.info("Session " + sessionId + " joined table " + tableId); + return ret; + } + catch (Exception ex) { + if (ex instanceof GameException) + throw (GameException)ex; + handleException(ex); + } + return false; + } + @Override public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException { try { @@ -232,13 +248,13 @@ public class ServerImpl extends RemoteServer implements Server { } @Override - public void startDraft(final UUID sessionId, final UUID roomId, final UUID draftId) throws MageException { + public void startDraft(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException { try { rmiExecutor.execute( new Runnable() { @Override public void run() { -// TableManager.getInstance().startMatch(sessionId, roomId, tableId); + TableManager.getInstance().startDraft(sessionId, roomId, tableId); } } ); @@ -394,6 +410,23 @@ public class ServerImpl extends RemoteServer implements Server { } } + @Override + public void joinDraft(final UUID draftId, final UUID sessionId) throws MageException { + try { + rmiExecutor.execute( + new Runnable() { + @Override + public void run() { + DraftManager.getInstance().joinDraft(draftId, sessionId); + } + } + ); + } + catch (Exception ex) { + handleException(ex); + } + } + @Override public UUID getGameChatId(UUID gameId) throws MageException { try { @@ -474,13 +507,13 @@ public class ServerImpl extends RemoteServer implements Server { } @Override - public void sendCardPick(final UUID gameId, final UUID sessionId, final UUID cardPick) throws MageException { + public void sendCardPick(final UUID draftId, final UUID sessionId, final UUID cardPick) throws MageException { try { rmiExecutor.execute( new Runnable() { @Override public void run() { -// GameManager.getInstance().sendPlayerUUID(gameId, sessionId, data); + DraftManager.getInstance().sendCardPick(draftId, sessionId, cardPick); } } ); diff --git a/Mage.Server/src/main/java/mage/server/Session.java b/Mage.Server/src/main/java/mage/server/Session.java index 055d334a20d..5dec0724d05 100644 --- a/Mage.Server/src/main/java/mage/server/Session.java +++ b/Mage.Server/src/main/java/mage/server/Session.java @@ -95,6 +95,10 @@ public class Session { fireCallback(new ClientCallback("startGame", new TableClientMessage(gameId, playerId))); } + public void draftStarted(final UUID draftId, final UUID playerId) { + fireCallback(new ClientCallback("startDraft", new TableClientMessage(draftId, playerId))); + } + public void sideboard(final Deck deck, final UUID tableId) { fireCallback(new ClientCallback("sideboard", new TableClientMessage(deck, tableId))); } diff --git a/Mage.Server/src/main/java/mage/server/game/DraftController.java b/Mage.Server/src/main/java/mage/server/game/DraftController.java new file mode 100644 index 00000000000..9e47bfe8f5a --- /dev/null +++ b/Mage.Server/src/main/java/mage/server/game/DraftController.java @@ -0,0 +1,202 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.server.game; + +import java.io.File; +import java.util.UUID; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.logging.Logger; + +import mage.game.draft.Draft; +import mage.game.draft.DraftPlayer; +import mage.game.events.Listener; +import mage.game.events.PlayerQueryEvent; +import mage.game.events.TableEvent; +import mage.server.ChatManager; +import mage.server.util.ThreadExecutor; +import mage.util.Logging; +import mage.view.DraftPickView; +import mage.view.ChatMessage.MessageColor; +import mage.view.DraftView; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DraftController { + +// private static ExecutorService gameExecutor = ThreadExecutor.getInstance().getGameExecutor(); + private final static Logger logger = Logging.getLogger(GameController.class.getName()); + public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt"; + + private ConcurrentHashMap draftSessions = new ConcurrentHashMap(); +// private ConcurrentHashMap watchers = new ConcurrentHashMap(); + private ConcurrentHashMap sessionPlayerMap; + private UUID draftSessionId; + private Draft draft; + private UUID chatId; + private UUID tableId; + + public DraftController(Draft draft, ConcurrentHashMap sessionPlayerMap, UUID tableId) { + draftSessionId = UUID.randomUUID(); + this.sessionPlayerMap = sessionPlayerMap; + chatId = ChatManager.getInstance().createChatSession(); + this.draft = draft; + this.tableId = tableId; + init(); + } + + private void init() { + draft.addTableEventListener( + new Listener () { + @Override + public void event(TableEvent event) { + switch (event.getEventType()) { + case UPDATE: + updateDraft(); + break; + } + } + } + ); + draft.addPlayerQueryEventListener( + new Listener () { + @Override + public void event(PlayerQueryEvent event) { + switch (event.getQueryType()) { + case PICK_CARD: + pickCard(event.getPlayerId()); + break; + } + } + } + ); + } + + private UUID getPlayerId(UUID sessionId) { + return sessionPlayerMap.get(sessionId); + } + + public void join(UUID sessionId) { + UUID playerId = sessionPlayerMap.get(sessionId); + DraftSession draftSession = new DraftSession(sessionId, draft.getId()); + draftSessions.put(playerId, draftSession); + logger.info("player " + playerId + " has joined draft " + draft.getId()); + ChatManager.getInstance().broadcast(chatId, "", draft.getPlayer(playerId).getPlayer().getName() + " has joined the draft", MessageColor.BLACK); + if (allJoined()) { + ThreadExecutor.getInstance().getRMIExecutor().execute( + new Runnable() { + @Override + public void run() { + startDraft(); + } + }); + } + } + + private synchronized void startDraft() { + for (final Entry entry: draftSessions.entrySet()) { + if (!entry.getValue().init(getDraftView())) { + logger.severe("Unable to initialize client"); + //TODO: generate client error message + return; + } + } + } + + private boolean allJoined() { + for (DraftPlayer player: draft.getPlayers()) { + if (player.getPlayer().isHuman() && draftSessions.get(player.getPlayer().getId()) == null) { + return false; + } + } + return true; + } + + private void leave(UUID sessionId) { + draft.leave(getPlayerId(sessionId)); + } + + public void kill(UUID sessionId) { + if (sessionPlayerMap.containsKey(sessionId)) { + draftSessions.get(sessionPlayerMap.get(sessionId)).setKilled(); + draftSessions.remove(sessionPlayerMap.get(sessionId)); + leave(sessionId); + sessionPlayerMap.remove(sessionId); + } + } + + public void timeout(UUID sessionId) { + if (sessionPlayerMap.containsKey(sessionId)) { + ChatManager.getInstance().broadcast(chatId, "", draft.getPlayer(sessionPlayerMap.get(sessionId)).getPlayer().getName() + " has timed out. Auto picking.", MessageColor.BLACK); + draft.autoPick(sessionPlayerMap.get(sessionId)); + } + } + + public void endDraft(final String message) { + for (final DraftSession draftSession: draftSessions.values()) { + draftSession.gameOver(message); + } + TableManager.getInstance().endGame(tableId); + } + + public UUID getSessionId() { + return this.draftSessionId; + } + + public UUID getChatId() { + return chatId; + } + + public void sendCardPick(UUID sessionId, UUID cardId) { + draft.addPick(sessionPlayerMap.get(sessionId), cardId); + } + + private synchronized void updateDraft() { + for (final Entry entry: draftSessions.entrySet()) { + entry.getValue().update(getDraftView()); + } + } + + private synchronized void pickCard(UUID playerId) { + if (draftSessions.containsKey(playerId)) + draftSessions.get(playerId).pickCard(getDraftPickView(playerId)); + } + + private DraftView getDraftView() { + return new DraftView(draft); + } + + private DraftPickView getDraftPickView(UUID playerId) { + return new DraftPickView(); + } + +} diff --git a/Mage.Server/src/main/java/mage/server/game/DraftFactory.java b/Mage.Server/src/main/java/mage/server/game/DraftFactory.java new file mode 100644 index 00000000000..8b528c0008f --- /dev/null +++ b/Mage.Server/src/main/java/mage/server/game/DraftFactory.java @@ -0,0 +1,79 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.server.game; + +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import mage.game.draft.Draft; +import mage.game.draft.DraftOptions; +import mage.util.Logging; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DraftFactory { + + private final static DraftFactory INSTANCE = new DraftFactory(); + private final static Logger logger = Logging.getLogger(DraftFactory.class.getName()); + + private Map> drafts = new HashMap>(); + + public static DraftFactory getInstance() { + return INSTANCE; + } + + private DraftFactory() {} + + public Draft createDraft(String draftType, DraftOptions options) { + + Draft draft; + Constructor con; + try { + con = drafts.get(draftType).getConstructor(new Class[]{DraftOptions.class}); + draft = con.newInstance(new Object[] {options}); + } catch (Exception ex) { + logger.log(Level.SEVERE, null, ex); + return null; + } + logger.info("Draft created: " + draftType); // + game.getId().toString()); + + return draft; + } + + public void addDraftType(String name, Class draft) { + if (draft != null) { + this.drafts.put(name, draft); + } + } + +} diff --git a/Mage.Server/src/main/java/mage/server/game/DraftManager.java b/Mage.Server/src/main/java/mage/server/game/DraftManager.java new file mode 100644 index 00000000000..b0b65aab7a4 --- /dev/null +++ b/Mage.Server/src/main/java/mage/server/game/DraftManager.java @@ -0,0 +1,90 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.server.game; + +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import mage.game.draft.Draft; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DraftManager { + private final static DraftManager INSTANCE = new DraftManager(); + + public static DraftManager getInstance() { + return INSTANCE; + } + + private DraftManager() {} + + private ConcurrentHashMap draftControllers = new ConcurrentHashMap(); + + public UUID createDraftSession(Draft draft, ConcurrentHashMap sessionPlayerMap, UUID tableId) { + DraftController draftController = new DraftController(draft, sessionPlayerMap, tableId); + draftControllers.put(draft.getId(), draftController); + return draftController.getSessionId(); + } + + public void joinDraft(UUID draftId, UUID sessionId) { + draftControllers.get(draftId).join(sessionId); + } + + public void destroyChatSession(UUID gameId) { + draftControllers.remove(gameId); + } + + public UUID getChatId(UUID draftId) { + return draftControllers.get(draftId).getChatId(); + } + + public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) { + draftControllers.get(draftId).sendCardPick(sessionId, cardId); + } + + public void removeSession(UUID sessionId) { + for (DraftController controller: draftControllers.values()) { + controller.kill(sessionId); + } + } + + public void kill(UUID draftId, UUID sessionId) { + draftControllers.get(draftId).kill(sessionId); + } + + void timeout(UUID gameId, UUID sessionId) { + draftControllers.get(gameId).timeout(sessionId); + } + + void removeDraft(UUID draftId) { + draftControllers.remove(draftId); + } + +} diff --git a/Mage.Server/src/main/java/mage/server/game/DraftSession.java b/Mage.Server/src/main/java/mage/server/game/DraftSession.java new file mode 100644 index 00000000000..c8fb939eedf --- /dev/null +++ b/Mage.Server/src/main/java/mage/server/game/DraftSession.java @@ -0,0 +1,150 @@ +/* +* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.server.game; + +import java.rmi.RemoteException; +import java.util.UUID; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; +import mage.interfaces.callback.ClientCallback; +import mage.server.Session; +import mage.server.SessionManager; +import mage.server.util.ThreadExecutor; +import mage.util.Logging; +import mage.view.DraftClientMessage; +import mage.view.DraftPickView; +import mage.view.DraftView; +import mage.view.GameClientMessage; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DraftSession { + + protected final static Logger logger = Logging.getLogger(GameWatcher.class.getName()); + + protected UUID sessionId; + protected UUID draftId; + protected boolean killed = false; + + private ScheduledFuture futureTimeout; + protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor(); + + public DraftSession(UUID sessionId, UUID draftId) { + this.sessionId = sessionId; + this.draftId = draftId; + } + + public boolean init(final DraftView draftView) { + if (!killed) { + Session session = SessionManager.getInstance().getSession(sessionId); + if (session != null) { + session.clearAck(); + session.fireCallback(new ClientCallback("draftInit", draftView)); + if (waitForAck("draftInit")) + return true; + } + } + return false; + } + + public boolean waitForAck(String message) { + Session session = SessionManager.getInstance().getSession(sessionId); + do { + //TODO: add timeout + } while (!session.getAckMessage().equals(message) && !killed); + return true; + } + + public void update(final DraftView draftView) { + if (!killed) { + Session session = SessionManager.getInstance().getSession(sessionId); + if (session != null) + session.fireCallback(new ClientCallback("draftUpdate", draftView)); + } + } + + public void inform(final String message, final DraftView draftView) { + if (!killed) { + Session session = SessionManager.getInstance().getSession(sessionId); + if (session != null) + session.fireCallback(new ClientCallback("draftInform", new DraftClientMessage(draftView, message))); + } + } + + public void gameOver(final String message) { + if (!killed) { + Session session = SessionManager.getInstance().getSession(sessionId); + if (session != null) + session.fireCallback(new ClientCallback("gameOver", message)); + } + } + + public void pickCard(final DraftPickView draftPickView) { + if (!killed) { + setupTimeout(20); + Session session = SessionManager.getInstance().getSession(sessionId); + if (session != null) + session.fireCallback(new ClientCallback("draftPick", new DraftClientMessage(draftPickView))); + } + } + + private synchronized void setupTimeout(int seconds) { + cancelTimeout(); + futureTimeout = timeoutExecutor.schedule( + new Runnable() { + @Override + public void run() { + DraftManager.getInstance().timeout(draftId, sessionId); + } + }, + seconds, TimeUnit.SECONDS + ); + } + + private synchronized void cancelTimeout() { + if (futureTimeout != null) { + futureTimeout.cancel(false); + } + } + + protected void handleRemoteException(RemoteException ex) { + logger.log(Level.SEVERE, null, ex); + DraftManager.getInstance().kill(draftId, sessionId); + } + + public void setKilled() { + killed = true; + } + +} diff --git a/Mage.Server/src/main/java/mage/server/game/GamesRoom.java b/Mage.Server/src/main/java/mage/server/game/GamesRoom.java index 39901f5103b..8d1ce7c5f1b 100644 --- a/Mage.Server/src/main/java/mage/server/game/GamesRoom.java +++ b/Mage.Server/src/main/java/mage/server/game/GamesRoom.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.UUID; import mage.cards.decks.DeckCardLists; import mage.game.GameException; +import mage.game.draft.DraftOptions; import mage.game.match.MatchOptions; import mage.view.TableView; @@ -43,7 +44,9 @@ public interface GamesRoom extends Room { public List getTables(); public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException; + public boolean joinDraftTable(UUID sessionId, UUID tableId, String name) throws GameException; public TableView createTable(UUID sessionId, MatchOptions options); + public TableView createDraftTable(UUID sessionId, DraftOptions options); public void removeTable(UUID sessionId, UUID tableId); public TableView getTable(UUID tableId); public void leaveTable(UUID sessionId, UUID tableId); diff --git a/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java b/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java index 51d29d8e26a..5fdd808bc42 100644 --- a/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java +++ b/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java @@ -37,6 +37,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; import mage.cards.decks.DeckCardLists; import mage.game.GameException; +import mage.game.draft.DraftOptions; import mage.game.match.MatchOptions; import mage.util.Logging; import mage.view.TableView; @@ -76,6 +77,22 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable { return new TableView(table); } + @Override + public boolean joinDraftTable(UUID sessionId, UUID tableId, String name) throws GameException { + if (tables.containsKey(tableId)) { + return TableManager.getInstance().joinDraft(sessionId, tableId, name); + } else { + return false; + } + } + + @Override + public TableView createDraftTable(UUID sessionId, DraftOptions options) { + Table table = TableManager.getInstance().createDraftTable(sessionId, options); + tables.put(table.getId(), table); + return new TableView(table); + } + @Override public TableView getTable(UUID tableId) { return new TableView(tables.get(tableId)); diff --git a/Mage.Server/src/main/java/mage/server/game/TableController.java b/Mage.Server/src/main/java/mage/server/game/TableController.java index 25b9875e280..610e5af271f 100644 --- a/Mage.Server/src/main/java/mage/server/game/TableController.java +++ b/Mage.Server/src/main/java/mage/server/game/TableController.java @@ -54,6 +54,8 @@ import mage.game.GameException; import mage.game.GameStates; import mage.game.match.Match; import mage.game.Seat; +import mage.game.draft.Draft; +import mage.game.draft.DraftOptions; import mage.game.events.Listener; import mage.game.events.TableEvent; import mage.game.match.MatchOptions; @@ -78,6 +80,8 @@ public class TableController { private Table table; private Match match; private MatchOptions options; + private Draft draft; + private DraftOptions draftOptions; private ConcurrentHashMap sessionPlayerMap = new ConcurrentHashMap(); public TableController(UUID sessionId, MatchOptions options) { @@ -89,6 +93,15 @@ public class TableController { init(); } + public TableController(UUID sessionId, DraftOptions options) { + this.sessionId = sessionId; + chatId = ChatManager.getInstance().createChatSession(); + this.draftOptions = options; + draft = DraftFactory.getInstance().createDraft(options.getDraftType(), options); + table = new Table(options.getDraftType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator("Limited"), options.getPlayerTypes()); + init(); + } + private void init() { table.addTableEventListener( new Listener () { @@ -107,6 +120,26 @@ public class TableController { ); } + public synchronized boolean joinDraft(UUID sessionId, String name) throws GameException { + if (table.getState() != TableState.WAITING) { + return false; + } + Seat seat = table.getNextAvailableSeat(); + if (seat == null) { + throw new GameException("No available seats."); + } + Player player = createPlayer(name, seat.getPlayerType()); + draft.addPlayer(player); + table.joinTable(player, seat); + logger.info("player joined " + player.getId()); + //only add human players to sessionPlayerMap + if (seat.getPlayer().isHuman()) { + sessionPlayerMap.put(sessionId, player.getId()); + } + + return true; + } + public synchronized boolean joinTable(UUID sessionId, String name, DeckCardLists deckList) throws GameException { if (table.getState() != TableState.WAITING) { return false; @@ -210,6 +243,18 @@ 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(); + for (Entry entry: sessionPlayerMap.entrySet()) { + sessionManager.getSession(entry.getKey()).draftStarted(draft.getId(), entry.getValue()); + } + } + } + private void sideboard() { table.sideboard(); for (MatchPlayer player: match.getPlayers()) { diff --git a/Mage.Server/src/main/java/mage/server/game/TableManager.java b/Mage.Server/src/main/java/mage/server/game/TableManager.java index 2262a96704f..8cbccfc80af 100644 --- a/Mage.Server/src/main/java/mage/server/game/TableManager.java +++ b/Mage.Server/src/main/java/mage/server/game/TableManager.java @@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; import mage.cards.decks.DeckCardLists; import mage.game.GameException; +import mage.game.draft.DraftOptions; import mage.game.match.MatchOptions; import mage.util.Logging; @@ -61,6 +62,13 @@ public class TableManager { return tableController.getTable(); } + public Table createDraftTable(UUID sessionId, DraftOptions options) { + TableController tableController = new TableController(sessionId, options); + controllers.put(tableController.getTable().getId(), tableController); + tables.put(tableController.getTable().getId(), tableController.getTable()); + return tableController.getTable(); + } + public Table getTable(UUID tableId) { return tables.get(tableId); } @@ -73,6 +81,10 @@ public class TableManager { return controllers.get(tableId).joinTable(sessionId, name, deckList); } + public boolean joinDraft(UUID sessionId, UUID tableId, String name) throws GameException { + return controllers.get(tableId).joinDraft(sessionId, name); + } + public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws GameException { return controllers.get(tableId).submitDeck(sessionId, deckList); } @@ -106,6 +118,10 @@ public class TableManager { controllers.get(tableId).startMatch(sessionId); } + public void startDraft(UUID sessionId, UUID roomId, UUID tableId) { + controllers.get(tableId).startDraft(sessionId); + } + public boolean watchTable(UUID sessionId, UUID tableId) { return controllers.get(tableId).watchTable(sessionId); } diff --git a/Mage/src/mage/Constants.java b/Mage/src/mage/Constants.java index 292fcbc3abc..3230d69bc1a 100644 --- a/Mage/src/mage/Constants.java +++ b/Mage/src/mage/Constants.java @@ -218,6 +218,7 @@ public final class Constants { public enum TableState { WAITING ("Waiting for players"), STARTING ("Waiting to start"), + DRAFTING ("Drafting"), DUELING ("Dueling"), SIDEBOARDING ("Sideboarding"), FINISHED ("Finished"); diff --git a/Mage/src/mage/game/Table.java b/Mage/src/mage/game/Table.java index 302060bece3..4ac2c9559c5 100644 --- a/Mage/src/mage/game/Table.java +++ b/Mage/src/mage/game/Table.java @@ -82,6 +82,10 @@ public class Table implements Serializable { state = TableState.DUELING; } + public void initDraft() { + state = TableState.DRAFTING; + } + public void endGame() { state = TableState.FINISHED; } diff --git a/Mage/src/mage/game/draft/Draft.java b/Mage/src/mage/game/draft/Draft.java index 71cf6577596..71c1cd91964 100644 --- a/Mage/src/mage/game/draft/Draft.java +++ b/Mage/src/mage/game/draft/Draft.java @@ -29,6 +29,7 @@ package mage.game.draft; import java.io.Serializable; +import java.util.Collection; import java.util.UUID; import mage.MageItem; import mage.game.events.Listener; @@ -43,8 +44,12 @@ import mage.players.Player; public interface Draft extends MageItem, Serializable { public void addPlayer(Player player); + public Collection getPlayers(); + public DraftPlayer getPlayer(UUID playerId); public void addPick(UUID playerId, UUID cardId); public void start(); + public void leave(UUID playerId); + public void autoPick(UUID playerId); public void addTableEventListener(Listener listener); public void fireUpdatePlayersEvent(); diff --git a/Mage/src/mage/game/draft/DraftImpl.java b/Mage/src/mage/game/draft/DraftImpl.java index cacb0d054df..a5d74aad1ea 100644 --- a/Mage/src/mage/game/draft/DraftImpl.java +++ b/Mage/src/mage/game/draft/DraftImpl.java @@ -28,6 +28,7 @@ package mage.game.draft; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -60,9 +61,9 @@ public class DraftImpl> implements Draft { protected transient TableEventSource tableEventSource = new TableEventSource(); protected transient PlayerQueryEventSource playerQueryEventSource = new PlayerQueryEventSource(); - public DraftImpl(List sets) { + public DraftImpl(DraftOptions options) { id = UUID.randomUUID(); - this.sets = sets; + this.sets = options.getSets(); } @Override @@ -77,6 +78,26 @@ public class DraftImpl> implements Draft { table.add(draftPlayer.getId()); } + @Override + public Collection getPlayers() { + return players.values(); + } + + @Override + public DraftPlayer getPlayer(UUID playerId) { + return players.get(playerId); + } + + @Override + public void leave(UUID playerId) { + //TODO: implement this + } + + @Override + public void autoPick(UUID playerId) { + //TODO: implement this + } + protected void passLeft() { UUID startId = table.get(0); UUID currentId = startId; @@ -163,6 +184,7 @@ public class DraftImpl> implements Draft { fireUpdatePlayersEvent(); } } + startTournament(); } @Override @@ -196,4 +218,8 @@ public class DraftImpl> implements Draft { } } + protected void startTournament() { + //TODO: implement this + } + } diff --git a/Mage/src/mage/game/draft/DraftOptions.java b/Mage/src/mage/game/draft/DraftOptions.java new file mode 100644 index 00000000000..d973c32c0db --- /dev/null +++ b/Mage/src/mage/game/draft/DraftOptions.java @@ -0,0 +1,83 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.draft; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import mage.cards.ExpansionSet; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DraftOptions implements Serializable { + + protected String name; + protected String draftType; + protected List sets; + protected List playerTypes = new ArrayList(); + protected TimingOption timing; + + public enum TimingOption { + REGULAR, BEGINNER, NONE + } + + public DraftOptions(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public List getSets() { + return sets; + } + + public List getPlayerTypes() { + return playerTypes; + } + + public String getDraftType() { + return draftType; + } + + public void setDraftType(String draftType) { + this.draftType = draftType; + } + + public TimingOption getTiming() { + return timing; + } + + public void setTiming(TimingOption timing) { + this.timing = timing; + } +} diff --git a/Mage/src/mage/game/tournament/Round.java b/Mage/src/mage/game/tournament/Round.java new file mode 100644 index 00000000000..d156ea46ef9 --- /dev/null +++ b/Mage/src/mage/game/tournament/Round.java @@ -0,0 +1,54 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.tournament; + +import java.util.ArrayList; +import java.util.List; +import mage.game.match.Match; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Round { + + private int roundNum; + private List matches = new ArrayList(); + + public Round(int roundNum, List players) { + this.roundNum = roundNum; + + } + + public List getMatches() { + return matches; + } + +} diff --git a/Mage/src/mage/game/tournament/Tournament.java b/Mage/src/mage/game/tournament/Tournament.java new file mode 100644 index 00000000000..403369b7867 --- /dev/null +++ b/Mage/src/mage/game/tournament/Tournament.java @@ -0,0 +1,39 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.tournament; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface Tournament { + + public void playRound(); + +} diff --git a/Mage/src/mage/game/tournament/TournamentImpl.java b/Mage/src/mage/game/tournament/TournamentImpl.java new file mode 100644 index 00000000000..7e6ab86ed1b --- /dev/null +++ b/Mage/src/mage/game/tournament/TournamentImpl.java @@ -0,0 +1,52 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.tournament; + +import java.util.ArrayList; +import java.util.List; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TournamentImpl implements Tournament { + + List rounds = new ArrayList(); + List players = new ArrayList(); + + @Override + public void playRound() { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected void createRound() { + + } +} diff --git a/Mage/src/mage/game/tournament/TournamentPlayer.java b/Mage/src/mage/game/tournament/TournamentPlayer.java new file mode 100644 index 00000000000..0d78685f5f1 --- /dev/null +++ b/Mage/src/mage/game/tournament/TournamentPlayer.java @@ -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.game.tournament; + +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TournamentPlayer { + + protected int points; + protected String name; + protected Player player; + + public TournamentPlayer(Player player) { + this.player = player; + } + + public Player getPlayer() { + return player; + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + +}