From 0afacf6e571ed5da61aa130f8418bef5e408d248 Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Fri, 16 Sep 2011 00:39:36 +0000 Subject: [PATCH] Adding hall to the game and fixing They Are Coming to discard 3 cards at once. --- .../lotro/cards/set1/moria/Card1_196.java | 4 +- .../com/gempukku/lotro/hall/HallServer.java | 9 +- .../gemp-lotr-web/src/main/webapp/index.html | 41 +------ .../gemp-lotr-web/src/main/webapp/js/chat.js | 6 +- .../src/main/webapp/js/communication.js | 34 ++++++ .../src/main/webapp/js/gameUi.js | 2 +- .../src/main/webapp/js/hallUi.js | 104 ++++++++++++++++++ 7 files changed, 155 insertions(+), 45 deletions(-) create mode 100644 gemp-lotr/gemp-lotr-web/src/main/webapp/js/hallUi.js diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set1/moria/Card1_196.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set1/moria/Card1_196.java index 26e509fa0..612dcb951 100644 --- a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set1/moria/Card1_196.java +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set1/moria/Card1_196.java @@ -33,9 +33,7 @@ public class Card1_196 extends AbstractPermanent { if (PlayConditions.canUseShadowCardDuringPhase(game.getGameState(), Phase.SHADOW, self, 0) && game.getGameState().getHand(playerId).size() >= 3) { DefaultCostToEffectAction action = new DefaultCostToEffectAction(self, null, "Discard 3 cards from hand to play a [MORIA] Orc from your discard pile."); - action.addCost(new ChooseAndDiscardCardsFromHandEffect(action, playerId, true)); - action.addCost(new ChooseAndDiscardCardsFromHandEffect(action, playerId, true)); - action.addCost(new ChooseAndDiscardCardsFromHandEffect(action, playerId, true)); + action.addCost(new ChooseAndDiscardCardsFromHandEffect(action, playerId, true, 3)); action.addEffect( new ChooseAndPlayCardFromDiscardEffect(playerId, Filters.and(Filters.culture(Culture.MORIA), Filters.race(Race.ORC)))); return Collections.singletonList(action); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java index e3547eaaf..96f2a1ada 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java @@ -15,7 +15,7 @@ public class HallServer extends AbstractServer { private LotroFormat _lotroFormat = new DefaultLotroFormat(true); private Map _awaitingTables = new ConcurrentHashMap(); - private Map _runningTables = new ConcurrentHashMap(); + private Map _runningTables = Collections.synchronizedMap(new LinkedHashMap()); private int _nextTableId = 1; private final int _playerInactivityPeriod = 1000 * 10; // 10 seconds @@ -67,11 +67,12 @@ public class HallServer extends AbstractServer { boolean tableFull = awaitingTable.addPlayer(new LotroGameParticipant(playerId, lotroDeck)); if (tableFull) { Set players = awaitingTable.getPlayers(); - LotroGameParticipant[] participants = new LotroGameParticipant[players.size()]; + LotroGameParticipant[] participants = players.toArray(new LotroGameParticipant[players.size()]); String gameId = _lotroServer.createNewGame(new DefaultLotroFormat(true), participants); LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId); lotroGameMediator.startGame(); _runningTables.put(tableId, gameId); + _awaitingTables.remove(tableId); } return true; } @@ -92,7 +93,7 @@ public class HallServer extends AbstractServer { for (Map.Entry table : copy.entrySet()) visitor.visitTable(table.getKey(), "Waiting", table.getValue().getPlayerNames()); - Map runningCopy = new HashMap(_runningTables); + Map runningCopy = new LinkedHashMap(_runningTables); for (Map.Entry runningGame : runningCopy.entrySet()) { LotroGameMediator lotroGameMediator = _lotroServer.getGameById(runningGame.getValue()); if (lotroGameMediator != null) @@ -134,7 +135,7 @@ public class HallServer extends AbstractServer { for (String gameId : _runningTables.values()) { LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId); - if (lotroGameMediator.getPlayersPlaying().contains(playerId)) + if (lotroGameMediator != null && !lotroGameMediator.getGameStatus().equals("Finished") && lotroGameMediator.getPlayersPlaying().contains(playerId)) return true; } return false; diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/index.html b/gemp-lotr/gemp-lotr-web/src/main/webapp/index.html index d1d7575ce..34b7a07a9 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/index.html +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/index.html @@ -20,6 +20,7 @@ + -
- -
- -
- Create game:
- First player name:
- Second player name:
- -
- -
- +
+
diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/chat.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/chat.js index 91aa92c31..0a8f14140 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/chat.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/chat.js @@ -6,10 +6,12 @@ var ChatBoxUI = Class.extend({ chatTalkDiv: null, talkBoxHeight: 25, - init: function(name, div, communication) { + init: function(name, div, url) { this.name = name; this.div = div; - this.communication = communication; + this.communication = new GempLotrCommunication(url, function() { + alert("Chat had a problem communicating with the server, reload the page to continue"); + }); this.chatMessagesDiv = $("
"); this.chatTalkDiv = $(""); diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js index d6df2a7bd..f058e809f 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js @@ -131,5 +131,39 @@ var GempLotrCommunication = Class.extend({ error: this.failure, dataType: "xml" }); + }, + getHall: function(callback) { + $.ajax({ + type: "GET", + url: this.url + "/hall", + cache: false, + data: { + participantId: getUrlParam("participantId")}, + success: callback, + error: this.failure, + dataType: "xml" + }); + }, + joinTable: function(tableId) { + $.ajax({ + type: "POST", + url: this.url + "/hall/" + tableId, + cache: false, + data: { + participantId: getUrlParam("participantId")}, + error: this.failure, + dataType: "xml" + }); + }, + createTable: function() { + $.ajax({ + type: "POST", + url: this.url + "/hall", + cache: false, + data: { + participantId: getUrlParam("participantId")}, + error: this.failure, + dataType: "xml" + }); } }); diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js index 5946d65e3..8de51f074 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js @@ -155,7 +155,7 @@ var GempLotrGameUI = Class.extend({ $.cookie("autoAccept", "" + selected, { expires: 365 }); }); - this.chatBox = new ChatBoxUI("Game" + getUrlParam("gameId"), $("#chatBox"), this.communication); + this.chatBox = new ChatBoxUI("Game" + getUrlParam("gameId"), $("#chatBox"), this.communication.url); $("body").click( function (event) { diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/hallUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/hallUi.js new file mode 100644 index 000000000..8f09feef4 --- /dev/null +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/hallUi.js @@ -0,0 +1,104 @@ +var GempLotrHallUI = Class.extend({ + div : null, + comm: null, + + tablesDiv: null, + + init: function(div, url) { + this.div = div; + this.comm = new GempLotrCommunication(url, function() { + alert("There was a problem communicating with the server, reload this window to continue."); + }); + + var width = $(div).width(); + var height = $(div).height(); + + this.tablesDiv = $("
"); + this.tablesDiv.css({scroll: "auto", left: "0px", top: "0px", width: width + "px", height: (height - 40) + "px"}); + this.div.append(this.tablesDiv); + + var buttonsDiv = $("
"); + buttonsDiv.css({left: "0px", top: (height - 40) + "px", width: width + "px", height: 40 + "px", align: "right"}); + + var that = this; + + var createTableButton = $(""); + $(createTableButton).button().click( + function() { + that.comm.createTable(); + }); + + buttonsDiv.append(createTableButton); + + this.div.append(buttonsDiv); + + this.updateHall(); + }, + + updateHall: function() { + var that = this; + + this.comm.getHall(function(xml) { + that.processHall(xml); + }); + }, + + processHall: function(xml) { + var root = xml.documentElement; + if (root.tagName == 'hall') { + this.tablesDiv.html(""); + + var tables = root.getElementsByTagName("table"); + for (var i = 0; i < tables.length; i++) { + var table = tables[i]; + var id = table.getAttribute("id"); + var status = table.getAttribute("status"); + var playersAttr = table.getAttribute("players"); + var players = new Array(); + if (playersAttr.length > 0) + players = playersAttr.split(","); + + var tableDiv = this.createTableDiv(id, status, players); + this.tablesDiv.append(tableDiv); + } + + var games = root.getElementsByTagName("game"); + if (games.length > 0) { + var waitingGameId = games[0].getAttribute("id"); + var participantId = getUrlParam("participantId"); + var participantIdAppend = ""; + if (participantId != null) + participantIdAppend = "&participantId=" + participantId; + location.href = "/gemp-lotr/game.html?gameId=" + waitingGameId + participantIdAppend; + } + + var that = this; + + setTimeout(function() { + that.updateHall(); + }, 1000); + } + }, + + createTableDiv: function(id, status, players) { + var tableDiv = $("
"); + tableDiv.css({ display: "inline", width: "120px", height: "120px", margin: "5px", "background-color": "#333300", color: "#ffffff"}); + tableDiv.append("" + status + "
"); + tableDiv.append("Players:
"); + for (var i = 0; i < players.length; i++) + tableDiv.append(players[i] + "
"); + + if (players.length < 2) { + var that = this; + + var but = $(""); + $(but).button().click( + function(event) { + that.comm.joinTable(id); + }); + tableDiv.append(but); + } + + return tableDiv; + } +}); \ No newline at end of file