Adding hall to the game and fixing They Are Coming to discard 3 cards at once.

This commit is contained in:
marcins78@gmail.com
2011-09-16 00:39:36 +00:00
parent bb9c271a06
commit 0afacf6e57
7 changed files with 155 additions and 45 deletions

View File

@@ -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);

View File

@@ -15,7 +15,7 @@ public class HallServer extends AbstractServer {
private LotroFormat _lotroFormat = new DefaultLotroFormat(true);
private Map<String, AwaitingTable> _awaitingTables = new ConcurrentHashMap<String, AwaitingTable>();
private Map<String, String> _runningTables = new ConcurrentHashMap<String, String>();
private Map<String, String> _runningTables = Collections.synchronizedMap(new LinkedHashMap<String, String>());
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<LotroGameParticipant> 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<String, AwaitingTable> table : copy.entrySet())
visitor.visitTable(table.getKey(), "Waiting", table.getValue().getPlayerNames());
Map<String, String> runningCopy = new HashMap<String, String>(_runningTables);
Map<String, String> runningCopy = new LinkedHashMap<String, String>(_runningTables);
for (Map.Entry<String, String> 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;

View File

@@ -20,6 +20,7 @@
<script type="text/javascript" src="js/inheritance.js"></script>
<script type="text/javascript" src="js/logging.js"></script>
<script type="text/javascript" src="js/chat.js"></script>
<script type="text/javascript" src="js/hallUi.js"></script>
<script type="text/javascript" src="js/communication.js"></script>
<script type="text/javascript">
@@ -40,47 +41,17 @@
$(document).ready(
function() {
/* attach a submit handler to the form */
$("#createGameForm").submit(function(event) {
var hall = new GempLotrHallUI($("#hall"), "/gemp-lotr/server");
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var form = $(this);
/* Send the data using post and put the results in a div */
$.post("/gemp-lotr/server/createGame", form.serialize(),
function(data) {
$("#result").empty().append(data);
});
});
var comm = new GempLotrCommunication("/gemp-lotr/server",
function() {
alert("There was problem with communication with the server");
});
var chat = new ChatBoxUI("default", $("#chat"), comm);
chat.setBounds(2, 2, 800 - 4, 300 - 4);
var chat = new ChatBoxUI("default", $("#chat"), "/gemp-lotr/server");
chat.setBounds(2, 2, 780 - 4, 200 - 4);
});
</script>
</head>
<body>
<div id="chat" style="width:800px;height:300px;">
</div>
<form action="/" id="createGameForm">
<b>Create game:</b><br/>
First player name: <input type="text" name="player1"/><br/>
Second player name: <input type="text" name="player2"/><br/>
<input type="submit" value="Create game"/>
</form>
<!-- the result of the search will be rendered inside this div -->
<div id="result"></div>
<div id="hall" style="position:absolute;left:0px;top:0px;width:780px;height:300px;"></div>
<div id="chat" style="position:absolute;left:0px;top:300px;width:780px;height:200px;"></div>
</body>
</html>

View File

@@ -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 = $("<div class='chatMessages'></div>");
this.chatTalkDiv = $("<input class='chatTalk'>");

View File

@@ -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"
});
}
});

View File

@@ -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) {

View File

@@ -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 = $("<div></div>");
this.tablesDiv.css({scroll: "auto", left: "0px", top: "0px", width: width + "px", height: (height - 40) + "px"});
this.div.append(this.tablesDiv);
var buttonsDiv = $("<div></div>");
buttonsDiv.css({left: "0px", top: (height - 40) + "px", width: width + "px", height: 40 + "px", align: "right"});
var that = this;
var createTableButton = $("<button>Create table</button>");
$(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 = $("<div></div>");
tableDiv.css({ display: "inline", width: "120px", height: "120px", margin: "5px", "background-color": "#333300", color: "#ffffff"});
tableDiv.append("<i>" + status + "</i><br/>");
tableDiv.append("Players:<br/>");
for (var i = 0; i < players.length; i++)
tableDiv.append(players[i] + "<br/>");
if (players.length < 2) {
var that = this;
var but = $("<button>Join game</button>");
$(but).button().click(
function(event) {
that.comm.joinTable(id);
});
tableDiv.append(but);
}
return tableDiv;
}
});