Extract DraftCommunicationChannel to be accessed directly.

This commit is contained in:
marcins78
2013-01-18 17:33:53 +00:00
parent 27828408cf
commit 54270471a9
4 changed files with 20 additions and 25 deletions

View File

@@ -8,6 +8,7 @@ import com.gempukku.lotro.async.LongPollingSystem;
import com.gempukku.lotro.async.ResponseWriter;
import com.gempukku.lotro.collection.CollectionsManager;
import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.draft.Draft;
import com.gempukku.lotro.draft.DraftChannelVisitor;
import com.gempukku.lotro.draft.DraftFinishedException;
import com.gempukku.lotro.game.*;
@@ -152,7 +153,8 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
public boolean isChanged() {
try {
return _hallServer.hasChangesInDraft(_tournamentId, _player, _channelNumber);
Draft draft = _hallServer.getDraft(_tournamentId);
return draft.getCommunicationChannel(_player.getName(), _channelNumber).hasChangesInCommunicationChannel(draft.getCardChoice(_player.getName()));
} catch (DraftFinishedException e) {
return true;
} catch (SubscriptionConflictException e) {
@@ -170,12 +172,15 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
Document doc = documentBuilder.newDocument();
Element draft = doc.createElement("draft");
Element draftElem = doc.createElement("draft");
try {
_hallServer.processChangesInDraft(_tournamentId, _player, _channelNumber, new SerializeDraftVisitor(doc, draft));
Draft draft = _hallServer.getDraft(_tournamentId);
SerializeDraftVisitor serializeDraftVisitor = new SerializeDraftVisitor(doc, draftElem);
draft.getCommunicationChannel(_player.getName(), _channelNumber).processCommunicationChannel(draft.getCardChoice(_player.getName()), serializeDraftVisitor);
serializeDraftVisitor.chosenCards(draft.getChosenCards(_player));
doc.appendChild(draft);
doc.appendChild(draftElem);
_responseWriter.writeXmlResponse(doc);
} catch (DraftFinishedException e) {

View File

@@ -7,6 +7,7 @@ import com.gempukku.lotro.db.vo.CollectionType;
import com.gempukku.lotro.game.CardCollection;
import com.gempukku.lotro.game.DefaultCardCollection;
import com.gempukku.lotro.game.MutableCardCollection;
import com.gempukku.lotro.game.Player;
import com.gempukku.lotro.packs.PacksStorage;
import com.gempukku.lotro.tournament.TournamentCallback;
@@ -101,6 +102,11 @@ public class DefaultDraft implements Draft {
return new DefaultDraftCardChoice(cardChoice, _lastPickStart + PICK_TIME);
}
@Override
public CardCollection getChosenCards(Player player) {
return _collectionsManager.getPlayerCollection(player, _collectionType.getCode());
}
@Override
public boolean isFinished() {
return _finishedDraft;

View File

@@ -2,6 +2,8 @@ package com.gempukku.lotro.draft;
import com.gempukku.lotro.SubscriptionConflictException;
import com.gempukku.lotro.SubscriptionExpiredException;
import com.gempukku.lotro.game.CardCollection;
import com.gempukku.lotro.game.Player;
import com.gempukku.lotro.tournament.TournamentCallback;
public interface Draft {
@@ -14,6 +16,7 @@ public interface Draft {
public DraftCommunicationChannel getCommunicationChannel(String playerName, int channelNumber) throws SubscriptionExpiredException, SubscriptionConflictException;
public DraftCardChoice getCardChoice(String playerName);
public CardCollection getChosenCards(Player player);
public boolean isFinished();
}

View File

@@ -362,8 +362,7 @@ public class HallServer extends AbstractServer {
}
}
public boolean hasChangesInDraft(String tournamentId, Player player, int channelNumber)
throws DraftFinishedException, SubscriptionConflictException, SubscriptionExpiredException {
public Draft getDraft(String tournamentId) throws DraftFinishedException {
_hallDataAccessLock.readLock().lock();
try {
Tournament tournament = _runningTournaments.get(tournamentId);
@@ -372,25 +371,7 @@ public class HallServer extends AbstractServer {
Draft draft = tournament.getDraft();
if (draft == null)
throw new DraftFinishedException();
return draft.getCommunicationChannel(player.getName(), channelNumber).hasChangesInCommunicationChannel(draft.getCardChoice(player.getName()));
} finally {
_hallDataAccessLock.readLock().unlock();
}
}
public void processChangesInDraft(String tournamentId, Player player, int channelNumber, DraftChannelVisitor draftChannelVisitor)
throws DraftFinishedException, SubscriptionConflictException, SubscriptionExpiredException {
_hallDataAccessLock.readLock().lock();
try {
Tournament tournament = _runningTournaments.get(tournamentId);
if (tournament == null)
throw new DraftFinishedException();
Draft draft = tournament.getDraft();
if (draft == null)
throw new DraftFinishedException();
draft.getCommunicationChannel(player.getName(), channelNumber).processCommunicationChannel(draft.getCardChoice(player.getName()), draftChannelVisitor);
CardCollection cardCollection = _collectionsManager.getPlayerCollection(player, tournament.getCollectionType().getCode());
draftChannelVisitor.chosenCards(cardCollection);
return draft;
} finally {
_hallDataAccessLock.readLock().unlock();
}