League format and validating every deck against collection (even "All cards").
This commit is contained in:
@@ -3,7 +3,6 @@ package com.gempukku.lotro.logic.timing;
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
import com.gempukku.lotro.logic.GameUtils;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -11,9 +10,7 @@ public abstract class AbstractEffect implements Effect {
|
||||
private Boolean _carriedOut;
|
||||
private Boolean _successful;
|
||||
|
||||
protected abstract
|
||||
@NotNull
|
||||
FullEffectResult playEffectReturningResult(LotroGame game);
|
||||
protected abstract FullEffectResult playEffectReturningResult(LotroGame game);
|
||||
|
||||
@Override
|
||||
public final void playEffect(LotroGame game) {
|
||||
|
||||
@@ -17,17 +17,18 @@ public class LeagueSerieDAO {
|
||||
_dbAccess = dbAccess;
|
||||
}
|
||||
|
||||
public void addSerie(String leagueType, String seasonType, int start, int end, int maxMatches) {
|
||||
public void addSerie(String leagueType, String seasonType, String format, int start, int end, int maxMatches) {
|
||||
try {
|
||||
Connection conn = _dbAccess.getDataSource().getConnection();
|
||||
try {
|
||||
PreparedStatement statement = conn.prepareStatement("insert into league_season (league_type, season_type, start, end, max_matches) values (?, ?, ?, ?, ?)");
|
||||
PreparedStatement statement = conn.prepareStatement("insert into league_season (league_type, season_type, format, start, end, max_matches) values (?, ?, ?, ?, ?, ?)");
|
||||
try {
|
||||
statement.setString(1, leagueType);
|
||||
statement.setString(2, seasonType);
|
||||
statement.setInt(3, start);
|
||||
statement.setInt(4, end);
|
||||
statement.setInt(5, maxMatches);
|
||||
statement.setString(3, format);
|
||||
statement.setInt(4, start);
|
||||
statement.setInt(5, end);
|
||||
statement.setInt(6, maxMatches);
|
||||
statement.execute();
|
||||
} finally {
|
||||
statement.close();
|
||||
@@ -44,7 +45,7 @@ public class LeagueSerieDAO {
|
||||
try {
|
||||
Connection conn = _dbAccess.getDataSource().getConnection();
|
||||
try {
|
||||
PreparedStatement statement = conn.prepareStatement("select season_type, max_matches, start, end from league_season where league_type=? order by start asc");
|
||||
PreparedStatement statement = conn.prepareStatement("select season_type, format, max_matches, start, end from league_season where league_type=? order by start asc");
|
||||
try {
|
||||
statement.setString(1, league.getType());
|
||||
ResultSet rs = statement.executeQuery();
|
||||
@@ -52,10 +53,11 @@ public class LeagueSerieDAO {
|
||||
List<LeagueSerie> seasons = new LinkedList<LeagueSerie>();
|
||||
while (rs.next()) {
|
||||
String type = rs.getString(1);
|
||||
int maxMatches = rs.getInt(2);
|
||||
int start = rs.getInt(3);
|
||||
int end = rs.getInt(4);
|
||||
seasons.add(new LeagueSerie(type, maxMatches, start, end));
|
||||
String format = rs.getString(2);
|
||||
int maxMatches = rs.getInt(3);
|
||||
int start = rs.getInt(4);
|
||||
int end = rs.getInt(5);
|
||||
seasons.add(new LeagueSerie(type, format, maxMatches, start, end));
|
||||
}
|
||||
return seasons;
|
||||
} finally {
|
||||
@@ -76,7 +78,7 @@ public class LeagueSerieDAO {
|
||||
try {
|
||||
Connection conn = _dbAccess.getDataSource().getConnection();
|
||||
try {
|
||||
PreparedStatement statement = conn.prepareStatement("select season_type, max_matches, start, end from league_season where league_type=? and start<=? and end>=?");
|
||||
PreparedStatement statement = conn.prepareStatement("select season_type, format, max_matches, start, end from league_season where league_type=? and start<=? and end>=?");
|
||||
try {
|
||||
statement.setString(1, league.getType());
|
||||
statement.setInt(2, inTime);
|
||||
@@ -85,10 +87,11 @@ public class LeagueSerieDAO {
|
||||
try {
|
||||
if (rs.next()) {
|
||||
String type = rs.getString(1);
|
||||
int maxMatches = rs.getInt(2);
|
||||
int start = rs.getInt(3);
|
||||
int end = rs.getInt(4);
|
||||
return new LeagueSerie(type, maxMatches, start, end);
|
||||
String format = rs.getString(2);
|
||||
int maxMatches = rs.getInt(3);
|
||||
int start = rs.getInt(4);
|
||||
int end = rs.getInt(5);
|
||||
return new LeagueSerie(type, format, maxMatches, start, end);
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
|
||||
@@ -2,12 +2,14 @@ package com.gempukku.lotro.db.vo;
|
||||
|
||||
public class LeagueSerie {
|
||||
private String _type;
|
||||
private String _format;
|
||||
private int _maxMatches;
|
||||
private int _start;
|
||||
private int _end;
|
||||
|
||||
public LeagueSerie(String type, int maxMatches, int start, int end) {
|
||||
public LeagueSerie(String type, String format, int maxMatches, int start, int end) {
|
||||
_type = type;
|
||||
_format = format;
|
||||
_maxMatches = maxMatches;
|
||||
_start = start;
|
||||
_end = end;
|
||||
@@ -21,6 +23,10 @@ public class LeagueSerie {
|
||||
return _type;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return _format;
|
||||
}
|
||||
|
||||
public int getEnd() {
|
||||
return _end;
|
||||
}
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
package com.gempukku.lotro.hall;
|
||||
|
||||
import com.gempukku.lotro.db.vo.League;
|
||||
import com.gempukku.lotro.db.vo.LeagueSerie;
|
||||
import com.gempukku.lotro.game.LotroFormat;
|
||||
import com.gempukku.lotro.game.LotroGameParticipant;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class AwaitingTable {
|
||||
private String _formatType;
|
||||
private String _formatName;
|
||||
private String _collectionType;
|
||||
private LotroFormat _lotroFormat;
|
||||
private League _league;
|
||||
private LeagueSerie _leagueSerie;
|
||||
private Map<String, LotroGameParticipant> _players = new HashMap<String, LotroGameParticipant>();
|
||||
|
||||
private int _capacity = 2;
|
||||
|
||||
public AwaitingTable(String formatType, String formatName, LotroFormat lotroFormat, League league) {
|
||||
_formatType = formatType;
|
||||
public AwaitingTable(String formatName, String collectionType, LotroFormat lotroFormat, League league, LeagueSerie leagueSerie) {
|
||||
_formatName = formatName;
|
||||
_collectionType = collectionType;
|
||||
_lotroFormat = lotroFormat;
|
||||
_league = league;
|
||||
_leagueSerie = leagueSerie;
|
||||
}
|
||||
|
||||
public boolean addPlayer(LotroGameParticipant player) {
|
||||
@@ -44,14 +47,14 @@ public class AwaitingTable {
|
||||
return Collections.unmodifiableSet(new HashSet<LotroGameParticipant>(_players.values()));
|
||||
}
|
||||
|
||||
public String getFormatType() {
|
||||
return _formatType;
|
||||
}
|
||||
|
||||
public String getFormatName() {
|
||||
return _formatName;
|
||||
}
|
||||
|
||||
public String getCollectionType() {
|
||||
return _collectionType;
|
||||
}
|
||||
|
||||
public LotroFormat getLotroFormat() {
|
||||
return _lotroFormat;
|
||||
}
|
||||
@@ -59,4 +62,8 @@ public class AwaitingTable {
|
||||
public League getLeague() {
|
||||
return _league;
|
||||
}
|
||||
|
||||
public LeagueSerie getLeagueSerie() {
|
||||
return _leagueSerie;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.gempukku.lotro.hall;
|
||||
|
||||
import com.gempukku.lotro.AbstractServer;
|
||||
import com.gempukku.lotro.chat.ChatServer;
|
||||
import com.gempukku.lotro.db.CollectionDAO;
|
||||
import com.gempukku.lotro.db.vo.League;
|
||||
import com.gempukku.lotro.db.vo.LeagueSerie;
|
||||
import com.gempukku.lotro.game.*;
|
||||
import com.gempukku.lotro.game.formats.*;
|
||||
import com.gempukku.lotro.league.LeagueService;
|
||||
@@ -14,6 +16,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class HallServer extends AbstractServer {
|
||||
private ChatServer _chatServer;
|
||||
private LeagueService _leagueService;
|
||||
private LotroCardBlueprintLibrary _library;
|
||||
private CollectionDAO _collectionDao;
|
||||
private LotroServer _lotroServer;
|
||||
|
||||
private Map<String, String> _supportedFormatNames = new LinkedHashMap<String, String>();
|
||||
@@ -32,10 +36,12 @@ public class HallServer extends AbstractServer {
|
||||
|
||||
private String _motd;
|
||||
|
||||
public HallServer(LotroServer lotroServer, ChatServer chatServer, LeagueService leagueService, LotroCardBlueprintLibrary library, boolean test) {
|
||||
public HallServer(LotroServer lotroServer, ChatServer chatServer, LeagueService leagueService, LotroCardBlueprintLibrary library, CollectionDAO collectionDao, boolean test) {
|
||||
_lotroServer = lotroServer;
|
||||
_chatServer = chatServer;
|
||||
_leagueService = leagueService;
|
||||
_library = library;
|
||||
_collectionDao = collectionDao;
|
||||
_chatServer.createChatRoom("Game Hall", 10);
|
||||
|
||||
addFormat("fotr_block", "Fellowship block", "default", new FotRBlockFormat(library, false));
|
||||
@@ -89,6 +95,8 @@ public class HallServer extends AbstractServer {
|
||||
*/
|
||||
public synchronized void createNewTable(String type, Player player, String deckName) throws HallException {
|
||||
League league = null;
|
||||
LeagueSerie leagueSerie = null;
|
||||
String collectionType = _formatCollectionIds.get(type);
|
||||
LotroFormat format = _supportedFormats.get(type);
|
||||
String formatName = null;
|
||||
if (format != null)
|
||||
@@ -98,24 +106,28 @@ public class HallServer extends AbstractServer {
|
||||
// Maybe it's a league format?
|
||||
league = _leagueService.getLeagueByType(type);
|
||||
if (league != null) {
|
||||
format = _leagueService.getLeagueFormat(league);
|
||||
formatName = league.getName();
|
||||
leagueSerie = _leagueService.getCurrentLeagueSerie(league);
|
||||
if (leagueSerie == null)
|
||||
throw new HallException("There is no ongoing serie for that league");
|
||||
format = _supportedFormats.get(leagueSerie.getFormat());
|
||||
formatName = _supportedFormatNames.get(leagueSerie.getFormat());
|
||||
collectionType = league.getType();
|
||||
}
|
||||
}
|
||||
// It's not a normal format and also not a league one
|
||||
if (format == null)
|
||||
throw new HallException("This format is not supported: " + type);
|
||||
|
||||
LotroDeck lotroDeck = validateUserAndDeck(type, format, player, deckName);
|
||||
LotroDeck lotroDeck = validateUserAndDeck(format, player, deckName, collectionType);
|
||||
|
||||
String tableId = String.valueOf(_nextTableId++);
|
||||
AwaitingTable table = new AwaitingTable(type, formatName, format, league);
|
||||
AwaitingTable table = new AwaitingTable(formatName, collectionType, format, league, leagueSerie);
|
||||
_awaitingTables.put(tableId, table);
|
||||
|
||||
joinTableInternal(tableId, player.getName(), table, deckName, lotroDeck);
|
||||
}
|
||||
|
||||
private LotroDeck validateUserAndDeck(String type, LotroFormat format, Player player, String deckName) throws HallException {
|
||||
private LotroDeck validateUserAndDeck(LotroFormat format, Player player, String deckName, String collectionType) throws HallException {
|
||||
if (isPlayerBusy(player.getName()))
|
||||
throw new HallException("You can't play more than one game at a time or wait at more than one table");
|
||||
|
||||
@@ -129,8 +141,20 @@ public class HallServer extends AbstractServer {
|
||||
throw new HallException("Your registered deck is not valid for this format: " + e.getMessage());
|
||||
}
|
||||
|
||||
// CardCollection collection = _collectionDao.getCollectionForPlayer(player, _formatCollectionIds.get(type));
|
||||
// TODO check that player has cards in collection
|
||||
// Now check if player owns all the cards
|
||||
CardCollection collection = _collectionDao.getCollectionForPlayer(player, collectionType);
|
||||
|
||||
Map<String, Integer> deckCardCounts = CollectionUtils.getTotalCardCountForDeck(lotroDeck);
|
||||
final Map<String, Integer> collectionCardCounts = collection.getAll();
|
||||
|
||||
for (Map.Entry<String, Integer> cardCount : deckCardCounts.entrySet()) {
|
||||
final Integer collectionCount = collectionCardCounts.get(cardCount.getKey());
|
||||
if (collectionCount == null || collectionCount < cardCount.getValue()) {
|
||||
String cardName = _library.getLotroCardBlueprint(cardCount.getKey()).getName();
|
||||
int owned = (collectionCount == null) ? 0 : collectionCount;
|
||||
throw new HallException("You don't have the required cards in collection: " + cardName + " required " + cardCount.getValue() + ", owned " + owned);
|
||||
}
|
||||
}
|
||||
|
||||
return lotroDeck;
|
||||
}
|
||||
@@ -143,7 +167,7 @@ public class HallServer extends AbstractServer {
|
||||
if (awaitingTable == null)
|
||||
throw new HallException("Table is already taken or was removed");
|
||||
|
||||
LotroDeck lotroDeck = validateUserAndDeck(awaitingTable.getFormatType(), awaitingTable.getLotroFormat(), player, deckName);
|
||||
LotroDeck lotroDeck = validateUserAndDeck(awaitingTable.getLotroFormat(), player, deckName, awaitingTable.getCollectionType());
|
||||
|
||||
joinTableInternal(tableId, player.getName(), awaitingTable, deckName, lotroDeck);
|
||||
|
||||
@@ -163,7 +187,7 @@ public class HallServer extends AbstractServer {
|
||||
String gameId = _lotroServer.createNewGame(awaitingTable.getLotroFormat(), awaitingTable.getFormatName(), participants, league != null);
|
||||
LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId);
|
||||
if (league != null)
|
||||
_leagueService.leagueGameStarting(league, lotroGameMediator);
|
||||
_leagueService.leagueGameStarting(league, awaitingTable.getLeagueSerie(), lotroGameMediator);
|
||||
lotroGameMediator.startGame();
|
||||
_runningTables.put(tableId, gameId);
|
||||
_runningTableFormatNames.put(tableId, awaitingTable.getFormatName());
|
||||
|
||||
@@ -56,23 +56,22 @@ public class LeagueService {
|
||||
return null;
|
||||
}
|
||||
|
||||
public LotroFormat getLeagueFormat(League league) {
|
||||
return new LeagueFormat(_library, this, league, true);
|
||||
}
|
||||
|
||||
public void leagueGameStarting(final League league, LotroGameMediator gameMediator) {
|
||||
public LeagueSerie getCurrentLeagueSerie(League league) {
|
||||
final int startDay = getCurrentDate();
|
||||
|
||||
final LeagueSerie season = _leagueSeasonDao.getSerieForLeague(league, startDay);
|
||||
if (season != null && isRanked(league, season, gameMediator)) {
|
||||
return _leagueSeasonDao.getSerieForLeague(league, startDay);
|
||||
}
|
||||
|
||||
public void leagueGameStarting(final League league, final LeagueSerie serie, LotroGameMediator gameMediator) {
|
||||
if (isRanked(league, serie, gameMediator)) {
|
||||
gameMediator.addGameResultListener(
|
||||
new GameResultListener() {
|
||||
@Override
|
||||
public void gameFinished(String winnerPlayerId, String winReason, Map<String, String> loserPlayerIdsWithReasons) {
|
||||
String loser = loserPlayerIdsWithReasons.keySet().iterator().next();
|
||||
_leagueMatchDao.addPlayedMatch(league, season, winnerPlayerId, loser);
|
||||
_leaguePointsDao.addPoints(league, season, winnerPlayerId, 2);
|
||||
_leaguePointsDao.addPoints(league, season, loser, 1);
|
||||
_leagueMatchDao.addPlayedMatch(league, serie, winnerPlayerId, loser);
|
||||
_leaguePointsDao.addPoints(league, serie, winnerPlayerId, 2);
|
||||
_leaguePointsDao.addPoints(league, serie, loser, 1);
|
||||
}
|
||||
});
|
||||
gameMediator.sendMessageToPlayers("This is a ranked game in " + league.getName());
|
||||
|
||||
@@ -86,13 +86,14 @@ public class AdminResource extends AbstractResource {
|
||||
public String addLeagueSeason(
|
||||
@FormParam("leagueType") String leagueType,
|
||||
@FormParam("type") String type,
|
||||
@FormParam("format") String format,
|
||||
@FormParam("start") int start,
|
||||
@FormParam("end") int end,
|
||||
@FormParam("maxMatches") int maxMatches,
|
||||
@Context HttpServletRequest request) throws Exception {
|
||||
validateAdmin(request);
|
||||
|
||||
_leagueSeasonDao.addSerie(leagueType, type, start, end, maxMatches);
|
||||
_leagueSeasonDao.addSerie(leagueType, type, format, start, end, maxMatches);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ 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(), _library, false);
|
||||
final HallServer hallServer = new HallServer(getLotroServerInjectable().getValue(), getChatServerInjectable().getValue(), getLeagueServiceInjectable().getValue(), _library, _collectionDao, false);
|
||||
hallServer.startServer();
|
||||
_hallServerInjectable = new Injectable<HallServer>() {
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<form method="POST" action="server/admin/addLeague">
|
||||
Name: <input type="text" name="name"><br/>
|
||||
Type: <input type="text" name="type"><br/>
|
||||
Format: <input type="text" name="format"><br/>
|
||||
Start: <input type="text" name="start"><br/>
|
||||
End: <input type="text" name="end"><br/>
|
||||
Packs: <textarea rows="5" cols="20" name="packCollection"></textarea><br/>
|
||||
|
||||
Reference in New Issue
Block a user