Payment for joining queue.
This commit is contained in:
@@ -173,7 +173,7 @@ public class HallServer extends AbstractServer {
|
||||
|
||||
LotroDeck lotroDeck = validateUserAndDeck(tournamentQueue.getLotroFormat(), player, deckName, tournamentQueue.getCollectionType());
|
||||
|
||||
tournamentQueue.joinPlayer(player.getName(), lotroDeck);
|
||||
tournamentQueue.joinPlayer(_collectionsManager, player, lotroDeck);
|
||||
|
||||
return true;
|
||||
} finally {
|
||||
@@ -212,7 +212,7 @@ public class HallServer extends AbstractServer {
|
||||
try {
|
||||
for (TournamentQueue tournamentQueue : _tournamentQueues.values()) {
|
||||
if (tournamentQueue.isPlayerSignedUp(player.getName()))
|
||||
tournamentQueue.leavePlayer(player.getName());
|
||||
tournamentQueue.leavePlayer(_collectionsManager, player);
|
||||
}
|
||||
} finally {
|
||||
_hallDataAccessLock.writeLock().unlock();
|
||||
@@ -479,9 +479,6 @@ public class HallServer extends AbstractServer {
|
||||
// If it's finished, remove it
|
||||
if (tournamentQueue.process(queueCallback))
|
||||
_tournamentQueues.remove(tournamentQueueKey);
|
||||
// If something was created to replace it, then add it
|
||||
if (queueCallback.getTournamentQueue() != null)
|
||||
_tournamentQueues.put(tournamentQueueKey, queueCallback.getTournamentQueue());
|
||||
}
|
||||
|
||||
for (Tournament runningTournament : new ArrayList<Tournament>(_runningTournaments)) {
|
||||
@@ -498,21 +495,10 @@ public class HallServer extends AbstractServer {
|
||||
}
|
||||
|
||||
private class HallTournamentQueueCallback implements TournamentQueueCallback {
|
||||
private TournamentQueue _tournamentQueue;
|
||||
|
||||
@Override
|
||||
public void createTournament(Tournament tournament) {
|
||||
_runningTournaments.add(tournament);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTournamentQueue(TournamentQueue tournamentQueue) {
|
||||
_tournamentQueue = tournamentQueue;
|
||||
}
|
||||
|
||||
public TournamentQueue getTournamentQueue() {
|
||||
return _tournamentQueue;
|
||||
}
|
||||
}
|
||||
|
||||
private class HallTournamentCallback implements TournamentCallback {
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class SingleEliminationTournament implements Tournament {
|
||||
private int _cost;
|
||||
private CollectionType _collectionType;
|
||||
private String _lotroFormat;
|
||||
private String _tournamentName;
|
||||
@@ -40,10 +39,9 @@ public class SingleEliminationTournament implements Tournament {
|
||||
_tournamentService = tournamentService;
|
||||
|
||||
String[] params = parameters.split(",");
|
||||
_cost = Integer.parseInt(params[0]);
|
||||
_lotroFormat = params[1];
|
||||
_collectionType = new CollectionType(params[2], params[3]);
|
||||
_tournamentName = params[4];
|
||||
_lotroFormat = params[0];
|
||||
_collectionType = new CollectionType(params[1], params[2]);
|
||||
_tournamentName = params[3];
|
||||
|
||||
_tournamentId = tournamentId;
|
||||
_playerDecks = new HashMap<String, LotroDeck>(_tournamentService.getPlayers(tournamentId));
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.gempukku.lotro.tournament;
|
||||
|
||||
import com.gempukku.lotro.collection.CollectionsManager;
|
||||
import com.gempukku.lotro.db.vo.CollectionType;
|
||||
import com.gempukku.lotro.game.LotroFormat;
|
||||
import com.gempukku.lotro.game.Player;
|
||||
import com.gempukku.lotro.logic.vo.LotroDeck;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -13,6 +15,7 @@ public class SingleEliminationTournamentQueue implements TournamentQueue {
|
||||
private LotroFormat _lotroFormat;
|
||||
private CollectionType _collectionType;
|
||||
private String _tournamentQueueName;
|
||||
private CollectionType _currencyCollection = new CollectionType("permanent", "My cards");
|
||||
|
||||
private Map<String, LotroDeck> _playerDecks = new HashMap<String, LotroDeck>();
|
||||
|
||||
@@ -54,7 +57,7 @@ public class SingleEliminationTournamentQueue implements TournamentQueue {
|
||||
String tournamentId = _tournamentIdPrefix + System.currentTimeMillis();
|
||||
String tournamentName = _tournamentQueueName + " - " + _tournamentIteration;
|
||||
|
||||
String parameters = _cost + "," + _lotroFormat.getName() + "," + _collectionType.getCode() + "," + _collectionType.getFullName() + "," + tournamentName;
|
||||
String parameters = _lotroFormat.getName() + "," + _collectionType.getCode() + "," + _collectionType.getFullName() + "," + tournamentName;
|
||||
|
||||
_tournamentService.addTournament(_cost, tournamentId, SingleEliminationTournament.class.getName(), parameters, new Date());
|
||||
|
||||
@@ -63,18 +66,18 @@ public class SingleEliminationTournamentQueue implements TournamentQueue {
|
||||
|
||||
tournamentQueueCallback.createTournament(
|
||||
new SingleEliminationTournament(_tournamentService, tournamentId, parameters));
|
||||
tournamentQueueCallback.createTournamentQueue(
|
||||
new SingleEliminationTournamentQueue(_cost, _lotroFormat, _collectionType, _tournamentIdPrefix, _tournamentIteration + 1,
|
||||
_tournamentQueueName, _playerCap, _tournamentService));
|
||||
return true;
|
||||
|
||||
_playerDecks.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void joinPlayer(String player, LotroDeck deck) {
|
||||
if (!_playerDecks.containsKey(player) && _playerDecks.size() < _playerCap)
|
||||
_playerDecks.put(player, deck);
|
||||
public synchronized void joinPlayer(CollectionsManager collectionsManager, Player player, LotroDeck deck) {
|
||||
if (!_playerDecks.containsKey(player.getName()) && _playerDecks.size() < _playerCap) {
|
||||
if (collectionsManager.removeCurrencyFromPlayerCollection(player, _currencyCollection, _cost))
|
||||
_playerDecks.put(player.getName(), deck);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,8 +86,11 @@ public class SingleEliminationTournamentQueue implements TournamentQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void leavePlayer(String player) {
|
||||
_playerDecks.remove(player);
|
||||
public synchronized void leavePlayer(CollectionsManager collectionsManager, Player player) {
|
||||
if (_playerDecks.containsKey(player.getName())) {
|
||||
collectionsManager.addCurrencyToPlayerCollection(player, _currencyCollection, _cost);
|
||||
_playerDecks.remove(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.gempukku.lotro.tournament;
|
||||
|
||||
import com.gempukku.lotro.collection.CollectionsManager;
|
||||
import com.gempukku.lotro.db.vo.CollectionType;
|
||||
import com.gempukku.lotro.game.LotroFormat;
|
||||
import com.gempukku.lotro.game.Player;
|
||||
import com.gempukku.lotro.logic.vo.LotroDeck;
|
||||
|
||||
public interface TournamentQueue {
|
||||
@@ -13,9 +15,9 @@ public interface TournamentQueue {
|
||||
|
||||
public boolean process(TournamentQueueCallback tournamentQueueCallback);
|
||||
|
||||
public void joinPlayer(String player, LotroDeck deck);
|
||||
public void joinPlayer(CollectionsManager collectionsManager, Player player, LotroDeck deck);
|
||||
|
||||
public void leavePlayer(String player);
|
||||
public void leavePlayer(CollectionsManager collectionsManager, Player player);
|
||||
|
||||
public int getPlayerCount();
|
||||
|
||||
|
||||
@@ -2,6 +2,4 @@ package com.gempukku.lotro.tournament;
|
||||
|
||||
public interface TournamentQueueCallback {
|
||||
public void createTournament(Tournament tournament);
|
||||
|
||||
public void createTournamentQueue(TournamentQueue tournamentQueue);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user