Rewarding winning games in league.
This commit is contained in:
@@ -20,11 +20,13 @@ public class CollectionsManager {
|
|||||||
private PlayerDAO _playerDAO;
|
private PlayerDAO _playerDAO;
|
||||||
private CollectionDAO _collectionDAO;
|
private CollectionDAO _collectionDAO;
|
||||||
private LeagueService _leagueService;
|
private LeagueService _leagueService;
|
||||||
|
private DeliveryService _deliveryService;
|
||||||
|
|
||||||
public CollectionsManager(PlayerDAO playerDAO, CollectionDAO collectionDAO, LeagueService leagueService) {
|
public CollectionsManager(PlayerDAO playerDAO, CollectionDAO collectionDAO, LeagueService leagueService, DeliveryService deliveryService) {
|
||||||
_playerDAO = playerDAO;
|
_playerDAO = playerDAO;
|
||||||
_collectionDAO = collectionDAO;
|
_collectionDAO = collectionDAO;
|
||||||
_leagueService = leagueService;
|
_leagueService = leagueService;
|
||||||
|
_deliveryService = deliveryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearDBCache() {
|
public void clearDBCache() {
|
||||||
@@ -71,8 +73,10 @@ public class CollectionsManager {
|
|||||||
return null;
|
return null;
|
||||||
MutableCardCollection mutableCardCollection = new DefaultCardCollection(playerCollection);
|
MutableCardCollection mutableCardCollection = new DefaultCardCollection(playerCollection);
|
||||||
final CardCollection packContents = mutableCardCollection.openPack(packId, selection, packsStorage);
|
final CardCollection packContents = mutableCardCollection.openPack(packId, selection, packsStorage);
|
||||||
if (packContents != null)
|
if (packContents != null) {
|
||||||
_collectionDAO.setCollectionForPlayer(player.getId(), collectionType, mutableCardCollection);
|
_collectionDAO.setCollectionForPlayer(player.getId(), collectionType, mutableCardCollection);
|
||||||
|
addPackage(player, collectionType, packContents);
|
||||||
|
}
|
||||||
return packContents;
|
return packContents;
|
||||||
} finally {
|
} finally {
|
||||||
_readWriteLock.writeLock().unlock();
|
_readWriteLock.writeLock().unlock();
|
||||||
@@ -85,16 +89,24 @@ public class CollectionsManager {
|
|||||||
final CardCollection playerCollection = getPlayerCollection(player, collectionType);
|
final CardCollection playerCollection = getPlayerCollection(player, collectionType);
|
||||||
if (playerCollection != null) {
|
if (playerCollection != null) {
|
||||||
MutableCardCollection mutableCardCollection = new DefaultCardCollection(playerCollection);
|
MutableCardCollection mutableCardCollection = new DefaultCardCollection(playerCollection);
|
||||||
for (Map.Entry<String, Integer> item : items.entrySet())
|
MutableCardCollection addedCards = new DefaultCardCollection();
|
||||||
|
for (Map.Entry<String, Integer> item : items.entrySet()) {
|
||||||
mutableCardCollection.addItem(item.getKey(), item.getValue());
|
mutableCardCollection.addItem(item.getKey(), item.getValue());
|
||||||
|
addedCards.addItem(item.getKey(), item.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
_collectionDAO.setCollectionForPlayer(player.getId(), collectionType, mutableCardCollection);
|
_collectionDAO.setCollectionForPlayer(player.getId(), collectionType, mutableCardCollection);
|
||||||
|
addPackage(player, collectionType, addedCards);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
_readWriteLock.writeLock().unlock();
|
_readWriteLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addItemsToPlayerCollection(String player, String collectionType, Map<String, Integer> items) {
|
||||||
|
addItemsToPlayerCollection(_playerDAO.getPlayer(player), collectionType, items);
|
||||||
|
}
|
||||||
|
|
||||||
public void moveCollectionToCollection(Player player, String collectionFrom, String collectionTo) {
|
public void moveCollectionToCollection(Player player, String collectionFrom, String collectionTo) {
|
||||||
_readWriteLock.writeLock().lock();
|
_readWriteLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -107,6 +119,7 @@ public class CollectionsManager {
|
|||||||
mutableCardCollection.addItem(item.getKey(), item.getValue());
|
mutableCardCollection.addItem(item.getKey(), item.getValue());
|
||||||
|
|
||||||
_collectionDAO.setCollectionForPlayer(player.getId(), collectionTo, mutableCardCollection);
|
_collectionDAO.setCollectionForPlayer(player.getId(), collectionTo, mutableCardCollection);
|
||||||
|
addPackage(player, collectionTo, oldCollection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -132,12 +145,18 @@ public class CollectionsManager {
|
|||||||
if (!removeItems(playerTwoCollection, itemsOfPlayerTwo))
|
if (!removeItems(playerTwoCollection, itemsOfPlayerTwo))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
addItems(playerOneCollection, itemsOfPlayerTwo);
|
MutableCardCollection addedCardsPlayerOne = new DefaultCardCollection();
|
||||||
addItems(playerTwoCollection, itemsOfPlayerOne);
|
MutableCardCollection addedCardsPlayerTwo = new DefaultCardCollection();
|
||||||
|
|
||||||
|
addItems(playerOneCollection, addedCardsPlayerOne, itemsOfPlayerTwo);
|
||||||
|
addItems(playerTwoCollection, addedCardsPlayerTwo, itemsOfPlayerOne);
|
||||||
|
|
||||||
_collectionDAO.setCollectionForPlayer(playerOne.getId(), collectionType, playerOneCollection);
|
_collectionDAO.setCollectionForPlayer(playerOne.getId(), collectionType, playerOneCollection);
|
||||||
_collectionDAO.setCollectionForPlayer(playerTwo.getId(), collectionType, playerTwoCollection);
|
_collectionDAO.setCollectionForPlayer(playerTwo.getId(), collectionType, playerTwoCollection);
|
||||||
|
|
||||||
|
addPackage(playerOne, collectionType, addedCardsPlayerOne);
|
||||||
|
addPackage(playerTwo, collectionType, addedCardsPlayerTwo);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
_readWriteLock.writeLock().unlock();
|
_readWriteLock.writeLock().unlock();
|
||||||
@@ -151,8 +170,25 @@ public class CollectionsManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addItems(MutableCardCollection collection, Map<String, Integer> items) {
|
private void addItems(MutableCardCollection collection, MutableCardCollection addedCards, Map<String, Integer> items) {
|
||||||
for (Map.Entry<String, Integer> item : items.entrySet())
|
for (Map.Entry<String, Integer> item : items.entrySet()) {
|
||||||
collection.addItem(item.getKey(), item.getValue());
|
collection.addItem(item.getKey(), item.getValue());
|
||||||
|
addedCards.addItem(item.getKey(), item.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addPackage(Player player, String collectionType, CardCollection cards) {
|
||||||
|
_deliveryService.addPackage(player, getPackageNameByCollectionType(collectionType), cards);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPackageNameByCollectionType(String collectionType) {
|
||||||
|
String packageName;
|
||||||
|
if (collectionType.equals("permanent"))
|
||||||
|
packageName = "My cards";
|
||||||
|
else {
|
||||||
|
League league = _leagueService.getLeagueByType(collectionType);
|
||||||
|
packageName = league.getName();
|
||||||
|
}
|
||||||
|
return packageName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.gempukku.lotro.db.vo.LeagueSerie;
|
|||||||
import com.gempukku.lotro.game.*;
|
import com.gempukku.lotro.game.*;
|
||||||
import com.gempukku.lotro.game.formats.*;
|
import com.gempukku.lotro.game.formats.*;
|
||||||
import com.gempukku.lotro.league.LeagueService;
|
import com.gempukku.lotro.league.LeagueService;
|
||||||
|
import com.gempukku.lotro.logic.timing.GameResultListener;
|
||||||
import com.gempukku.lotro.logic.vo.LotroDeck;
|
import com.gempukku.lotro.logic.vo.LotroDeck;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -298,11 +299,20 @@ public class HallServer extends AbstractServer {
|
|||||||
private void createGame(String tableId, AwaitingTable awaitingTable) {
|
private void createGame(String tableId, AwaitingTable awaitingTable) {
|
||||||
Set<LotroGameParticipant> players = awaitingTable.getPlayers();
|
Set<LotroGameParticipant> players = awaitingTable.getPlayers();
|
||||||
LotroGameParticipant[] participants = players.toArray(new LotroGameParticipant[players.size()]);
|
LotroGameParticipant[] participants = players.toArray(new LotroGameParticipant[players.size()]);
|
||||||
League league = awaitingTable.getLeague();
|
final League league = awaitingTable.getLeague();
|
||||||
|
final LeagueSerie leagueSerie = awaitingTable.getLeagueSerie();
|
||||||
String gameId = _lotroServer.createNewGame(awaitingTable.getLotroFormat(), participants, league != null);
|
String gameId = _lotroServer.createNewGame(awaitingTable.getLotroFormat(), participants, league != null);
|
||||||
LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId);
|
LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId);
|
||||||
if (league != null)
|
if (league != null) {
|
||||||
_leagueService.leagueGameStarting(league, awaitingTable.getLeagueSerie(), lotroGameMediator);
|
lotroGameMediator.addGameResultListener(
|
||||||
|
new GameResultListener() {
|
||||||
|
@Override
|
||||||
|
public void gameFinished(String winnerPlayerId, String winReason, Map<String, String> loserPlayerIdsWithReasons) {
|
||||||
|
final CardCollection winnerPrize = _leagueService.reportLeagueGameResult(league, leagueSerie, winnerPlayerId, loserPlayerIdsWithReasons.keySet().iterator().next());
|
||||||
|
_collectionsManager.addItemsToPlayerCollection(winnerPlayerId, "permanent", winnerPrize.getAll());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
lotroGameMediator.startGame();
|
lotroGameMediator.startGame();
|
||||||
_runningTables.put(tableId, new RunningTable(gameId, awaitingTable.getLotroFormat().getName(), getTournamentName(awaitingTable)));
|
_runningTables.put(tableId, new RunningTable(gameId, awaitingTable.getLotroFormat().getName(), getTournamentName(awaitingTable)));
|
||||||
_awaitingTables.remove(tableId);
|
_awaitingTables.remove(tableId);
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ import com.gempukku.lotro.db.LeagueSerieDAO;
|
|||||||
import com.gempukku.lotro.db.vo.League;
|
import com.gempukku.lotro.db.vo.League;
|
||||||
import com.gempukku.lotro.db.vo.LeagueMatch;
|
import com.gempukku.lotro.db.vo.LeagueMatch;
|
||||||
import com.gempukku.lotro.db.vo.LeagueSerie;
|
import com.gempukku.lotro.db.vo.LeagueSerie;
|
||||||
|
import com.gempukku.lotro.game.CardCollection;
|
||||||
|
import com.gempukku.lotro.game.DefaultCardCollection;
|
||||||
import com.gempukku.lotro.game.LotroGameMediator;
|
import com.gempukku.lotro.game.LotroGameMediator;
|
||||||
import com.gempukku.lotro.logic.timing.GameResultListener;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -28,11 +29,57 @@ public class LeagueService {
|
|||||||
private Map<League, List<LeagueStanding>> _leagueStandings = new ConcurrentHashMap<League, List<LeagueStanding>>();
|
private Map<League, List<LeagueStanding>> _leagueStandings = new ConcurrentHashMap<League, List<LeagueStanding>>();
|
||||||
private Map<LeagueSerie, List<LeagueStanding>> _leagueSerieStandings = new ConcurrentHashMap<LeagueSerie, List<LeagueStanding>>();
|
private Map<LeagueSerie, List<LeagueStanding>> _leagueSerieStandings = new ConcurrentHashMap<LeagueSerie, List<LeagueStanding>>();
|
||||||
|
|
||||||
|
private Map<String, List<String>> _winnerPromos = new HashMap<String, List<String>>();
|
||||||
|
|
||||||
public LeagueService(LeagueDAO leagueDao, LeagueSerieDAO leagueSeasonDao, LeaguePointsDAO leaguePointsDao, LeagueMatchDAO leagueMatchDao) {
|
public LeagueService(LeagueDAO leagueDao, LeagueSerieDAO leagueSeasonDao, LeaguePointsDAO leaguePointsDao, LeagueMatchDAO leagueMatchDao) {
|
||||||
_leagueDao = leagueDao;
|
_leagueDao = leagueDao;
|
||||||
_leagueSeasonDao = leagueSeasonDao;
|
_leagueSeasonDao = leagueSeasonDao;
|
||||||
_leaguePointsDao = leaguePointsDao;
|
_leaguePointsDao = leaguePointsDao;
|
||||||
_leagueMatchDao = leagueMatchDao;
|
_leagueMatchDao = leagueMatchDao;
|
||||||
|
|
||||||
|
List<String> fotrPromos = new ArrayList<String>();
|
||||||
|
fotrPromos.add("0_1");
|
||||||
|
fotrPromos.add("0_2");
|
||||||
|
fotrPromos.add("0_3");
|
||||||
|
fotrPromos.add("0_4");
|
||||||
|
fotrPromos.add("0_5");
|
||||||
|
fotrPromos.add("0_6");
|
||||||
|
fotrPromos.add("0_7");
|
||||||
|
fotrPromos.add("0_8");
|
||||||
|
fotrPromos.add("0_9");
|
||||||
|
fotrPromos.add("0_10");
|
||||||
|
fotrPromos.add("0_11");
|
||||||
|
fotrPromos.add("0_12");
|
||||||
|
fotrPromos.add("0_13");
|
||||||
|
fotrPromos.add("0_14");
|
||||||
|
fotrPromos.add("0_15");
|
||||||
|
fotrPromos.add("0_34");
|
||||||
|
fotrPromos.add("0_36");
|
||||||
|
fotrPromos.add("0_37");
|
||||||
|
fotrPromos.add("0_41");
|
||||||
|
fotrPromos.add("0_42");
|
||||||
|
fotrPromos.add("0_43");
|
||||||
|
_winnerPromos.put("fotr_block", fotrPromos);
|
||||||
|
|
||||||
|
List<String> tttPromos = new ArrayList<String>();
|
||||||
|
tttPromos.add("0_16");
|
||||||
|
tttPromos.add("0_17");
|
||||||
|
tttPromos.add("0_18");
|
||||||
|
tttPromos.add("0_19");
|
||||||
|
tttPromos.add("0_21");
|
||||||
|
tttPromos.add("0_22");
|
||||||
|
tttPromos.add("0_30");
|
||||||
|
tttPromos.add("0_32");
|
||||||
|
tttPromos.add("0_33");
|
||||||
|
tttPromos.add("0_35");
|
||||||
|
tttPromos.add("0_38");
|
||||||
|
tttPromos.add("0_39");
|
||||||
|
tttPromos.add("0_40");
|
||||||
|
tttPromos.add("0_44");
|
||||||
|
tttPromos.add("0_45");
|
||||||
|
tttPromos.add("0_46");
|
||||||
|
tttPromos.add("0_47");
|
||||||
|
_winnerPromos.put("ttt_block", tttPromos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<League> getActiveLeagues() {
|
public Set<League> getActiveLeagues() {
|
||||||
@@ -53,24 +100,33 @@ public class LeagueService {
|
|||||||
return _leagueSeasonDao.getSerieForLeague(league, startDay);
|
return _leagueSeasonDao.getSerieForLeague(league, startDay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leagueGameStarting(final League league, final LeagueSerie serie, LotroGameMediator gameMediator) {
|
public CardCollection reportLeagueGameResult(League league, LeagueSerie serie, String winner, String loser) {
|
||||||
if (isRanked(league, serie, gameMediator)) {
|
_leagueMatchDao.addPlayedMatch(league, serie, winner, loser);
|
||||||
gameMediator.addGameResultListener(
|
_leaguePointsDao.addPoints(league, serie, winner, 2);
|
||||||
new GameResultListener() {
|
_leaguePointsDao.addPoints(league, serie, loser, 1);
|
||||||
@Override
|
_leagueStandings.remove(league);
|
||||||
public void gameFinished(String winnerPlayerId, String winReason, Map<String, String> loserPlayerIdsWithReasons) {
|
_leagueSerieStandings.remove(serie);
|
||||||
String loser = loserPlayerIdsWithReasons.keySet().iterator().next();
|
|
||||||
_leagueMatchDao.addPlayedMatch(league, serie, winnerPlayerId, loser);
|
int count = 0;
|
||||||
_leaguePointsDao.addPoints(league, serie, winnerPlayerId, 2);
|
Collection<LeagueMatch> playerMatchesPlayedOn = _leagueMatchDao.getPlayerMatchesPlayedOn(league, serie, winner);
|
||||||
_leaguePointsDao.addPoints(league, serie, loser, 1);
|
for (LeagueMatch leagueMatch : playerMatchesPlayedOn) {
|
||||||
_leagueStandings.remove(league);
|
if (leagueMatch.getWinner().equals(winner))
|
||||||
_leagueSerieStandings.remove(serie);
|
count++;
|
||||||
}
|
|
||||||
});
|
|
||||||
gameMediator.sendMessageToPlayers("This is a ranked game in " + league.getName());
|
|
||||||
} else {
|
|
||||||
gameMediator.sendMessageToPlayers("This is NOT a ranked game in " + league.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefaultCardCollection winnerPrize = new DefaultCardCollection();
|
||||||
|
winnerPrize.addItem("(S)Booster Choice", 1);
|
||||||
|
if (count == 2 || count == 4) {
|
||||||
|
winnerPrize.addItem(getRandomPromoForBlock(serie.getFormat()), 1);
|
||||||
|
} else if (count == 6 || count == 8 || count == 10) {
|
||||||
|
winnerPrize.addItem(getRandomPromoForBlock(serie.getFormat()) + "*", 1);
|
||||||
|
}
|
||||||
|
return winnerPrize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRandomPromoForBlock(String format) {
|
||||||
|
final List<String> promos = _winnerPromos.get(format);
|
||||||
|
return promos.get(new Random().nextInt(promos.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LeagueStanding> getLeagueStandings(League league) {
|
public List<LeagueStanding> getLeagueStandings(League league) {
|
||||||
|
|||||||
@@ -141,7 +141,6 @@ public class AdminResource extends AbstractResource {
|
|||||||
for (Map.Entry<Player, CardCollection> playerCollection : playerCollections.entrySet()) {
|
for (Map.Entry<Player, CardCollection> playerCollection : playerCollections.entrySet()) {
|
||||||
Player player = playerCollection.getKey();
|
Player player = playerCollection.getKey();
|
||||||
_collectionsManager.addItemsToPlayerCollection(player, leagueType, productItems);
|
_collectionsManager.addItemsToPlayerCollection(player, leagueType, productItems);
|
||||||
_deliveryService.addPackage(player, league.getName(), items);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "OK";
|
return "OK";
|
||||||
@@ -156,8 +155,6 @@ public class AdminResource extends AbstractResource {
|
|||||||
@Context HttpServletRequest request) throws Exception {
|
@Context HttpServletRequest request) throws Exception {
|
||||||
validateAdmin(request);
|
validateAdmin(request);
|
||||||
|
|
||||||
String packageName = getPackageNameByCollectionType(collectionType);
|
|
||||||
|
|
||||||
DefaultCardCollection items = new DefaultCardCollection();
|
DefaultCardCollection items = new DefaultCardCollection();
|
||||||
|
|
||||||
Map<String, Integer> productItems = getProductItems(product);
|
Map<String, Integer> productItems = getProductItems(product);
|
||||||
@@ -170,7 +167,6 @@ public class AdminResource extends AbstractResource {
|
|||||||
Player player = _playerDao.getPlayer(playerName);
|
Player player = _playerDao.getPlayer(playerName);
|
||||||
|
|
||||||
_collectionsManager.addItemsToPlayerCollection(player, collectionType, productItems);
|
_collectionsManager.addItemsToPlayerCollection(player, collectionType, productItems);
|
||||||
_deliveryService.addPackage(player, packageName, items);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "OK";
|
return "OK";
|
||||||
@@ -184,35 +180,16 @@ public class AdminResource extends AbstractResource {
|
|||||||
@Context HttpServletRequest request) throws Exception {
|
@Context HttpServletRequest request) throws Exception {
|
||||||
validateAdmin(request);
|
validateAdmin(request);
|
||||||
|
|
||||||
String toCollectionName = getPackageNameByCollectionType(collectionTo);
|
|
||||||
|
|
||||||
Map<Player, CardCollection> playerCollections = _collectionsManager.getPlayersCollection(collectionFrom);
|
Map<Player, CardCollection> playerCollections = _collectionsManager.getPlayersCollection(collectionFrom);
|
||||||
for (Map.Entry<Player, CardCollection> playerCollection : playerCollections.entrySet()) {
|
for (Map.Entry<Player, CardCollection> playerCollection : playerCollections.entrySet()) {
|
||||||
Player player = playerCollection.getKey();
|
Player player = playerCollection.getKey();
|
||||||
|
|
||||||
CardCollection oldCollection = playerCollection.getValue();
|
|
||||||
|
|
||||||
_collectionsManager.moveCollectionToCollection(player, collectionFrom, collectionTo);
|
_collectionsManager.moveCollectionToCollection(player, collectionFrom, collectionTo);
|
||||||
|
|
||||||
_deliveryService.addPackage(player, toCollectionName, oldCollection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "OK";
|
return "OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPackageNameByCollectionType(String collectionType) {
|
|
||||||
String packageName;
|
|
||||||
if (collectionType.equals("permanent"))
|
|
||||||
packageName = "My cards";
|
|
||||||
else {
|
|
||||||
League league = getLeagueByType(collectionType);
|
|
||||||
if (league == null)
|
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
|
||||||
packageName = league.getName();
|
|
||||||
}
|
|
||||||
return packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getItems(String values) {
|
private List<String> getItems(String values) {
|
||||||
List<String> result = new LinkedList<String>();
|
List<String> result = new LinkedList<String>();
|
||||||
for (String pack : values.split("\n")) {
|
for (String pack : values.split("\n")) {
|
||||||
|
|||||||
@@ -174,8 +174,6 @@ public class CollectionResource extends AbstractResource {
|
|||||||
if (packContents == null)
|
if (packContents == null)
|
||||||
sendError(Response.Status.NOT_FOUND);
|
sendError(Response.Status.NOT_FOUND);
|
||||||
|
|
||||||
_deliveryService.addPackage(resourceOwner, getPackageNameByCollectionType(collectionType), packContents);
|
|
||||||
|
|
||||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||||
|
|
||||||
@@ -206,24 +204,4 @@ public class CollectionResource extends AbstractResource {
|
|||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPackageNameByCollectionType(String collectionType) {
|
|
||||||
String packageName;
|
|
||||||
if (collectionType.equals("permanent"))
|
|
||||||
packageName = "My cards";
|
|
||||||
else {
|
|
||||||
League league = getLeagueByType(collectionType);
|
|
||||||
if (league == null)
|
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
|
||||||
packageName = league.getName();
|
|
||||||
}
|
|
||||||
return packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private League getLeagueByType(String leagueType) {
|
|
||||||
for (League league : _leagueDao.getActiveLeagues())
|
|
||||||
if (league.getType().equals(leagueType))
|
|
||||||
return league;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.gempukku.lotro.server;
|
|
||||||
|
|
||||||
import com.gempukku.lotro.collection.DeliveryService;
|
|
||||||
import com.sun.jersey.core.spi.component.ComponentContext;
|
|
||||||
import com.sun.jersey.core.spi.component.ComponentScope;
|
|
||||||
import com.sun.jersey.spi.inject.Injectable;
|
|
||||||
import com.sun.jersey.spi.inject.InjectableProvider;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.Context;
|
|
||||||
import javax.ws.rs.ext.Provider;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
|
|
||||||
@Provider
|
|
||||||
public class DeliveryServiceProvider implements Injectable<DeliveryService>, InjectableProvider<Context, Type> {
|
|
||||||
private DeliveryService _deliveryService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Injectable getInjectable(ComponentContext ic, Context context, Type type) {
|
|
||||||
if (type.equals(DeliveryService.class))
|
|
||||||
return this;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ComponentScope getScope() {
|
|
||||||
return ComponentScope.Singleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DeliveryService createDeliveryService() {
|
|
||||||
return new DeliveryService();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized DeliveryService getValue() {
|
|
||||||
if (_deliveryService == null)
|
|
||||||
_deliveryService = createDeliveryService();
|
|
||||||
return _deliveryService;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package com.gempukku.lotro.server;
|
|||||||
|
|
||||||
import com.gempukku.lotro.chat.ChatServer;
|
import com.gempukku.lotro.chat.ChatServer;
|
||||||
import com.gempukku.lotro.collection.CollectionsManager;
|
import com.gempukku.lotro.collection.CollectionsManager;
|
||||||
|
import com.gempukku.lotro.collection.DeliveryService;
|
||||||
import com.gempukku.lotro.db.*;
|
import com.gempukku.lotro.db.*;
|
||||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||||
import com.gempukku.lotro.game.LotroServer;
|
import com.gempukku.lotro.game.LotroServer;
|
||||||
@@ -25,6 +26,7 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
|
|||||||
private Injectable<LotroServer> _lotroServerInjectable;
|
private Injectable<LotroServer> _lotroServerInjectable;
|
||||||
private Injectable<TradeServer> _tradeServerInjectable;
|
private Injectable<TradeServer> _tradeServerInjectable;
|
||||||
private Injectable<CollectionsManager> _collectionsManagerInjectable;
|
private Injectable<CollectionsManager> _collectionsManagerInjectable;
|
||||||
|
private Injectable<DeliveryService> _deliveryServiceInjectable;
|
||||||
|
|
||||||
@Context
|
@Context
|
||||||
private PlayerDAO _playerDao;
|
private PlayerDAO _playerDao;
|
||||||
@@ -59,6 +61,8 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
|
|||||||
return getCollectionsManagerInjectable();
|
return getCollectionsManagerInjectable();
|
||||||
if (type.equals(TradeServer.class))
|
if (type.equals(TradeServer.class))
|
||||||
return getTradeServerInjectable();
|
return getTradeServerInjectable();
|
||||||
|
if (type.equals(DeliveryService.class))
|
||||||
|
return getDeliveryServiceInjectable();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +79,19 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
|
|||||||
return _leagueServerInjectable;
|
return _leagueServerInjectable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized Injectable<DeliveryService> getDeliveryServiceInjectable() {
|
||||||
|
if (_leagueServerInjectable == null) {
|
||||||
|
final DeliveryService deliveryService = new DeliveryService();
|
||||||
|
_deliveryServiceInjectable = new Injectable<DeliveryService>() {
|
||||||
|
@Override
|
||||||
|
public DeliveryService getValue() {
|
||||||
|
return deliveryService;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return _deliveryServiceInjectable;
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized Injectable<HallServer> getHallServerInjectable() {
|
private synchronized Injectable<HallServer> getHallServerInjectable() {
|
||||||
if (_hallServerInjectable == null) {
|
if (_hallServerInjectable == null) {
|
||||||
final HallServer hallServer = new HallServer(getLotroServerInjectable().getValue(), getChatServerInjectable().getValue(), getLeagueServiceInjectable().getValue(), _library, getCollectionsManagerInjectable().getValue(), false);
|
final HallServer hallServer = new HallServer(getLotroServerInjectable().getValue(), getChatServerInjectable().getValue(), getLeagueServiceInjectable().getValue(), _library, getCollectionsManagerInjectable().getValue(), false);
|
||||||
@@ -133,7 +150,7 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
|
|||||||
|
|
||||||
private synchronized Injectable<CollectionsManager> getCollectionsManagerInjectable() {
|
private synchronized Injectable<CollectionsManager> getCollectionsManagerInjectable() {
|
||||||
if (_collectionsManagerInjectable == null) {
|
if (_collectionsManagerInjectable == null) {
|
||||||
final CollectionsManager collectionsManager = new CollectionsManager(_playerDao, _collectionDao, getLeagueServiceInjectable().getValue());
|
final CollectionsManager collectionsManager = new CollectionsManager(_playerDao, _collectionDao, getLeagueServiceInjectable().getValue(), getDeliveryServiceInjectable().getValue());
|
||||||
_collectionsManagerInjectable = new Injectable<CollectionsManager>() {
|
_collectionsManagerInjectable = new Injectable<CollectionsManager>() {
|
||||||
@Override
|
@Override
|
||||||
public CollectionsManager getValue() {
|
public CollectionsManager getValue() {
|
||||||
|
|||||||
Reference in New Issue
Block a user