Continued work on Leagues.

This commit is contained in:
marcins78@gmail.com
2011-09-23 16:31:44 +00:00
parent 447b4ce472
commit 1e8adf17c4
4 changed files with 84 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ package com.gempukku.lotro.hall;
import com.gempukku.lotro.AbstractServer;
import com.gempukku.lotro.chat.ChatServer;
import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.game.DeckInvalidException;
import com.gempukku.lotro.game.LotroGameMediator;
import com.gempukku.lotro.game.LotroGameParticipant;
@@ -49,6 +50,10 @@ public class HallServer extends AbstractServer {
return new TreeMap<String, LotroFormat>(_supportedFormats);
}
public Set<League> getRunningLeagues() {
return _leagueService.getAllLeagues();
}
/**
* @param playerId
* @return If table created, otherwise <code>false</code> (if the user already is sitting at a table or playing).
@@ -101,15 +106,18 @@ public class HallServer extends AbstractServer {
private void joinTableInternal(String tableId, String playerId, AwaitingTable awaitingTable, LotroDeck lotroDeck) {
boolean tableFull = awaitingTable.addPlayer(new LotroGameParticipant(playerId, lotroDeck));
if (tableFull) {
Set<LotroGameParticipant> players = awaitingTable.getPlayers();
LotroGameParticipant[] participants = players.toArray(new LotroGameParticipant[players.size()]);
String gameId = _lotroServer.createNewGame(awaitingTable.getLotroFormat(), participants);
LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId);
lotroGameMediator.startGame();
_runningTables.put(tableId, gameId);
_awaitingTables.remove(tableId);
}
if (tableFull)
createGame(tableId, awaitingTable);
}
private void createGame(String tableId, AwaitingTable awaitingTable) {
Set<LotroGameParticipant> players = awaitingTable.getPlayers();
LotroGameParticipant[] participants = players.toArray(new LotroGameParticipant[players.size()]);
String gameId = _lotroServer.createNewGame(awaitingTable.getLotroFormat(), participants);
LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId);
lotroGameMediator.startGame();
_runningTables.put(tableId, gameId);
_awaitingTables.remove(tableId);
}
public synchronized void leaveAwaitingTables(String playerId) {

View File

@@ -0,0 +1,18 @@
package com.gempukku.lotro.league;
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
import com.gempukku.lotro.game.formats.DefaultLotroFormat;
public class LeagueFormat extends DefaultLotroFormat {
private boolean _orderedSites;
public LeagueFormat(LotroCardBlueprintLibrary library, boolean orderedSites) {
super(library, true, 60, Integer.MAX_VALUE);
_orderedSites = orderedSites;
}
@Override
public boolean isOrderedSites() {
return _orderedSites;
}
}

View File

@@ -1,13 +1,50 @@
package com.gempukku.lotro.league;
import com.gempukku.lotro.db.CollectionDAO;
import com.gempukku.lotro.db.DbAccess;
import com.gempukku.lotro.db.LeagueDAO;
import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.db.vo.Player;
import com.gempukku.lotro.game.CardCollection;
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
import com.gempukku.lotro.game.formats.LotroFormat;
import java.util.Set;
public class LeagueService {
private LeagueDAO _leagueDao;
private CollectionDAO _collectionDao;
private LotroCardBlueprintLibrary _library;
public LeagueService(DbAccess dbAccess, LotroCardBlueprintLibrary library) {
public LeagueService(DbAccess dbAccess, CollectionDAO collectionDao, LotroCardBlueprintLibrary library) {
_collectionDao = collectionDao;
_library = library;
_leagueDao = new LeagueDAO(dbAccess, library);
}
public Set<League> getAllLeagues() {
return _leagueDao.getAllLeagues();
}
public CardCollection getLeagueCollection(Player player, String type) {
final CardCollection collectionForPlayer = _collectionDao.getCollectionForPlayer(player, type);
if (collectionForPlayer == null) {
final League leagueByType = getLeagueByType(type);
if (leagueByType != null)
return leagueByType.getBaseCollection();
}
return collectionForPlayer;
}
private League getLeagueByType(String type) {
for (League league : getAllLeagues()) {
if (league.getType().equals(type))
return league;
}
return null;
}
public LotroFormat getLeagueFormat(String type) {
return new LeagueFormat(_library, true);
}
}

View File

@@ -4,9 +4,11 @@ import com.gempukku.lotro.chat.ChatMessage;
import com.gempukku.lotro.chat.ChatRoomMediator;
import com.gempukku.lotro.chat.ChatServer;
import com.gempukku.lotro.common.Side;
import com.gempukku.lotro.db.CollectionDAO;
import com.gempukku.lotro.db.DbAccess;
import com.gempukku.lotro.db.DeckDAO;
import com.gempukku.lotro.db.PlayerDAO;
import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.db.vo.Player;
import com.gempukku.lotro.game.*;
import com.gempukku.lotro.game.formats.LotroFormat;
@@ -53,13 +55,15 @@ public class ServerResource {
DbAccess dbAccess = new DbAccess();
LotroCardBlueprintLibrary library = new LotroCardBlueprintLibrary();
CollectionDAO collectionDao = new CollectionDAO(dbAccess, library);
_chatServer = new ChatServer();
_chatServer.startServer();
_lotroServer = new LotroServer(dbAccess, library, _chatServer);
_lotroServer.startServer();
_leagueService = new LeagueService(dbAccess, library);
_leagueService = new LeagueService(dbAccess, collectionDao, library);
_hallServer = new HallServer(_lotroServer, _chatServer, _leagueService, _test);
_hallServer.startServer();
@@ -480,6 +484,12 @@ public class ServerResource {
formatElem.appendChild(doc.createTextNode(format));
hall.appendChild(formatElem);
}
for (League league : _hallServer.getRunningLeagues()) {
Element formatElem = doc.createElement("format");
formatElem.appendChild(doc.createTextNode(league.getName()));
hall.appendChild(formatElem);
}
doc.appendChild(hall);