From 37d837ea11cfaba6525c1ca8d3a5db2a5b65c6c5 Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Mon, 5 Mar 2012 16:30:26 +0000 Subject: [PATCH] - "Relentless Warg" should no longer cause the game to freeze. --- .../lotro/cards/set17/orc/Card17_089.java | 18 ++- gemp-lotr/gemp-lotr-server/pom.xml | 6 + .../java/com/gempukku/lotro/db/LeagueDAO.java | 33 +++- .../com/gempukku/lotro/db/LeagueMatchDAO.java | 14 +- .../gempukku/lotro/db/LeaguePointsDAO.java | 10 +- .../com/gempukku/lotro/db/LeagueSerieDAO.java | 152 ----------------- .../gempukku/lotro/db/vo/CollectionType.java | 26 ++- .../java/com/gempukku/lotro/db/vo/League.java | 38 +++-- .../com/gempukku/lotro/db/vo/LeagueSerie.java | 82 ---------- .../gempukku/lotro/hall/AwaitingTable.java | 8 +- .../com/gempukku/lotro/hall/HallServer.java | 12 +- .../com/gempukku/lotro/league/LeagueData.java | 15 ++ .../lotro/league/LeagueSerieData.java | 24 +++ .../gempukku/lotro/league/LeagueService.java | 88 +++++----- .../lotro/league/SealedLeagueData.java | 98 +++++++++++ ...guePrizes.java => SealedLeaguePrizes.java} | 16 +- .../lotro/league/SealedLeagueProduct.java | 81 ++++++++++ .../lotro/league/SealedLeagueSerieData.java | 69 ++++++++ .../lotro/league/SealedLeagueDataTest.java | 153 ++++++++++++++++++ ...sTest.java => SealedLeaguePrizesTest.java} | 10 +- .../src/main/webapp/includes/changeLog.html | 1 + 21 files changed, 617 insertions(+), 337 deletions(-) delete mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueSerieDAO.java delete mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueSerie.java create mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueData.java create mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueSerieData.java create mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueData.java rename gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/{LeaguePrizes.java => SealedLeaguePrizes.java} (87%) create mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueProduct.java create mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueSerieData.java create mode 100644 gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java rename gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/{LeaguePrizesTest.java => SealedLeaguePrizesTest.java} (53%) diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/orc/Card17_089.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/orc/Card17_089.java index 05f92c2bb..4047249c6 100644 --- a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/orc/Card17_089.java +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/orc/Card17_089.java @@ -43,7 +43,7 @@ public class Card17_089 extends AbstractAttachable { } @Override - public List getAlwaysOnModifiers(LotroGame game, PhysicalCard self) { + public List getAlwaysOnModifiers(LotroGame game, final PhysicalCard self) { List modifiers = new LinkedList(); modifiers.add( new StrengthModifier(self, Filters.hasAttached(self), 2)); @@ -52,9 +52,21 @@ public class Card17_089 extends AbstractAttachable { modifiers.add( new KeywordModifier(self, Filters.hasAttached(self), Keyword.FIERCE)); modifiers.add( - new StrengthModifier(self, Filters.and(Filters.hasAttached(self), Filters.inSkirmishAgainst(CardType.COMPANION, (Race) self.getWhileInZoneData())), 3)); + new StrengthModifier(self, Filters.and(Filters.hasAttached(self), Filters.inSkirmishAgainst(CardType.COMPANION, + new Filter() { + @Override + public boolean accepts(GameState gameState, ModifiersQuerying modifiersQuerying, PhysicalCard physicalCard) { + return self.getWhileInZoneData() != null && physicalCard.getBlueprint().getRace() == self.getWhileInZoneData(); + } + })), 3)); modifiers.add( - new KeywordModifier(self, Filters.and(Filters.hasAttached(self), Filters.inSkirmishAgainst(CardType.COMPANION, (Race) self.getWhileInZoneData())), Keyword.DAMAGE, 1)); + new KeywordModifier(self, Filters.and(Filters.hasAttached(self), Filters.inSkirmishAgainst(CardType.COMPANION, + new Filter() { + @Override + public boolean accepts(GameState gameState, ModifiersQuerying modifiersQuerying, PhysicalCard physicalCard) { + return self.getWhileInZoneData() != null && physicalCard.getBlueprint().getRace() == self.getWhileInZoneData(); + } + })), Keyword.DAMAGE, 1)); return modifiers; } diff --git a/gemp-lotr/gemp-lotr-server/pom.xml b/gemp-lotr/gemp-lotr-server/pom.xml index 1812f1982..26359df30 100644 --- a/gemp-lotr/gemp-lotr-server/pom.xml +++ b/gemp-lotr/gemp-lotr-server/pom.xml @@ -42,5 +42,11 @@ 4.9 test + + org.mockito + mockito-all + 1.9.0 + test + \ No newline at end of file diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java index 84435e180..640758584 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java @@ -49,7 +49,7 @@ public class LeagueDAO { public Set loadActiveLeagues(int currentTime) throws SQLException, IOException { Connection conn = _dbAccess.getDataSource().getConnection(); try { - PreparedStatement statement = conn.prepareStatement("select id, name, type, start, end from league where start<=? and end>=? order by start desc"); + PreparedStatement statement = conn.prepareStatement("select id, name, type, class, parameters, start, end, status from league where start<=? and end>=? order by start desc"); try { statement.setInt(1, currentTime); statement.setInt(2, currentTime); @@ -60,9 +60,12 @@ public class LeagueDAO { int id = rs.getInt(1); String name = rs.getString(2); String type = rs.getString(3); - int start = rs.getInt(4); - int end = rs.getInt(5); - activeLeagues.add(new League(id, type, name, start, end)); + String clazz = rs.getString(4); + String parameters = rs.getString(5); + int start = rs.getInt(6); + int end = rs.getInt(7); + int status = rs.getInt(8); + activeLeagues.add(new League(id, name, type, clazz, parameters, start, end, status)); } return activeLeagues; } finally { @@ -75,4 +78,26 @@ public class LeagueDAO { conn.close(); } } + + public void setStatus(League league, int newStatus) { + try { + Connection connection = _dbAccess.getDataSource().getConnection(); + try { + String sql = "update league set status=? where id=?"; + + PreparedStatement statement = connection.prepareStatement(sql); + try { + statement.setInt(1, newStatus); + statement.setInt(2, league.getId()); + statement.execute(); + } finally { + statement.close(); + } + } finally { + connection.close(); + } + } catch (SQLException exp) { + throw new RuntimeException("Unable to update league status", exp); + } + } } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java index 6e545a9e3..2bde7428d 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java @@ -2,7 +2,7 @@ package com.gempukku.lotro.db; import com.gempukku.lotro.db.vo.League; import com.gempukku.lotro.db.vo.LeagueMatch; -import com.gempukku.lotro.db.vo.LeagueSerie; +import com.gempukku.lotro.league.LeagueSerieData; import java.sql.Connection; import java.sql.PreparedStatement; @@ -48,14 +48,14 @@ public class LeagueMatchDAO { } } - public Collection getLeagueSerieMatches(League league, LeagueSerie leagueSerie) { + public Collection getLeagueSerieMatches(League league, LeagueSerieData leagueSerie) { try { Connection conn = _dbAccess.getDataSource().getConnection(); try { PreparedStatement statement = conn.prepareStatement("select winner, loser from league_match where league_type=? and season_type=?"); try { statement.setString(1, league.getType()); - statement.setString(2, leagueSerie.getType()); + statement.setString(2, leagueSerie.getName()); ResultSet rs = statement.executeQuery(); try { Set result = new HashSet(); @@ -80,14 +80,14 @@ public class LeagueMatchDAO { } } - public Collection getPlayerMatchesPlayedOn(League league, LeagueSerie leagueSeason, String player) { + public Collection getPlayerMatchesPlayedOn(League league, LeagueSerieData leagueSeason, String player) { try { Connection conn = _dbAccess.getDataSource().getConnection(); try { PreparedStatement statement = conn.prepareStatement("select winner, loser from league_match where league_type=? and season_type=? and (winner=? or loser=?)"); try { statement.setString(1, league.getType()); - statement.setString(2, leagueSeason.getType()); + statement.setString(2, leagueSeason.getName()); statement.setString(3, player); statement.setString(4, player); ResultSet rs = statement.executeQuery(); @@ -114,14 +114,14 @@ public class LeagueMatchDAO { } } - public void addPlayedMatch(League league, LeagueSerie leagueSeason, String winner, String loser) { + public void addPlayedMatch(League league, LeagueSerieData leagueSeason, String winner, String loser) { try { Connection conn = _dbAccess.getDataSource().getConnection(); try { PreparedStatement statement = conn.prepareStatement("insert into league_match (league_type, season_type, winner, loser) values (?, ?, ?, ?)"); try { statement.setString(1, league.getType()); - statement.setString(2, leagueSeason.getType()); + statement.setString(2, leagueSeason.getName()); statement.setString(3, winner); statement.setString(4, loser); statement.execute(); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeaguePointsDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeaguePointsDAO.java index 4275098d2..37eab4490 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeaguePointsDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeaguePointsDAO.java @@ -1,7 +1,7 @@ package com.gempukku.lotro.db; import com.gempukku.lotro.db.vo.League; -import com.gempukku.lotro.db.vo.LeagueSerie; +import com.gempukku.lotro.league.LeagueSerieData; import java.sql.Connection; import java.sql.PreparedStatement; @@ -17,14 +17,14 @@ public class LeaguePointsDAO { _dbAccess = dbAccess; } - public synchronized void addPoints(League league, LeagueSerie serie, String playerName, int points) { + public synchronized void addPoints(League league, LeagueSerieData serie, String playerName, int points) { try { Connection conn = _dbAccess.getDataSource().getConnection(); try { PreparedStatement statement = conn.prepareStatement("insert into league_points (league_type, season_type, player_name, points) values (?, ?, ?, ?)"); try { statement.setString(1, league.getType()); - statement.setString(2, serie.getType()); + statement.setString(2, serie.getName()); statement.setString(3, playerName); statement.setInt(4, points); statement.execute(); @@ -74,14 +74,14 @@ public class LeaguePointsDAO { return result; } - public Map getLeagueSeriePoints(League league, LeagueSerie serie) { + public Map getLeagueSeriePoints(League league, LeagueSerieData serie) { try { Connection conn = _dbAccess.getDataSource().getConnection(); try { PreparedStatement statement = conn.prepareStatement("select player_name, sum(points), count(*) from league_points where league_type=? and season_type=? group by player_name order by 2 desc, 3 asc"); try { statement.setString(1, league.getType()); - statement.setString(2, serie.getType()); + statement.setString(2, serie.getName()); ResultSet rs = statement.executeQuery(); try { return createPoints(rs); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueSerieDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueSerieDAO.java deleted file mode 100644 index 87688d533..000000000 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueSerieDAO.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.gempukku.lotro.db; - -import com.gempukku.lotro.db.vo.League; -import com.gempukku.lotro.db.vo.LeagueSerie; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -public class LeagueSerieDAO { - private DbAccess _dbAccess; - - public LeagueSerieDAO(DbAccess dbAccess) { - _dbAccess = dbAccess; - } - - public void addSerie(String leagueType, String seasonType, String format, String collection, 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, format, collection, status, start, end, max_matches) values (?, ?, ?, ?, ?, ?, ?, ?)"); - try { - statement.setString(1, leagueType); - statement.setString(2, seasonType); - statement.setString(3, format); - statement.setString(4, collection); - statement.setInt(5, 0); - statement.setInt(6, start); - statement.setInt(7, end); - statement.setInt(8, maxMatches); - statement.execute(); - } finally { - statement.close(); - } - } finally { - conn.close(); - } - } catch (SQLException exp) { - throw new RuntimeException(exp); - } - } - - public void setCollectionGiven(LeagueSerie leagueSerie) { - try { - Connection conn = _dbAccess.getDataSource().getConnection(); - try { - PreparedStatement statement = conn.prepareStatement("update league_season set status = 1 where league_type = ? and season_type = ?"); - try { - statement.setString(1, leagueSerie.getLeagueType()); - statement.setString(2, leagueSerie.getType()); - statement.execute(); - } finally { - statement.close(); - } - } finally { - conn.close(); - } - } catch (SQLException exp) { - throw new RuntimeException(exp); - } - } - - public List getSeriesForLeague(League league) { - try { - Connection conn = _dbAccess.getDataSource().getConnection(); - try { - PreparedStatement statement = conn.prepareStatement("select league_type, season_type, format, collection, status, max_matches, start, end from league_season where league_type=? order by start asc"); - try { - statement.setString(1, league.getType()); - ResultSet rs = statement.executeQuery(); - try { - List seasons = new LinkedList(); - while (rs.next()) { - String leagueType = rs.getString(1); - String type = rs.getString(2); - String format = rs.getString(3); - Map collection = createCollection(rs.getString(4)); - int status = rs.getInt(5); - int maxMatches = rs.getInt(6); - int start = rs.getInt(7); - int end = rs.getInt(8); - seasons.add(new LeagueSerie(leagueType, type, format, collection, status, maxMatches, start, end)); - } - return seasons; - } finally { - rs.close(); - } - } finally { - statement.close(); - } - } finally { - conn.close(); - } - } catch (SQLException exp) { - throw new RuntimeException(exp); - } - } - - private Map createCollection(String collection) { - Map result = new HashMap(); - if (collection != null) { - final String[] items = collection.split("\n"); - for (String item : items) { - final String[] xes = item.trim().split("x", 2); - result.put(xes[1], Integer.parseInt(xes[0])); - } - } - return result; - } - - public LeagueSerie getSerieForLeague(League league, int inTime) { - try { - Connection conn = _dbAccess.getDataSource().getConnection(); - try { - PreparedStatement statement = conn.prepareStatement("select league_type, season_type, format, collection, status, max_matches, start, end from league_season where league_type=? and start<=? and end>=?"); - try { - statement.setString(1, league.getType()); - statement.setInt(2, inTime); - statement.setInt(3, inTime); - ResultSet rs = statement.executeQuery(); - try { - if (rs.next()) { - String leagueType = rs.getString(1); - String type = rs.getString(2); - String format = rs.getString(3); - Map collection = createCollection(rs.getString(4)); - int status = rs.getInt(5); - int maxMatches = rs.getInt(6); - int start = rs.getInt(7); - int end = rs.getInt(8); - return new LeagueSerie(leagueType, type, format, collection, status, maxMatches, start, end); - } - return null; - } finally { - rs.close(); - } - } finally { - statement.close(); - } - } finally { - conn.close(); - } - } catch (SQLException exp) { - throw new RuntimeException(exp); - } - } -} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/CollectionType.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/CollectionType.java index b87c3badc..680a7126c 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/CollectionType.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/CollectionType.java @@ -1,8 +1,8 @@ package com.gempukku.lotro.db.vo; -public class CollectionType { - private String _code; - private String _fullName; +public final class CollectionType { + private final String _code; + private final String _fullName; public CollectionType(String code, String fullName) { _code = code; @@ -16,4 +16,24 @@ public class CollectionType { public String getFullName() { return _fullName; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CollectionType that = (CollectionType) o; + + if (_code != null ? !_code.equals(that._code) : that._code != null) return false; + if (_fullName != null ? !_fullName.equals(that._fullName) : that._fullName != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = _code != null ? _code.hashCode() : 0; + result = 31 * result + (_fullName != null ? _fullName.hashCode() : 0); + return result; + } } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/League.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/League.java index 85ecd5516..7635f980e 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/League.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/League.java @@ -1,42 +1,62 @@ package com.gempukku.lotro.db.vo; +import com.gempukku.lotro.league.LeagueData; + +import java.lang.reflect.Constructor; + public class League { private int _id; - private String _type; private String _name; + private String _type; + private String _clazz; + private String _parameters; private int _start; private int _end; + private int _status; - public League(int id, String type, String name, int start, int end) { + public League(int id, String name, String type, String clazz, String parameters, int start, int end, int status) { _id = id; - _type = type; _name = name; + _type = type; + _clazz = clazz; + _parameters = parameters; _start = start; _end = end; + _status = status; } public int getId() { return _id; } - public CollectionType getCollectionType() { - return new CollectionType(_type, _name); + public String getName() { + return _name; } public String getType() { return _type; } - public String getName() { - return _name; + public LeagueData getLeagueData() { + try { + Class aClass = Class.forName(_clazz); + Constructor constructor = aClass.getConstructor(String.class); + return (LeagueData) constructor.newInstance(_parameters); + } catch (Exception exp) { + throw new RuntimeException("Unable to create LeagueData", exp); + } + } + + public int getStart() { + return _start; } public int getEnd() { return _end; } - public int getStart() { - return _start; + public int getStatus() { + return _status; } @Override diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueSerie.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueSerie.java deleted file mode 100644 index 6fa3b7aa1..000000000 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueSerie.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.gempukku.lotro.db.vo; - -import java.util.Collections; -import java.util.Map; - -public class LeagueSerie { - private String _leagueType; - private String _type; - private String _format; - private Map _serieCollection; - private int _status; - private int _maxMatches; - private int _start; - private int _end; - - public LeagueSerie(String leagueType, String type, String format, Map serieCollection, int status, int maxMatches, int start, int end) { - _leagueType = leagueType; - _type = type; - _format = format; - _serieCollection = serieCollection; - _status = status; - _maxMatches = maxMatches; - _start = start; - _end = end; - } - - public int getMaxMatches() { - return _maxMatches; - } - - public String getLeagueType() { - return _leagueType; - } - - public String getType() { - return _type; - } - - public String getFormat() { - return _format; - } - - public int getEnd() { - return _end; - } - - public int getStart() { - return _start; - } - - public boolean wasCollectionGiven() { - return _status == 1; - } - - public Map getSerieCollection() { - return Collections.unmodifiableMap(_serieCollection); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - LeagueSerie that = (LeagueSerie) o; - - if (_leagueType != null ? !_leagueType.equals(that._leagueType) : that._leagueType != null) return false; - if (_type != null ? !_type.equals(that._type) : that._type != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = _leagueType != null ? _leagueType.hashCode() : 0; - result = 31 * result + (_type != null ? _type.hashCode() : 0); - result = 31 * result + (_format != null ? _format.hashCode() : 0); - result = 31 * result + _maxMatches; - result = 31 * result + _start; - result = 31 * result + _end; - return result; - } -} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/AwaitingTable.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/AwaitingTable.java index 5d8fbc018..7c582d92c 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/AwaitingTable.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/AwaitingTable.java @@ -2,9 +2,9 @@ package com.gempukku.lotro.hall; import com.gempukku.lotro.db.vo.CollectionType; 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 com.gempukku.lotro.league.LeagueSerieData; import java.util.*; @@ -12,12 +12,12 @@ public class AwaitingTable { private CollectionType _collectionType; private LotroFormat _lotroFormat; private League _league; - private LeagueSerie _leagueSerie; + private LeagueSerieData _leagueSerie; private Map _players = new HashMap(); private int _capacity = 2; - public AwaitingTable(LotroFormat lotroFormat, CollectionType collectionType, League league, LeagueSerie leagueSerie) { + public AwaitingTable(LotroFormat lotroFormat, CollectionType collectionType, League league, LeagueSerieData leagueSerie) { _lotroFormat = lotroFormat; _collectionType = collectionType; _league = league; @@ -58,7 +58,7 @@ public class AwaitingTable { return _league; } - public LeagueSerie getLeagueSerie() { + public LeagueSerieData getLeagueSerie() { return _leagueSerie; } } 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 c24d1925c..c0118ed79 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 @@ -5,9 +5,9 @@ import com.gempukku.lotro.chat.ChatServer; import com.gempukku.lotro.collection.CollectionsManager; import com.gempukku.lotro.db.vo.CollectionType; 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.LeagueSerieData; import com.gempukku.lotro.league.LeagueService; import com.gempukku.lotro.logic.timing.GameResultListener; import com.gempukku.lotro.logic.vo.LotroDeck; @@ -106,7 +106,7 @@ public class HallServer extends AbstractServer { _hallDataAccessLock.writeLock().lock(); try { League league = null; - LeagueSerie leagueSerie = null; + LeagueSerieData leagueSerie = null; CollectionType collectionType = _allCardsCollectionType; LotroFormat format = _supportedFormats.get(type); @@ -121,7 +121,7 @@ public class HallServer extends AbstractServer { 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(); + collectionType = leagueSerie.getCollectionType(); } } // It's not a normal format and also not a league one @@ -293,7 +293,7 @@ public class HallServer extends AbstractServer { String tournamentName = "Casual"; final League league = table.getLeague(); if (league != null) - tournamentName = league.getName() + " - " + table.getLeagueSerie().getType(); + tournamentName = league.getName() + " - " + table.getLeagueSerie().getName(); return tournamentName; } @@ -301,7 +301,7 @@ public class HallServer extends AbstractServer { Set players = awaitingTable.getPlayers(); LotroGameParticipant[] participants = players.toArray(new LotroGameParticipant[players.size()]); final League league = awaitingTable.getLeague(); - final LeagueSerie leagueSerie = awaitingTable.getLeagueSerie(); + final LeagueSerieData leagueSerie = awaitingTable.getLeagueSerie(); String gameId = _lotroServer.createNewGame(awaitingTable.getLotroFormat(), participants, league != null); LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId); if (league != null) { @@ -321,7 +321,7 @@ public class HallServer extends AbstractServer { 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(); + LeagueSerieData leagueSerie = awaitingTable.getLeagueSerie(); if (!_leagueService.canPlayRankedGame(league, leagueSerie, playerId)) throw new HallException("You have already played max games in league"); if (awaitingTable.getPlayerNames().size() != 0 && !_leagueService.canPlayRankedGame(league, leagueSerie, awaitingTable.getPlayerNames().iterator().next(), playerId)) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueData.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueData.java new file mode 100644 index 000000000..bd0414942 --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueData.java @@ -0,0 +1,15 @@ +package com.gempukku.lotro.league; + +import com.gempukku.lotro.collection.CollectionsManager; +import com.gempukku.lotro.game.CardCollection; +import com.gempukku.lotro.game.Player; + +import java.util.List; + +public interface LeagueData { + public List getSeries(); + + public CardCollection joinLeague(CollectionsManager collecionsManager, Player player, int currentTime); + + public int process(CollectionsManager collectionsManager, int oldStatus, int currentTime); +} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueSerieData.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueSerieData.java new file mode 100644 index 000000000..a023f653c --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueSerieData.java @@ -0,0 +1,24 @@ +package com.gempukku.lotro.league; + +import com.gempukku.lotro.db.vo.CollectionType; +import com.gempukku.lotro.game.CardCollection; + +public interface LeagueSerieData { + public int getStart(); + + public int getEnd(); + + public int getMaxMatches(); + + public boolean isLimited(); + + public String getName(); + + public String getFormat(); + + public CollectionType getCollectionType(); + + public CardCollection getPrizeForLeagueMatchWinner(int winCountThisSerie, int totalGamesPlayedThisSerie); + + public CardCollection getPrizeForLeagueMatchLoser(int winCountThisSerie, int totalGamesPlayedThisSerie); +} 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 67cafed99..3c783d8f7 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 @@ -4,14 +4,10 @@ import com.gempukku.lotro.collection.CollectionsManager; import com.gempukku.lotro.db.LeagueDAO; import com.gempukku.lotro.db.LeagueMatchDAO; import com.gempukku.lotro.db.LeaguePointsDAO; -import com.gempukku.lotro.db.LeagueSerieDAO; import com.gempukku.lotro.db.vo.CollectionType; import com.gempukku.lotro.db.vo.League; import com.gempukku.lotro.db.vo.LeagueMatch; -import com.gempukku.lotro.db.vo.LeagueSerie; import com.gempukku.lotro.game.CardCollection; -import com.gempukku.lotro.game.DefaultCardCollection; -import com.gempukku.lotro.game.MutableCardCollection; import com.gempukku.lotro.game.Player; import java.io.IOException; @@ -27,26 +23,22 @@ public class LeagueService { new DescComparator(new OpponentsWinComparator())); private LeagueDAO _leagueDao; - private LeagueSerieDAO _leagueSeasonDao; private LeaguePointsDAO _leaguePointsDao; private LeagueMatchDAO _leagueMatchDao; private CollectionsManager _collectionsManager; - private LeaguePrizes _leaguePrizes; private Map> _leagueStandings = new ConcurrentHashMap>(); - private Map> _leagueSerieStandings = new ConcurrentHashMap>(); + private Map> _leagueSerieStandings = new ConcurrentHashMap>(); private int _activeLeaguesLoadedDate; private Set _activeLeagues; - public LeagueService(LeagueDAO leagueDao, LeagueSerieDAO leagueSeasonDao, LeaguePointsDAO leaguePointsDao, LeagueMatchDAO leagueMatchDao, + public LeagueService(LeagueDAO leagueDao, LeaguePointsDAO leaguePointsDao, LeagueMatchDAO leagueMatchDao, CollectionsManager collectionsManager) { _leagueDao = leagueDao; - _leagueSeasonDao = leagueSeasonDao; _leaguePointsDao = leaguePointsDao; _leagueMatchDao = leagueMatchDao; _collectionsManager = collectionsManager; - _leaguePrizes = new LeaguePrizes(); } public void clearCache() { @@ -86,36 +78,24 @@ public class LeagueService { private void processLoadedLeagues(int currentDate) { for (League activeLeague : _activeLeagues) { - for (LeagueSerie leagueSerie : _leagueSeasonDao.getSeriesForLeague(activeLeague)) { - if (leagueSerie.getStart() <= currentDate && !leagueSerie.wasCollectionGiven()) { - for (Map.Entry playerLeagueCollection : _collectionsManager.getPlayersCollection(activeLeague.getType()).entrySet()) { - _collectionsManager.addItemsToPlayerCollection(playerLeagueCollection.getKey(), activeLeague.getCollectionType(), leagueSerie.getSerieCollection()); - } - _leagueSeasonDao.setCollectionGiven(leagueSerie); - } - } + int oldStatus = activeLeague.getStatus(); + int newStatus = activeLeague.getLeagueData().process(_collectionsManager, oldStatus, currentDate); + if (newStatus != oldStatus) + _leagueDao.setStatus(activeLeague, newStatus); } } - public synchronized void ensurePlayerIsInLeague(Player player, League league) { - if (_collectionsManager.getPlayerCollection(player, league.getType()) == null) - playerJoinsLeague(player, league); - } - - private void playerJoinsLeague(Player player, League league) { - for (League activeLeague : getActiveLeagues()) { - if (activeLeague.getType().equals(league.getType())) { - MutableCardCollection startingCollection = new DefaultCardCollection(); - final List seriesForLeague = _leagueSeasonDao.getSeriesForLeague(league); - for (LeagueSerie leagueSerie : seriesForLeague) { - if (leagueSerie.wasCollectionGiven()) { - for (Map.Entry serieCollectionItem : leagueSerie.getSerieCollection().entrySet()) - startingCollection.addItem(serieCollectionItem.getKey(), serieCollectionItem.getValue()); - } + public synchronized CardCollection ensurePlayerHasCollection(Player player, String collectionType) { + for (League league : getActiveLeagues()) { + LeagueData leagueData = league.getLeagueData(); + for (LeagueSerieData leagueSerieData : leagueData.getSeries()) { + CollectionType serieCollectionType = leagueSerieData.getCollectionType(); + if (serieCollectionType != null && serieCollectionType.getCode().equals(collectionType)) { + return leagueData.joinLeague(_collectionsManager, player, getCurrentDate()); } - _collectionsManager.addPlayerCollection(player, league.getCollectionType(), startingCollection); } } + return null; } public League getLeagueByType(String type) { @@ -126,13 +106,29 @@ public class LeagueService { return null; } - public LeagueSerie getCurrentLeagueSerie(League league) { - final int startDay = getCurrentDate(); - - return _leagueSeasonDao.getSerieForLeague(league, startDay); + public CollectionType getCollectionTypeByCode(String collectionTypeCode) { + for (League league : getActiveLeagues()) { + for (LeagueSerieData leagueSerieData : league.getLeagueData().getSeries()) { + CollectionType collectionType = leagueSerieData.getCollectionType(); + if (collectionType != null && collectionType.getCode().equals(collectionTypeCode)) + return collectionType; + } + } + return null; } - public void reportLeagueGameResult(League league, LeagueSerie serie, String winner, String loser) { + public LeagueSerieData getCurrentLeagueSerie(League league) { + final int currentDate = getCurrentDate(); + + for (LeagueSerieData leagueSerieData : league.getLeagueData().getSeries()) { + if (currentDate >= leagueSerieData.getStart() && currentDate <= leagueSerieData.getEnd()) + return leagueSerieData; + } + + return null; + } + + public void reportLeagueGameResult(League league, LeagueSerieData serie, String winner, String loser) { _leagueMatchDao.addPlayedMatch(league, serie, winner, loser); _leaguePointsDao.addPoints(league, serie, winner, 2); _leaguePointsDao.addPoints(league, serie, loser, 1); @@ -143,7 +139,7 @@ public class LeagueService { awardPrizesToPlayer(league, serie, loser, false); } - private void awardPrizesToPlayer(League league, LeagueSerie serie, String player, boolean winner) { + private void awardPrizesToPlayer(League league, LeagueSerieData serie, String player, boolean winner) { int count = 0; Collection playerMatchesPlayedOn = _leagueMatchDao.getPlayerMatchesPlayedOn(league, serie, player); for (LeagueMatch leagueMatch : playerMatchesPlayedOn) { @@ -153,9 +149,9 @@ public class LeagueService { CardCollection prize; if (winner) - prize = _leaguePrizes.getPrizeForLeagueMatchWinner(count, playerMatchesPlayedOn.size(), league, serie); + prize = serie.getPrizeForLeagueMatchWinner(count, playerMatchesPlayedOn.size()); else - prize = _leaguePrizes.getPrizeForLeagueMatchLoser(count, playerMatchesPlayedOn.size(), league, serie); + prize = serie.getPrizeForLeagueMatchLoser(count, playerMatchesPlayedOn.size()); if (prize != null) _collectionsManager.addItemsToPlayerCollection(player, new CollectionType("permanent", "My cards"), prize.getAll()); } @@ -171,7 +167,7 @@ public class LeagueService { return leagueStandings; } - public List getLeagueSerieStandings(League league, LeagueSerie leagueSerie) { + public List getLeagueSerieStandings(League league, LeagueSerieData leagueSerie) { List serieStandings = _leagueSerieStandings.get(leagueSerie); if (serieStandings == null) { synchronized (this) { @@ -182,7 +178,7 @@ public class LeagueService { return serieStandings; } - private List createLeagueSerieStandings(League league, LeagueSerie leagueSerie) { + private List createLeagueSerieStandings(League league, LeagueSerieData leagueSerie) { final Map points = _leaguePointsDao.getLeagueSeriePoints(league, leagueSerie); final Collection matches = _leagueMatchDao.getLeagueSerieMatches(league, leagueSerie); @@ -242,7 +238,7 @@ public class LeagueService { opponents.add(opponent); } - public boolean canPlayRankedGame(League league, LeagueSerie season, String player) { + public boolean canPlayRankedGame(League league, LeagueSerieData season, String player) { int maxMatches = season.getMaxMatches(); Collection playedInSeason = _leagueMatchDao.getPlayerMatchesPlayedOn(league, season, player); if (playedInSeason.size() >= maxMatches) @@ -250,7 +246,7 @@ public class LeagueService { return true; } - public boolean canPlayRankedGame(League league, LeagueSerie season, String playerOne, String playerTwo) { + public boolean canPlayRankedGame(League league, LeagueSerieData 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())) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueData.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueData.java new file mode 100644 index 000000000..f5c1a8aa6 --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueData.java @@ -0,0 +1,98 @@ +package com.gempukku.lotro.league; + +import com.gempukku.lotro.collection.CollectionsManager; +import com.gempukku.lotro.db.vo.CollectionType; +import com.gempukku.lotro.game.CardCollection; +import com.gempukku.lotro.game.DefaultCardCollection; +import com.gempukku.lotro.game.MutableCardCollection; +import com.gempukku.lotro.game.Player; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +public class SealedLeagueData implements LeagueData { + private String _format; + private List _series; + private CollectionType _collectionType; + private SealedLeaguePrizes _leaguePrizes; + private SealedLeagueProduct _leagueProduct; + + public SealedLeagueData(String parameters) { + String[] params = parameters.split(","); + _format = params[0]; + int start = Integer.parseInt(params[1]); + _collectionType = new CollectionType(params[2], params[3]); + + int serieDuration = 7; + int maxMatches = 10; + + _leaguePrizes = new SealedLeaguePrizes(); + _leagueProduct = new SealedLeagueProduct(); + + _series = new LinkedList(); + for (int i = 0; i < 4; i++) { + _series.add( + new SealedLeagueSerieData(_leaguePrizes, "Week " + (i + 1), + getDate(start, i * serieDuration), getDate(start, (i + 1) * serieDuration - 1), maxMatches, _format, _collectionType)); + } + } + + private int getDate(int start, int dayOffset) { + try { + SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); + Date date = format.parse(String.valueOf(start)); + date.setDate(date.getDate() + dayOffset); + return Integer.parseInt(format.format(date)); + } catch (ParseException exp) { + throw new RuntimeException("Can't parse date", exp); + } + } + + @Override + public List getSeries() { + return Collections.unmodifiableList(_series); + } + + @Override + public CardCollection joinLeague(CollectionsManager collectionManager, Player player, int currentTime) { + MutableCardCollection startingCollection = new DefaultCardCollection(); + for (int i = 0; i < _series.size(); i++) { + LeagueSerieData serie = _series.get(i); + if (currentTime >= serie.getStart()) { + CardCollection leagueProduct = _leagueProduct.getCollectionForSerie(_format, i); + + for (Map.Entry serieCollectionItem : leagueProduct.getAll().entrySet()) + startingCollection.addItem(serieCollectionItem.getKey(), serieCollectionItem.getValue()); + } + } + collectionManager.addPlayerCollection(player, _collectionType, startingCollection); + return startingCollection; + } + + @Override + public int process(CollectionsManager collectionsManager, int oldStatus, int currentTime) { + int status = oldStatus; + + for (int i = status; i < _series.size(); i++) { + LeagueSerieData serie = _series.get(i); + if (currentTime >= serie.getStart()) { + CardCollection leagueProduct = _leagueProduct.getCollectionForSerie(_format, i); + Map map = collectionsManager.getPlayersCollection(_collectionType.getCode()); + for (Map.Entry playerCardCollectionEntry : map.entrySet()) { + collectionsManager.addItemsToPlayerCollection(playerCardCollectionEntry.getKey(), _collectionType, leagueProduct.getAll()); + } + status = i + 1; + } + } + + if (status == _series.size()) { + LeagueSerieData lastSerie = _series.get(_series.size() - 1); + if (currentTime >= getDate(lastSerie.getEnd(), 1)) { + // Award prizes and move collections + } + } + + return status; + } +} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeaguePrizes.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeaguePrizes.java similarity index 87% rename from gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeaguePrizes.java rename to gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeaguePrizes.java index d1a9d26a1..5e92020ce 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeaguePrizes.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeaguePrizes.java @@ -2,19 +2,17 @@ package com.gempukku.lotro.league; import com.gempukku.lotro.cards.packs.RarityReader; import com.gempukku.lotro.cards.packs.SetRarity; -import com.gempukku.lotro.db.vo.League; -import com.gempukku.lotro.db.vo.LeagueSerie; import com.gempukku.lotro.game.CardCollection; import com.gempukku.lotro.game.DefaultCardCollection; import java.util.*; -public class LeaguePrizes { +public class SealedLeaguePrizes { private Map> _blockPromos = new HashMap>(); private Map> _blockCommons = new HashMap>(); private Map> _blockUncommons = new HashMap>(); - public LeaguePrizes() { + public SealedLeaguePrizes() { List fotrPromos = new ArrayList(); fotrPromos.add("0_1"); fotrPromos.add("0_2"); @@ -93,14 +91,14 @@ public class LeaguePrizes { _blockUncommons.put("ttt_block", tttUncommons); } - public CardCollection getPrizeForLeagueMatchWinner(int winCountThisSerie, int totalGamesPlayedThisSerie, League league, LeagueSerie leagueSerie) { + public CardCollection getPrizeForLeagueMatchWinner(int winCountThisSerie, int totalGamesPlayedThisSerie, String format) { DefaultCardCollection winnerPrize = new DefaultCardCollection(); if (winCountThisSerie == 1 || winCountThisSerie == 3 || winCountThisSerie == 5 || winCountThisSerie == 8 || winCountThisSerie == 10) winnerPrize.addItem("(S)Booster Choice", 1); else { - List blockCommons = _blockCommons.get(leagueSerie.getFormat()); - List blockUncommons = _blockUncommons.get(leagueSerie.getFormat()); - List blockPromos = _blockPromos.get(leagueSerie.getFormat()); + List blockCommons = _blockCommons.get(format); + List blockUncommons = _blockUncommons.get(format); + List blockPromos = _blockPromos.get(format); if (winCountThisSerie == 2) winnerPrize.addItem(getRandom(blockCommons) + "*", 1); else if (winCountThisSerie == 4) @@ -117,7 +115,7 @@ public class LeaguePrizes { return winnerPrize; } - public CardCollection getPrizeForLeagueMatchLoser(int winCountThisSerie, int totalGamesPlayedThisSerie, League league, LeagueSerie leagueSerie) { + public CardCollection getPrizeForLeagueMatchLoser(int winCountThisSerie, int totalGamesPlayedThisSerie, String format) { return null; } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueProduct.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueProduct.java new file mode 100644 index 000000000..9499d8239 --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueProduct.java @@ -0,0 +1,81 @@ +package com.gempukku.lotro.league; + +import com.gempukku.lotro.game.CardCollection; +import com.gempukku.lotro.game.DefaultCardCollection; +import com.gempukku.lotro.game.MutableCardCollection; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SealedLeagueProduct { + private Map> _collections = new HashMap>(); + + public SealedLeagueProduct() { + createFellowshipBlock(); + createTowersBlock(); + } + + private void createFellowshipBlock() { + List fotrBlock = new ArrayList(); + + MutableCardCollection firstWeek = new DefaultCardCollection(); + firstWeek.addItem("(S)FotR - Starter", 1); + firstWeek.addItem("FotR - Booster", 6); + firstWeek.addItem("1_231", 2); + fotrBlock.add(firstWeek); + + MutableCardCollection secondWeek = new DefaultCardCollection(); + secondWeek.addItem("(S)MoM - Starter", 1); + secondWeek.addItem("MoM - Booster", 3); + secondWeek.addItem("2_51", 1); + fotrBlock.add(secondWeek); + + MutableCardCollection thirdWeek = new DefaultCardCollection(); + thirdWeek.addItem("(S)RotEL - Starter", 1); + thirdWeek.addItem("RotEL - Booster", 3); + fotrBlock.add(thirdWeek); + + MutableCardCollection fourthWeek = new DefaultCardCollection(); + fourthWeek.addItem("FotR - Booster", 2); + fourthWeek.addItem("MoM - Booster", 2); + fourthWeek.addItem("RotEL - Booster", 2); + fotrBlock.add(fourthWeek); + + _collections.put("fotr_block", fotrBlock); + } + + private void createTowersBlock() { + List tttBlock = new ArrayList(); + + MutableCardCollection firstWeek = new DefaultCardCollection(); + firstWeek.addItem("(S)TTT - Starter", 1); + firstWeek.addItem("TTT - Booster", 6); + firstWeek.addItem("4_356", 1); + firstWeek.addItem("4_249", 2); + tttBlock.add(firstWeek); + + MutableCardCollection secondWeek = new DefaultCardCollection(); + secondWeek.addItem("(S)BoHD - Starter", 1); + secondWeek.addItem("BoHD - Booster", 3); + tttBlock.add(secondWeek); + + MutableCardCollection thirdWeek = new DefaultCardCollection(); + thirdWeek.addItem("(S)EoF - Starter", 1); + thirdWeek.addItem("EoF - Booster", 3); + tttBlock.add(thirdWeek); + + MutableCardCollection fourthWeek = new DefaultCardCollection(); + fourthWeek.addItem("TTT - Booster", 2); + fourthWeek.addItem("BoHD - Booster", 2); + fourthWeek.addItem("EoF - Booster", 2); + tttBlock.add(fourthWeek); + + _collections.put("ttt_block", tttBlock); + } + + public CardCollection getCollectionForSerie(String format, int serieIndex) { + return _collections.get(format).get(serieIndex); + } +} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueSerieData.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueSerieData.java new file mode 100644 index 000000000..ed706328e --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueSerieData.java @@ -0,0 +1,69 @@ +package com.gempukku.lotro.league; + +import com.gempukku.lotro.db.vo.CollectionType; +import com.gempukku.lotro.game.CardCollection; + +public class SealedLeagueSerieData implements LeagueSerieData { + private SealedLeaguePrizes _leaguePrizes; + private String _name; + private int _start; + private int _end; + private int _maxMatches; + private String _format; + private CollectionType _collectionType; + + public SealedLeagueSerieData(SealedLeaguePrizes leaguePrizes, String name, int start, int end, int maxMatches, String format, CollectionType collectionType) { + _leaguePrizes = leaguePrizes; + _name = name; + _start = start; + _end = end; + _maxMatches = maxMatches; + _format = format; + _collectionType = collectionType; + } + + @Override + public String getName() { + return _name; + } + + @Override + public int getStart() { + return _start; + } + + @Override + public int getEnd() { + return _end; + } + + @Override + public int getMaxMatches() { + return _maxMatches; + } + + @Override + public boolean isLimited() { + return true; + } + + @Override + public String getFormat() { + return _format; + } + + @Override + public CollectionType getCollectionType() { + return _collectionType; + } + + @Override + public CardCollection getPrizeForLeagueMatchWinner(int winCountThisSerie, int totalGamesPlayedThisSerie) { + return _leaguePrizes.getPrizeForLeagueMatchWinner(winCountThisSerie, totalGamesPlayedThisSerie, _format); + } + + @Override + public CardCollection getPrizeForLeagueMatchLoser(int winCountThisSerie, int totalGamesPlayedThisSerie) { + return _leaguePrizes.getPrizeForLeagueMatchLoser(winCountThisSerie, totalGamesPlayedThisSerie, _format); + } +} diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java new file mode 100644 index 000000000..4bd66c651 --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java @@ -0,0 +1,153 @@ +package com.gempukku.lotro.league; + +import com.gempukku.lotro.collection.CollectionsManager; +import com.gempukku.lotro.db.vo.CollectionType; +import com.gempukku.lotro.game.CardCollection; +import com.gempukku.lotro.game.DefaultCardCollection; +import com.gempukku.lotro.game.Player; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.internal.verification.Times; + +import java.util.HashMap; +import java.util.Map; + +public class SealedLeagueDataTest { + @Test + public void testJoinLeagueFirstWeek() { + SealedLeagueData data = new SealedLeagueData("fotr_block,20120101,test,Test Collection"); + CollectionType collectionType = new CollectionType("test", "Test Collection"); + for (int i = 20120101; i < 20120108; i++) { + CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); + Player player = new Player(1, "Test", "A"); + data.joinLeague(collectionsManager, player, i); + Mockito.verify(collectionsManager, new Times(1)).addPlayerCollection(Mockito.eq(player), Mockito.eq(collectionType), Mockito.argThat( + new BaseMatcher() { + @Override + public void describeTo(Description description) { + description.appendText("Expected collection"); + } + + @Override + public boolean matches(Object o) { + CardCollection cards = (CardCollection) o; + Map cardMap = cards.getAll(); + if (cardMap.size() != 3) + return false; + if (cardMap.get("(S)FotR - Starter") != 1) + return false; + if (cardMap.get("FotR - Booster") != 6) + return false; + if (cardMap.get("1_231") != 2) + return false; + return true; + } + } + )); + Mockito.verifyNoMoreInteractions(collectionsManager); + } + } + + @Test + public void testJoinLeagueSecondWeek() { + SealedLeagueData data = new SealedLeagueData("fotr_block,20120101,test,Test Collection"); + CollectionType collectionType = new CollectionType("test", "Test Collection"); + for (int i = 20120108; i < 20120115; i++) { + CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); + Player player = new Player(1, "Test", "A"); + data.joinLeague(collectionsManager, player, i); + Mockito.verify(collectionsManager, new Times(1)).addPlayerCollection(Mockito.eq(player), Mockito.eq(collectionType), Mockito.argThat( + new BaseMatcher() { + @Override + public void describeTo(Description description) { + description.appendText("Expected collection"); + } + + @Override + public boolean matches(Object o) { + CardCollection cards = (CardCollection) o; + Map cardMap = cards.getAll(); + if (cardMap.size() != 6) + return false; + if (cardMap.get("(S)FotR - Starter") != 1) + return false; + if (cardMap.get("FotR - Booster") != 6) + return false; + if (cardMap.get("1_231") != 2) + return false; + if (cardMap.get("(S)MoM - Starter") != 1) + return false; + if (cardMap.get("MoM - Booster") != 3) + return false; + if (cardMap.get("2_51") != 1) + return false; + return true; + } + } + )); + Mockito.verifyNoMoreInteractions(collectionsManager); + } + } + + @Test + public void testSwitchToFirstWeek() { + SealedLeagueData data = new SealedLeagueData("fotr_block,20120101,test,Test Collection"); + for (int i = 20120101; i < 20120108; i++) { + CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); + Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(new HashMap()); + int result = data.process(collectionsManager, 0, i); + assertEquals(1, result); + Mockito.verify(collectionsManager, new Times(1)).getPlayersCollection("test"); + Mockito.verifyNoMoreInteractions(collectionsManager); + } + } + + @Test + public void testProcessMidFirstWeek() { + SealedLeagueData data = new SealedLeagueData("fotr_block,20120101,test,Test Collection"); + for (int i = 20120101; i < 20120108; i++) { + CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); + Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(new HashMap()); + int result = data.process(collectionsManager, 1, i); + assertEquals(1, result); + Mockito.verifyNoMoreInteractions(collectionsManager); + } + } + + @Test + public void testSwitchToSecondWeek() { + SealedLeagueData data = new SealedLeagueData("fotr_block,20120101,test,Test Collection"); + CollectionType collectionType = new CollectionType("test", "Test Collection"); + for (int i = 20120108; i < 20120115; i++) { + CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); + Map playersInLeague = new HashMap(); + Player player = new Player(1, "Test", "A"); + playersInLeague.put(player, new DefaultCardCollection()); + Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(playersInLeague); + int result = data.process(collectionsManager, 1, i); + assertEquals(2, result); + Map expectedToAdd = new HashMap(); + expectedToAdd.put("(S)MoM - Starter", 1); + expectedToAdd.put("MoM - Booster", 3); + expectedToAdd.put("2_51", 1); + Mockito.verify(collectionsManager, new Times(1)).getPlayersCollection("test"); + Mockito.verify(collectionsManager, new Times(1)).addItemsToPlayerCollection(Mockito.eq(player), Mockito.eq(collectionType), Mockito.eq(expectedToAdd)); + Mockito.verifyNoMoreInteractions(collectionsManager); + } + } + + @Test + public void testProcessMidSecondWeek() { + SealedLeagueData data = new SealedLeagueData("fotr_block,20120101,test,Test Collection"); + for (int i = 20120108; i < 20120115; i++) { + CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); + Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(new HashMap()); + int result = data.process(collectionsManager, 2, i); + assertEquals(2, result); + Mockito.verifyNoMoreInteractions(collectionsManager); + } + } +} diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeaguePrizesTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeaguePrizesTest.java similarity index 53% rename from gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeaguePrizesTest.java rename to gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeaguePrizesTest.java index 2c2978994..5fba5319e 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeaguePrizesTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeaguePrizesTest.java @@ -1,19 +1,15 @@ package com.gempukku.lotro.league; -import com.gempukku.lotro.db.vo.League; -import com.gempukku.lotro.db.vo.LeagueSerie; import com.gempukku.lotro.game.CardCollection; import org.junit.Test; import java.util.Map; -public class LeaguePrizesTest { +public class SealedLeaguePrizesTest { @Test public void test() { - LeaguePrizes leaguePrizes = new LeaguePrizes(); - League league = new League(1, "a", "bla", 1, 1); - LeagueSerie leagueSerie = new LeagueSerie("a", "b", "fotr_block", null, 0, 0, 0, 0); - CardCollection prize = leaguePrizes.getPrizeForLeagueMatchWinner(2, 2, league, leagueSerie); + SealedLeaguePrizes leaguePrizes = new SealedLeaguePrizes(); + CardCollection prize = leaguePrizes.getPrizeForLeagueMatchWinner(2, 2, "fotr_block"); for (Map.Entry stringIntegerEntry : prize.getAll().entrySet()) { System.out.println(stringIntegerEntry.getKey() + ": " + stringIntegerEntry.getValue()); } 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 8bd6e2a13..4c6608c61 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 @@ -2,6 +2,7 @@ 5 Mar. 2012 - "Discard to heal" actions now shows the card to the opponent, the same way, as in case of played events. - Stacking discarded Hobbits on Treebeard should no longer cancel their action, for which the cost was discarding them. +- "Relentless Warg" should no longer cause the game to freeze. 3 Mar. 2012 - "The Palantir of Orthanc, Recovered Seeing Stone" should no longer discard itself.