From 313ff97119b06ebd086090014ca287695dbc50d0 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Mon, 17 May 2010 03:19:13 +0000 Subject: [PATCH] changes to support multiplayer --- Mage.Common/src/mage/interfaces/Server.java | 11 ++- Mage.Common/src/mage/view/GameTypeView.java | 92 +++++++++++++++++++++ Mage.Common/src/mage/view/GameView.java | 4 + Mage.Common/src/mage/view/PlayerView.java | 27 ++++-- Mage.Common/src/mage/view/SeatView.java | 2 +- 5 files changed, 123 insertions(+), 13 deletions(-) create mode 100644 Mage.Common/src/mage/view/GameTypeView.java diff --git a/Mage.Common/src/mage/interfaces/Server.java b/Mage.Common/src/mage/interfaces/Server.java index 8c308605c9..f95eb6bd97 100644 --- a/Mage.Common/src/mage/interfaces/Server.java +++ b/Mage.Common/src/mage/interfaces/Server.java @@ -30,12 +30,14 @@ package mage.interfaces; import java.rmi.Remote; import java.rmi.RemoteException; -import java.util.Collection; import java.util.List; import java.util.UUID; +import mage.Constants.MultiplayerAttackOption; +import mage.Constants.RangeOfInfluence; import mage.cards.decks.DeckCardLists; import mage.game.GameException; import mage.interfaces.callback.CallbackServer; +import mage.view.GameTypeView; import mage.view.TableView; /** @@ -48,20 +50,21 @@ public interface Server extends Remote, CallbackServer { public UUID registerClient(String userName, UUID clientId) throws RemoteException, MageException; public void deregisterClient(UUID sessionId) throws RemoteException, MageException; - public String[] getGameTypes() throws RemoteException, MageException; + public List getGameTypes() throws RemoteException, MageException; public String[] getPlayerTypes() throws RemoteException, MageException; public String[] getDeckTypes() throws RemoteException, MageException; //table methods - public TableView createTable(UUID sessionId, UUID roomId, String gameType, String deckType, List playerTypes) throws RemoteException, MageException; + public TableView createTable(UUID sessionId, UUID roomId, String gameType, String deckType, List playerTypes, MultiplayerAttackOption attackOption, RangeOfInfluence range) throws RemoteException, MageException; public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, int seatNum, String name, 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; public void leaveTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException; + public void swapSeats(UUID sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws RemoteException, MageException; public void removeTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException; public boolean isTableOwner(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException; public TableView getTable(UUID roomId, UUID tableId) throws RemoteException, MageException; - public Collection getTables(UUID roomId) throws RemoteException, MageException; + public List getTables(UUID roomId) throws RemoteException, MageException; //chat methods public void sendChatMessage(UUID chatId, String userName, String message) throws RemoteException, MageException; diff --git a/Mage.Common/src/mage/view/GameTypeView.java b/Mage.Common/src/mage/view/GameTypeView.java new file mode 100644 index 0000000000..97426e47f9 --- /dev/null +++ b/Mage.Common/src/mage/view/GameTypeView.java @@ -0,0 +1,92 @@ +/* + * 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.view; + +import java.io.Serializable; +import mage.game.GameType; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GameTypeView implements Serializable { + + private String name; + private int minPlayers; + private int maxPlayers; + private int numTeams; + private int playersPerTeam; + private boolean useRange; + private boolean useAttackOption; + + public GameTypeView(GameType gameType) { + this.name = gameType.getName(); + this.minPlayers = gameType.getMinPlayers(); + this.maxPlayers = gameType.getMaxPlayers(); + this.numTeams = gameType.getNumTeams(); + this.playersPerTeam = gameType.getPlayersPerTeam(); + this.useAttackOption = gameType.isUseAttackOption(); + this.useRange = gameType.isUseRange(); + } + + @Override + public String toString() { + return name; + } + + public String getName() { + return name; + } + + public int getMinPlayers() { + return minPlayers; + } + + public int getMaxPlayers() { + return maxPlayers; + } + + public int getNumTeams() { + return numTeams; + } + + public int getPlayersPerTeam() { + return playersPerTeam; + } + + public boolean isUseRange() { + return useRange; + } + + public boolean isUseAttackOption() { + return useAttackOption; + } + + +} diff --git a/Mage.Common/src/mage/view/GameView.java b/Mage.Common/src/mage/view/GameView.java index 9a101f64a0..ba0edfbde0 100644 --- a/Mage.Common/src/mage/view/GameView.java +++ b/Mage.Common/src/mage/view/GameView.java @@ -84,8 +84,12 @@ public class GameView implements Serializable { this.turn = game.getTurnNum(); if (game.getActivePlayerId() != null) this.activePlayerName = game.getPlayer(game.getActivePlayerId()).getName(); + else + this.activePlayerName = ""; if (game.getPriorityPlayerId() != null) this.priorityPlayerName = game.getPlayer(game.getPriorityPlayerId()).getName(); + else + this.priorityPlayerName = ""; for (CombatGroup combatGroup: game.getCombat().getGroups()) { combat.add(new CombatGroupView(combatGroup, game)); } diff --git a/Mage.Common/src/mage/view/PlayerView.java b/Mage.Common/src/mage/view/PlayerView.java index 0969098696..f06a625a48 100644 --- a/Mage.Common/src/mage/view/PlayerView.java +++ b/Mage.Common/src/mage/view/PlayerView.java @@ -48,6 +48,8 @@ public class PlayerView implements Serializable { private int life; private int libraryCount; private int handCount; + private boolean isActive; + private boolean hasLeft; private ManaPoolView manaPool; private CardsView graveyard = new CardsView(); private Map battlefield = new HashMap(); @@ -59,6 +61,8 @@ public class PlayerView implements Serializable { this.libraryCount = player.getLibrary().size(); this.handCount = player.getHand().size(); this.manaPool = new ManaPoolView(player.getManaPool()); + this.isActive = (player.getId().equals(game.getActivePlayerId())); + this.hasLeft = player.hasLeft(); for (Card card: player.getGraveyard().values()) { graveyard.add(new CardView(card)); } @@ -69,35 +73,42 @@ public class PlayerView implements Serializable { } public int getLife() { - return life; + return this.life; } public int getLibraryCount() { - return libraryCount; + return this.libraryCount; } public int getHandCount() { - return handCount; + return this.handCount; } public ManaPoolView getManaPool() { - return manaPool; + return this.manaPool; } public CardsView getGraveyard() { - return graveyard; + return this.graveyard; } public Map getBattlefield() { - return battlefield; + return this.battlefield; } public UUID getPlayerId() { - return playerId; + return this.playerId; } public String getName() { - return name; + return this.name; } + public boolean isActive() { + return this.isActive; + } + + public boolean hasLeft() { + return this.hasLeft; + } } diff --git a/Mage.Common/src/mage/view/SeatView.java b/Mage.Common/src/mage/view/SeatView.java index 3834ead47b..ce92d4574b 100644 --- a/Mage.Common/src/mage/view/SeatView.java +++ b/Mage.Common/src/mage/view/SeatView.java @@ -46,8 +46,8 @@ public class SeatView implements Serializable { if (seat.getPlayer() != null) { this.playerId = seat.getPlayer().getId(); this.playerName = seat.getPlayer().getName(); - this.playerType = seat.getPlayerType(); } + this.playerType = seat.getPlayerType(); } public UUID getPlayerId() {