Concession and real deck size is always used to sent to client, not the adventure deck sometimes.

This commit is contained in:
marcins78@gmail.com
2011-09-20 23:57:10 +00:00
parent fb06c7e1c4
commit 130fa8544f
6 changed files with 56 additions and 10 deletions

View File

@@ -285,7 +285,7 @@ public class GameState {
for (GameStateListener listener : getPrivateGameStateListeners(card))
listener.cardRemoved(card);
if (zone == Zone.DECK || zone == Zone.HAND || zone == Zone.DISCARD || zone == Zone.DEAD)
if ((zone == Zone.DECK && card.getBlueprint().getCardType() != CardType.SITE) || zone == Zone.HAND || zone == Zone.DISCARD || zone == Zone.DEAD)
for (GameStateListener listener : getAllGameStateListeners())
listener.setZoneSize(card.getOwner(), zone, zoneCards.size());
}
@@ -306,7 +306,7 @@ public class GameState {
else if (isZonePrivate(zone))
for (GameStateListener listener : getPrivateGameStateListeners(card))
listener.cardCreated(card);
if (zone == Zone.DECK || zone == Zone.HAND || zone == Zone.DISCARD || zone == Zone.DEAD)
if ((zone == Zone.DECK && card.getBlueprint().getCardType() != CardType.SITE) || zone == Zone.HAND || zone == Zone.DISCARD || zone == Zone.DEAD)
for (GameStateListener listener : getAllGameStateListeners())
listener.setZoneSize(card.getOwner(), zone, zoneCards.size());
}

View File

@@ -105,14 +105,16 @@ public class DefaultLotroGame implements LotroGame {
@Override
public void playerLost(String playerId, String reason) {
_losers.put(playerId, reason);
if (_gameState != null)
_gameState.sendMessage(playerId + " lost due to: " + reason);
if (_losers.get(playerId) == null) {
_losers.put(playerId, reason);
if (_gameState != null)
_gameState.sendMessage(playerId + " lost due to: " + reason);
if (_losers.size() + 1 == _allPlayers.size()) {
List<String> allPlayers = new LinkedList<String>(_allPlayers);
allPlayers.removeAll(_losers.keySet());
playerWon(allPlayers.get(0), "Last remaining player in game");
if (_losers.size() + 1 == _allPlayers.size()) {
List<String> allPlayers = new LinkedList<String>(_allPlayers);
allPlayers.removeAll(_losers.keySet());
playerWon(allPlayers.get(0), "Last remaining player in game");
}
}
}

View File

@@ -140,6 +140,16 @@ public class LotroGameMediator {
}
}
public void concede(String playerId) {
_writeLock.lock();
try {
if (_lotroGame.getWinnerPlayerId() == null)
_lotroGame.playerLost(playerId, "Concession");
} finally {
_writeLock.unlock();
}
}
public void playerAnswered(String lotroGameParticipant, int decisionId, String answer) {
_writeLock.lock();
try {

View File

@@ -148,6 +148,22 @@ public class ServerResource {
return gameMediator.produceCardInfo(participantId, cardId);
}
@Path("/game/{gameId}/concede")
@POST
public void concede(
@PathParam("gameId") String gameId,
@FormParam("participantId") String participantId,
@Context HttpServletRequest request) throws ParserConfigurationException {
if (!_test)
participantId = getLoggedUser(request);
LotroGameMediator gameMediator = _lotroServer.getGameById(gameId);
if (gameMediator == null)
sendError(Response.Status.NOT_FOUND);
gameMediator.concede(participantId);
}
@Path("/game/{gameId}")
@POST
@Produces(MediaType.APPLICATION_XML)

View File

@@ -55,6 +55,17 @@ var GempLotrCommunication = Class.extend({
dataType: "xml"
});
},
concede: function() {
$.ajax({
type: "POST",
url: this.url + "/game/" + getUrlParam("gameId") + "/concede",
cache: false,
data: {
participantId: getUrlParam("participantId")},
error: this.failure,
dataType: "xml"
});
},
getDeck: function(deckType, callback) {
$.ajax({
type: "GET",

View File

@@ -184,7 +184,8 @@ var GempLotrGameUI = Class.extend({
addBottomLeftTabPane: function() {
var that = this;
this.tabPane = $("<div><ul><li><a href='#chatBox'>Chat</a></li><li><a href='#settingsBox'>Settings</a></li></ul><div id='chatBox'></div><div id='settingsBox'></div></div>").tabs();
this.tabPane = $("<div><ul><li><a href='#chatBox'>Chat</a></li><li><a href='#settingsBox'>Settings</a></li><li><a href='#gameOptionsBox'>Game options</a></li></ul>"
+ "<div id='chatBox'></div><div id='settingsBox'></div><div id='gameOptionsBox'></div></div>").tabs();
$("#main").append(this.tabPane);
@@ -217,6 +218,12 @@ var GempLotrGameUI = Class.extend({
});
this.chatBox = new ChatBoxUI("Game" + getUrlParam("gameId"), $("#chatBox"), this.communication.url);
$("#gameOptionsBox").append("<button id='concedeGame'>Concede game</button>");
$("#concedeGame").button().click(
function() {
that.communication.concede();
});
},
clickCardFunction: function(event) {