diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java index 45225200e..4c57225e5 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java @@ -115,6 +115,9 @@ public class HallServer extends AbstractServer { leagueSerie = _leagueService.getCurrentLeagueSerie(league); if (leagueSerie == null) throw new HallException("There is no ongoing serie for that league"); + + if (!_leagueService.canPlayRankedGame(league, leagueSerie, player.getName())) + throw new HallException("You have already played max games in league"); format = _supportedFormats.get(leagueSerie.getFormat()); collectionType = league.getCollectionType(); } @@ -305,7 +308,15 @@ public class HallServer extends AbstractServer { _awaitingTables.remove(tableId); } - private void joinTableInternal(String tableId, String playerId, AwaitingTable awaitingTable, String deckName, LotroDeck lotroDeck) { + private void joinTableInternal(String tableId, String playerId, AwaitingTable awaitingTable, String deckName, LotroDeck lotroDeck) throws HallException { + League league = awaitingTable.getLeague(); + if (league != null) { + LeagueSerie leagueSerie = awaitingTable.getLeagueSerie(); + if (!_leagueService.canPlayRankedGame(league, leagueSerie, playerId)) + throw new HallException("You have already played max games in league"); + if (!_leagueService.canPlayRankedGame(league, leagueSerie, awaitingTable.getPlayerNames().iterator().next(), playerId)) + throw new HallException("You have already played ranked league game against this player in that series"); + } boolean tableFull = awaitingTable.addPlayer(new LotroGameParticipant(playerId, deckName, lotroDeck)); if (tableFull) createGame(tableId, awaitingTable); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java index 62eea1372..11f18d5e6 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java @@ -61,6 +61,23 @@ public class LeagueService { } } + public boolean canPlayRankedGame(League league, LeagueSerie season, String player) { + int maxMatches = season.getMaxMatches(); + Collection playedInSeason = _leagueMatchDao.getPlayerMatchesPlayedOn(league, season, player); + if (playedInSeason.size() >= maxMatches) + return false; + return true; + } + + public boolean canPlayRankedGame(League league, LeagueSerie season, String playerOne, String playerTwo) { + Collection playedInSeason = _leagueMatchDao.getPlayerMatchesPlayedOn(league, season, playerOne); + for (LeagueMatch leagueMatch : playedInSeason) { + if (playerTwo.equals(leagueMatch.getWinner()) && playerTwo.equals(leagueMatch.getLoser())) + return false; + } + return true; + } + private int getCurrentDate() { Calendar date = new GregorianCalendar(TimeZone.getTimeZone("GMT")); return date.get(Calendar.YEAR) * 10000 + (date.get(Calendar.MONTH) + 1) * 100 + date.get(Calendar.DAY_OF_MONTH); diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/includes/changeLog.html b/gemp-lotr/gemp-lotr-web/src/main/webapp/includes/changeLog.html index 1d6d8b24d..02cc345a7 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/includes/changeLog.html +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/includes/changeLog.html @@ -1,4 +1,8 @@
+23 Jan. 2012
+- You can't create a League table, if you played maximum number of games in league serie. You can't join a league table
+if you played maximum games in league serie, or if you played against that opponent in this league series already.
+
 22 Jan. 2012
 - Added resistance to card detail information window.
 - If an effect makes you exert a character X times, and you can't find a character able to be exerted X times, you can