* Added possibility to allow other players to see hand cards of player.

This commit is contained in:
LevelX2 2014-11-24 23:03:21 +01:00
parent d0e1107a3e
commit 7e145d2cfd
33 changed files with 1093 additions and 190 deletions

View file

@ -120,7 +120,7 @@ public interface MageServer {
void quitMatch(UUID gameId, String sessionId) throws MageException;
GameView getGameView(UUID gameId, String sessionId, UUID playerId) throws MageException;
// priority, undo, concede, mana pool
void sendPlayerAction(PlayerAction playerAction, UUID gameId, String sessionId) throws MageException;
void sendPlayerAction(PlayerAction playerAction, UUID gameId, String sessionId, Object data) throws MageException;
//tournament methods
boolean startTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;

View file

@ -54,6 +54,7 @@ public class Connection {
private int avatarId;
private boolean showAbilityPickerForced;
private boolean allowRequestShowHandCards;
private UserSkipPrioritySteps userSkipPrioritySteps;
private static final String serialization = "?serializationtype=jboss";
@ -231,6 +232,13 @@ public class Connection {
this.showAbilityPickerForced = showAbilityPickerForced;
}
public boolean allowRequestShowHandCards() {
return allowRequestShowHandCards;
}
public void setAllowRequestShowHandCards(boolean allowRequestShowHandCards) {
this.allowRequestShowHandCards = allowRequestShowHandCards;
}
public UserSkipPrioritySteps getUserSkipPrioritySteps() {
return userSkipPrioritySteps;
}

View file

@ -273,6 +273,7 @@ public class SessionImpl implements Session {
if (connection.getPassword() == null) {
UserDataView userDataView = new UserDataView(connection.getAvatarId(),
connection.isShowAbilityPickerForced(),
connection.allowRequestShowHandCards(),
connection.getUserSkipPrioritySteps());
// for backward compatibility. don't remove twice call - first one does nothing but for version checking
registerResult = server.registerClient(connection.getUsername(), sessionId, client.getVersion());
@ -1151,10 +1152,10 @@ public class SessionImpl implements Session {
}
@Override
public boolean sendPlayerAction(PlayerAction passPriorityAction, UUID gameId) {
public boolean sendPlayerAction(PlayerAction passPriorityAction, UUID gameId, Object data) {
try {
if (isConnected()) {
server.sendPlayerAction(passPriorityAction, gameId, sessionId);
server.sendPlayerAction(passPriorityAction, gameId, sessionId, data);
return true;
}
} catch (MageException ex) {
@ -1355,10 +1356,10 @@ public class SessionImpl implements Session {
}
@Override
public boolean updatePreferencesForServer(int avatarId, boolean showAbilityPickerForced, UserSkipPrioritySteps userSkipPrioritySteps) {
public boolean updatePreferencesForServer(int avatarId, boolean showAbilityPickerForced, boolean allowRequestShowHandCards, UserSkipPrioritySteps userSkipPrioritySteps) {
try {
if (isConnected()) {
UserDataView userDataView = new UserDataView(avatarId, showAbilityPickerForced, userSkipPrioritySteps);
UserDataView userDataView = new UserDataView(avatarId, showAbilityPickerForced, allowRequestShowHandCards, userSkipPrioritySteps);
server.setUserData(connection.getUsername(), sessionId, userDataView);
}
return true;

View file

@ -36,5 +36,5 @@ public interface ClientData {
String getUserName();
boolean updatePreferencesForServer(int avatarId, boolean showAbilityPickerForced, UserSkipPrioritySteps userSkipPrioritySteps);
boolean updatePreferencesForServer(int avatarId, boolean showAbilityPickerForced, boolean allowRequestShowHandCards, UserSkipPrioritySteps userSkipPrioritySteps);
}

View file

@ -80,6 +80,6 @@ public interface GamePlay {
* @param gameId
* @return
*/
boolean sendPlayerAction(PlayerAction passPriorityAction, UUID gameId);
boolean sendPlayerAction(PlayerAction passPriorityAction, UUID gameId, Object Data);
}

View file

@ -66,7 +66,7 @@ public class GameEndView implements Serializable {
int winner = 0;
Player you = null;
for (Player player: state.getPlayers().values()) {
PlayerView playerView = new PlayerView(player, state, game, playerId);
PlayerView playerView = new PlayerView(player, state, game, playerId, null);
if (playerView.getPlayerId().equals(playerId)) {
clientPlayer = playerView;
you = player;

View file

@ -65,6 +65,7 @@ public class GameView implements Serializable {
private CardsView hand;
private Set<UUID> canPlayInHand;
private Map<String, SimpleCardsView> opponentHands;
private Map<String, SimpleCardsView> watchedHands;
private final CardsView stack = new CardsView();
private final List<ExileView> exiles = new ArrayList<>();
private final List<RevealedView> revealed = new ArrayList<>();
@ -80,11 +81,11 @@ public class GameView implements Serializable {
private final boolean isPlayer;
public GameView(GameState state, Game game, UUID createdForPlayerId) {
public GameView(GameState state, Game game, UUID createdForPlayerId, UUID watcherUserId) {
this.isPlayer = createdForPlayerId != null;
this.priorityTime = game.getPriorityTime();
for (Player player: state.getPlayers().values()) {
players.add(new PlayerView(player, state, game, createdForPlayerId));
players.add(new PlayerView(player, state, game, createdForPlayerId, watcherUserId));
}
for (StackObject stackObject: state.getStack()) {
if (stackObject instanceof StackAbility) {
@ -222,6 +223,14 @@ public class GameView implements Serializable {
this.opponentHands = opponentHands;
}
public Map<String, SimpleCardsView> getWatchedHands() {
return watchedHands;
}
public void setWatchedHands(Map<String, SimpleCardsView> watchedHands) {
this.watchedHands = watchedHands;
}
public TurnPhase getPhase() {
return phase;
}

View file

@ -28,6 +28,12 @@
package mage.view;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.cards.Card;
import mage.counters.CounterType;
import mage.game.ExileZone;
@ -39,9 +45,6 @@ import mage.game.command.Emblem;
import mage.game.permanent.Permanent;
import mage.players.Player;
import java.io.Serializable;
import java.util.*;
/**
*
* @author BetaSteward_at_googlemail.com
@ -74,7 +77,7 @@ public class PlayerView implements Serializable {
private final boolean passedUntilStackResolved; // F8
private final boolean passedAllTurns; // F9
public PlayerView(Player player, GameState state, Game game, UUID createdForPlayerId) {
public PlayerView(Player player, GameState state, Game game, UUID createdForPlayerId, UUID watcherUserId) {
this.playerId = player.getId();
this.name = player.getName();
this.life = player.getLife();
@ -106,7 +109,7 @@ public class PlayerView implements Serializable {
if (player.getUserData() != null) {
this.userDataView = new UserDataView(player.getUserData());
} else {
this.userDataView = new UserDataView(0, false, null);
this.userDataView = new UserDataView(0, false, false, null);
}
for (CommandObject commandObject : game.getState().getCommand()) {

View file

@ -1,8 +1,7 @@
package mage.view;
import mage.players.net.UserData;
import java.io.Serializable;
import mage.players.net.UserData;
import mage.players.net.UserSkipPrioritySteps;
/**
@ -15,11 +14,13 @@ public class UserDataView implements Serializable {
protected int avatarId;
protected int userGroup;
protected boolean showAbilityPickerForced;
protected boolean allowRequestShowHandCards;
protected UserSkipPrioritySteps userSkipPrioritySteps;
public UserDataView(int avatarId, boolean showAbilityPickerForced, UserSkipPrioritySteps userSkipPrioritySteps) {
public UserDataView(int avatarId, boolean showAbilityPickerForced, boolean allowRequestShowHandCards, UserSkipPrioritySteps userSkipPrioritySteps) {
this.avatarId = avatarId;
this.showAbilityPickerForced = showAbilityPickerForced;
this.allowRequestShowHandCards = allowRequestShowHandCards;
this.userSkipPrioritySteps = userSkipPrioritySteps;
}
@ -36,6 +37,10 @@ public class UserDataView implements Serializable {
return showAbilityPickerForced;
}
public boolean allowRequestShowHandCards() {
return allowRequestShowHandCards;
}
public UserSkipPrioritySteps getUserSkipPrioritySteps() {
return userSkipPrioritySteps;
}

View file

@ -0,0 +1,152 @@
/*
* 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 java.util.UUID;
import mage.constants.PlayerAction;
/**
*
* @author LevelX2
*/
public class UserRequestMessage implements Serializable {
private static final long serialVersionUID = 1L;
private final String titel;
private final String message;
private final PlayerAction requestAction;
private UUID relatedUserId;
private String relatedUserName;
private UUID matchId;
private UUID gameId;
private String button1Text;
private PlayerAction button1Action;
private String button2Text;
private PlayerAction button2Action;
private String button3Text;
private PlayerAction button3Action;
public UserRequestMessage(String titel, String message, PlayerAction requestAction) {
this.titel = titel;
this.message = message;
this.requestAction = requestAction;
this.button1Action = null;
this.button2Action = null;
this.button3Action = null;
}
public void setMatchId(UUID matchId) {
this.matchId = matchId;
}
public void setGameId(UUID gameId) {
this.gameId = gameId;
}
public void setRelatedUser(UUID userId, String name) {
this.relatedUserId = userId;
this.relatedUserName = name;
}
public void setButton1(String text, PlayerAction buttonAction) {
this.button1Text = text;
this.button1Action = buttonAction;
}
public void setButton2(String text, PlayerAction buttonAction) {
this.button2Text = text;
this.button2Action = buttonAction;
}
public void setButton3(String text, PlayerAction buttonAction) {
this.button3Text = text;
this.button3Action = buttonAction;
}
public String getTitel() {
return titel;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getMessage() {
return message;
}
public PlayerAction getRequestAction() {
return requestAction;
}
public UUID getRelatedUserId() {
return relatedUserId;
}
public String getRelatedUserName() {
return relatedUserName;
}
public UUID getMatchId() {
return matchId;
}
public UUID getGameId() {
return gameId;
}
public String getButton1Text() {
return button1Text;
}
public PlayerAction getButton1Action() {
return button1Action;
}
public String getButton2Text() {
return button2Text;
}
public PlayerAction getButton2Action() {
return button2Action;
}
public String getButton3Text() {
return button3Text;
}
public PlayerAction getButton3Action() {
return button3Action;
}
}