Working on drafts.

This commit is contained in:
marcins78@gmail.com
2012-08-02 12:13:55 +00:00
parent 37a85f43a3
commit ad32025080
8 changed files with 110 additions and 23 deletions

View File

@@ -38,6 +38,7 @@ public class DefaultDraft implements Draft {
private int _playerCount;
private boolean _deckBuildingStarted;
private boolean _tournamentStarted;
private long _lastPickStart;
private long _deckBuildStart;
@@ -156,6 +157,11 @@ public class DefaultDraft implements Draft {
return false;
}
@Override
public boolean isFinished() {
return _tournamentStarted;
}
private void startTournament(DraftCallback draftCallback) {
String parameters = _format + "," + _collectionType.getCode() + "," + _collectionType.getFullName() + "," + _tournamentName;
@@ -164,7 +170,9 @@ public class DefaultDraft implements Draft {
Tournament tournament = _tournamentService.addTournament(_tournamentId, SingleEliminationTournament.class.getName(), parameters, new Date());
draftCallback.convertToTournament(tournament);
draftCallback.createTournament(tournament);
_tournamentStarted = true;
}
private boolean haveAllPlayersSubmittedDecks() {

View File

@@ -14,4 +14,6 @@ public interface Draft {
public boolean isPlayerInDraft(String player);
public DraftCardChoice getCardChoice(String playerName);
public boolean isFinished();
}

View File

@@ -3,5 +3,5 @@ package com.gempukku.lotro.draft;
import com.gempukku.lotro.tournament.Tournament;
public interface DraftCallback {
public void convertToTournament(Tournament tournament);
public void createTournament(Tournament tournament);
}

View File

@@ -0,0 +1,52 @@
package com.gempukku.lotro.draft;
import com.gempukku.lotro.AbstractServer;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class DraftServer extends AbstractServer {
private Map<Draft, DraftCallback> _draftCallbackMap = new HashMap<Draft, DraftCallback>();
private ReadWriteLock _lock = new ReentrantReadWriteLock();
public void addDraft(Draft draft, DraftCallback draftCallback) {
_lock.writeLock().lock();
try {
_draftCallbackMap.put(draft, draftCallback);
} finally {
_lock.writeLock().unlock();
}
}
public boolean isPlayerDrafting(String playerId) {
_lock.readLock().lock();
try {
for (Draft draft : _draftCallbackMap.keySet()) {
if (draft.isPlayerInDraft(playerId))
return true;
}
return false;
} finally {
_lock.readLock().unlock();
}
}
@Override
protected void cleanup() {
_lock.writeLock().lock();
try {
Map<Draft, DraftCallback> draftCallbackMap = new HashMap<Draft, DraftCallback>(_draftCallbackMap);
for (Map.Entry<Draft, DraftCallback> draftDraftCallbackEntry : draftCallbackMap.entrySet()) {
Draft draft = draftDraftCallbackEntry.getKey();
draft.advanceDraft(draftDraftCallbackEntry.getValue());
if (draft.isFinished())
_draftCallbackMap.remove(draft);
}
} finally {
_lock.writeLock().unlock();
}
}
}

View File

@@ -9,6 +9,8 @@ public interface HallInfoVisitor {
public void visitTable(String tableId, String gameId, boolean watchable, String tableStatus, String formatName, String tournamentName, Set<String> playerIds, String winner);
public void runningPlayerDraft(String draftId);
public void runningPlayerGame(String gameId);
public void visitTournamentQueue(String tournamentQueueKey, int cost, String collectionName, String formatName, String tournamentQueueName, int playerCount, boolean playerSignedUp);

View File

@@ -9,6 +9,7 @@ import com.gempukku.lotro.db.vo.CollectionType;
import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.draft.Draft;
import com.gempukku.lotro.draft.DraftCallback;
import com.gempukku.lotro.draft.DraftServer;
import com.gempukku.lotro.game.*;
import com.gempukku.lotro.game.formats.LotroFormatLibrary;
import com.gempukku.lotro.league.LeagueSerieData;
@@ -30,6 +31,7 @@ public class HallServer extends AbstractServer {
private LotroFormatLibrary _formatLibrary;
private CollectionsManager _collectionsManager;
private LotroServer _lotroServer;
private DraftServer _draftServer;
private CollectionType _allCardsCollectionType = new CollectionType("default", "All cards");
@@ -49,13 +51,13 @@ public class HallServer extends AbstractServer {
private Map<Player, Long> _lastVisitedPlayers = new HashMap<Player, Long>();
private List<Tournament> _runningTournaments = new ArrayList<Tournament>();
private List<Draft> _runningDrafts = new ArrayList<Draft>();
private Map<String, TournamentQueue> _tournamentQueues = new HashMap<String, TournamentQueue>();
private final ChatRoomMediator _hallChat;
public HallServer(LotroServer lotroServer, ChatServer chatServer, LeagueService leagueService, TournamentService tournamentService, LotroCardBlueprintLibrary library,
public HallServer(LotroServer lotroServer, DraftServer draftServer, ChatServer chatServer, LeagueService leagueService, TournamentService tournamentService, LotroCardBlueprintLibrary library,
LotroFormatLibrary formatLibrary, CollectionsManager collectionsManager, boolean test) {
_lotroServer = lotroServer;
_draftServer = draftServer;
_chatServer = chatServer;
_leagueService = leagueService;
_tournamentService = tournamentService;
@@ -450,10 +452,8 @@ public class HallServer extends AbstractServer {
return true;
}
for (Draft runningDraft : _runningDrafts) {
if (runningDraft.isPlayerInDraft(playerId))
return true;
}
if (_draftServer.isPlayerDrafting(playerId))
return true;
return false;
}
@@ -497,27 +497,20 @@ public class HallServer extends AbstractServer {
}
}
List<Draft> runningDrafts = new ArrayList<Draft>(_runningDrafts);
for (Draft runningDraft : runningDrafts) {
runningDraft.advanceDraft(new HallDraftCallback(runningDraft));
}
} finally {
_hallDataAccessLock.writeLock().unlock();
}
}
private class HallDraftCallback implements DraftCallback {
private Draft _draft;
private HallDraftCallback(Draft draft) {
_draft = draft;
}
@Override
public void convertToTournament(Tournament tournament) {
_runningTournaments.add(tournament);
_runningDrafts.remove(_draft);
public void createTournament(Tournament tournament) {
_hallDataAccessLock.writeLock().lock();
try {
_runningTournaments.add(tournament);
} finally {
_hallDataAccessLock.writeLock().unlock();
}
}
}
@@ -526,6 +519,11 @@ public class HallServer extends AbstractServer {
public void createTournament(Tournament tournament) {
_runningTournaments.add(tournament);
}
@Override
public void createDraft(Draft draft) {
_draftServer.addDraft(draft, new HallDraftCallback());
}
}
private class HallTournamentCallback implements TournamentCallback {

View File

@@ -1,5 +1,9 @@
package com.gempukku.lotro.tournament;
import com.gempukku.lotro.draft.Draft;
public interface TournamentQueueCallback {
public void createTournament(Tournament tournament);
public void createDraft(Draft draft);
}

View File

@@ -4,6 +4,7 @@ import com.gempukku.lotro.chat.ChatServer;
import com.gempukku.lotro.collection.CollectionsManager;
import com.gempukku.lotro.collection.DeliveryService;
import com.gempukku.lotro.db.*;
import com.gempukku.lotro.draft.DraftServer;
import com.gempukku.lotro.game.GameHistoryService;
import com.gempukku.lotro.game.GameRecorder;
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
@@ -35,6 +36,7 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
private Injectable<TournamentService> _tournamentServiceInjectable;
private Injectable<HallServer> _hallServerInjectable;
private Injectable<LotroServer> _lotroServerInjectable;
private Injectable<DraftServer> _draftServerInjectable;
private Injectable<CollectionsManager> _collectionsManagerInjectable;
private Injectable<DeliveryService> _deliveryServiceInjectable;
private Injectable<LotroFormatLibrary> _lotroFormatLibraryInjectable;
@@ -71,6 +73,8 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
return getChatServerInjectable();
if (type.equals(LotroServer.class))
return getLotroServerInjectable();
if (type.equals(DraftServer.class))
return getDraftServerInjectable();
if (type.equals(HallServer.class))
return getHallServerInjectable();
if (type.equals(LeagueService.class))
@@ -193,7 +197,10 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
private synchronized Injectable<HallServer> getHallServerInjectable() {
if (_hallServerInjectable == null) {
final HallServer hallServer = new HallServer(getLotroServerInjectable().getValue(), getChatServerInjectable().getValue(), getLeagueServiceInjectable().getValue(),
final HallServer hallServer = new HallServer(
getLotroServerInjectable().getValue(),
getDraftServerInjectable().getValue(),
getChatServerInjectable().getValue(), getLeagueServiceInjectable().getValue(),
getTournamentServiceInjectable().getValue(), _library,
getLotroFormatLibraryInjectable().getValue(), getCollectionsManagerInjectable().getValue(), false);
hallServer.startServer();
@@ -237,6 +244,20 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
return _lotroServerInjectable;
}
private synchronized Injectable<DraftServer> getDraftServerInjectable() {
if (_lotroServerInjectable == null) {
final DraftServer draftServer = new DraftServer();
draftServer.startServer();
_draftServerInjectable = new Injectable<DraftServer>() {
@Override
public DraftServer getValue() {
return draftServer;
}
};
}
return _draftServerInjectable;
}
private synchronized Injectable<ChatServer> getChatServerInjectable() {
if (_chatServerInjectable == null) {
final ChatServer chatServer = new ChatServer();