Working on drafts.
This commit is contained in:
@@ -15,10 +15,10 @@ import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class DefaultDraft implements Draft {
|
||||
// 45 seconds
|
||||
public static final int PICK_TIME = 45 * 1000;
|
||||
// 20 minutes
|
||||
public static final int DECK_BUILD_TIME = 20 * 60 * 1000;
|
||||
// 35 seconds
|
||||
public static final int PICK_TIME = 35 * 1000;
|
||||
// 10 minutes
|
||||
public static final int DECK_BUILD_TIME = 10 * 60 * 1000;
|
||||
|
||||
private String _tournamentIdPrefix;
|
||||
private String _tournamentNamePrefix;
|
||||
@@ -108,16 +108,14 @@ public class DefaultDraft implements Draft {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CardCollection getCardChoice(String playerName) {
|
||||
public DraftCardChoice getCardChoice(String playerName) {
|
||||
_lock.readLock().lock();
|
||||
try {
|
||||
if (_deckBuildingStarted)
|
||||
return null;
|
||||
MutableCardCollection cardChoice = _cardChoice.get(playerName);
|
||||
if (cardChoice == null)
|
||||
cardChoice = new DefaultCardCollection();
|
||||
|
||||
return cardChoice;
|
||||
return new DefaultDraftCardChoice(cardChoice, _lastPickStart + PICK_TIME);
|
||||
} finally {
|
||||
_lock.readLock().unlock();
|
||||
}
|
||||
@@ -148,6 +146,16 @@ public class DefaultDraft implements Draft {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerInDraft(String player) {
|
||||
for (Player playerInDraft : _players) {
|
||||
if (playerInDraft.getName().equals(player))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void startTournament(DraftCallback draftCallback) {
|
||||
String parameters = _format + "," + _collectionType.getCode() + "," + _collectionType.getFullName() + "," + _tournamentName;
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.gempukku.lotro.draft;
|
||||
|
||||
import com.gempukku.lotro.game.CardCollection;
|
||||
|
||||
public class DefaultDraftCardChoice implements DraftCardChoice {
|
||||
private CardCollection _cardCollection;
|
||||
private long _pickEnd;
|
||||
|
||||
public DefaultDraftCardChoice(CardCollection cardCollection, long pickEnd) {
|
||||
_cardCollection = cardCollection;
|
||||
_pickEnd = pickEnd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeLeft() {
|
||||
return _pickEnd - System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CardCollection getCardCollection() {
|
||||
return _cardCollection;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.gempukku.lotro.draft;
|
||||
|
||||
import com.gempukku.lotro.game.CardCollection;
|
||||
import com.gempukku.lotro.game.DeckInvalidException;
|
||||
import com.gempukku.lotro.game.Player;
|
||||
import com.gempukku.lotro.logic.vo.LotroDeck;
|
||||
@@ -12,5 +11,7 @@ public interface Draft {
|
||||
|
||||
public void playerSummittedDeck(Player player, LotroDeck deck) throws DeckInvalidException;
|
||||
|
||||
public CardCollection getCardChoice(String playerName);
|
||||
public boolean isPlayerInDraft(String player);
|
||||
|
||||
public DraftCardChoice getCardChoice(String playerName);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.gempukku.lotro.draft;
|
||||
|
||||
import com.gempukku.lotro.game.CardCollection;
|
||||
|
||||
public interface DraftCardChoice {
|
||||
public long getTimeLeft();
|
||||
|
||||
public CardCollection getCardCollection();
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.gempukku.lotro.collection.CollectionsManager;
|
||||
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.game.*;
|
||||
import com.gempukku.lotro.game.formats.LotroFormatLibrary;
|
||||
import com.gempukku.lotro.league.LeagueSerieData;
|
||||
@@ -48,7 +49,7 @@ public class HallServer extends AbstractServer {
|
||||
private Map<Player, Long> _lastVisitedPlayers = new HashMap<Player, Long>();
|
||||
|
||||
private List<Tournament> _runningTournaments = new ArrayList<Tournament>();
|
||||
private List<Draft> _running = new ArrayList<Draft>();
|
||||
private List<Draft> _runningDrafts = new ArrayList<Draft>();
|
||||
private Map<String, TournamentQueue> _tournamentQueues = new HashMap<String, TournamentQueue>();
|
||||
private final ChatRoomMediator _hallChat;
|
||||
|
||||
@@ -449,6 +450,11 @@ public class HallServer extends AbstractServer {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Draft runningDraft : _runningDrafts) {
|
||||
if (runningDraft.isPlayerInDraft(playerId))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -491,11 +497,30 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
private class HallTournamentQueueCallback implements TournamentQueueCallback {
|
||||
@Override
|
||||
public void createTournament(Tournament tournament) {
|
||||
|
||||
Reference in New Issue
Block a user