From 4983e5c81537db7af1505687410e2a48d06d320d Mon Sep 17 00:00:00 2001 From: Christian 'ketura' McCarty Date: Sun, 25 Dec 2022 19:31:49 -0600 Subject: [PATCH] Adding support for playing the same person multiple times in a league - Extended the LeagueData definition to include a field for maximum number of matches between a pair of players - Ensured that the default is 1 for all league types - Constructed leagues now support reading a custom max rematch limit from the DB, although the UI doesn't reflect this --- .../lotro/async/handler/AdminRequestHandler.java | 6 ++++-- .../com/gempukku/lotro/league/LeagueData.java | 4 ++++ .../com/gempukku/lotro/league/LeagueService.java | 7 +++++-- .../lotro/league/NewConstructedLeagueData.java | 16 ++++++++++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/AdminRequestHandler.java b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/AdminRequestHandler.java index baa89b989..96e91b0e6 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/AdminRequestHandler.java +++ b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/AdminRequestHandler.java @@ -342,7 +342,9 @@ public class AdminRequestHandler extends LotroServerRequestHandler implements Ur String code = String.valueOf(System.currentTimeMillis()); StringBuilder sb = new StringBuilder(); - sb.append(start + "," + collectionType + "," + prizeMultiplier + "," + formats.size()); + //The 1 is a hard-coded maximum number of player matches per league. + //TODO: Get this put into the UI properly. + sb.append(start + "," + collectionType + "," + prizeMultiplier + "," + "1" + "," + formats.size()); for (int i = 0; i < formats.size(); i++) sb.append("," + formats.get(i) + "," + serieDurations.get(i) + "," + maxMatches.get(i)); @@ -390,7 +392,7 @@ public class AdminRequestHandler extends LotroServerRequestHandler implements Ur int cost = Integer.parseInt(costStr); StringBuilder sb = new StringBuilder(); - sb.append(start + "," + collectionType + "," + prizeMultiplier + "," + formats.size()); + sb.append(start + "," + collectionType + "," + prizeMultiplier + "," + "1" + "," + formats.size()); for (int i = 0; i < formats.size(); i++) sb.append("," + formats.get(i) + "," + serieDurations.get(i) + "," + maxMatches.get(i)); 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 index 7bbfd4b26..1820830dd 100644 --- 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 @@ -18,4 +18,8 @@ public interface LeagueData { CardCollection joinLeague(CollectionsManager collecionsManager, Player player, int currentTime); int process(CollectionsManager collectionsManager, List leagueStandings, int oldStatus, int currentTime); + + default int getMaxRepeatMatchesPerSerie() { + return 1; + } } 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 ff5230c5b..2018d37ed 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 @@ -237,10 +237,13 @@ public class LeagueService { public synchronized boolean canPlayRankedGameAgainst(League league, LeagueSerieData season, String playerOne, String playerTwo) { Collection playedInSeason = getPlayerMatchesInSerie(league, season, playerOne); + int maxGames = league.getLeagueData(_cardLibrary, _formatLibrary, _soloDraftDefinitions) + .getMaxRepeatMatchesPerSerie(); + int totalGames = 0; for (LeagueMatchResult leagueMatch : playedInSeason) { if (playerTwo.equals(leagueMatch.getWinner()) || playerTwo.equals(leagueMatch.getLoser())) - return false; + totalGames++; } - return true; + return totalGames < maxGames; } } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/NewConstructedLeagueData.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/NewConstructedLeagueData.java index fecc09820..2cc374b31 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/NewConstructedLeagueData.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/NewConstructedLeagueData.java @@ -21,6 +21,8 @@ public class NewConstructedLeagueData implements LeagueData { private final CollectionType _prizeCollectionType = CollectionType.MY_CARDS; private final CollectionType _collectionType; + private final int _maxRepeatGames; + public NewConstructedLeagueData(LotroCardBlueprintLibrary library, LotroFormatLibrary formatLibrary, String parameters) { _leaguePrizes = new FixedLeaguePrizes(library); @@ -31,13 +33,14 @@ public class NewConstructedLeagueData implements LeagueData { if (_collectionType == null) throw new IllegalArgumentException("Unknown collection type"); - int series = Integer.parseInt(params[3]); + _maxRepeatGames = Integer.parseInt(params[3]); + int series = Integer.parseInt(params[4]); int serieStart = start; for (int i = 0; i < series; i++) { - String format = params[4 + i * 3]; - int duration = Integer.parseInt(params[5 + i * 3]); - int maxMatches = Integer.parseInt(params[6 + i * 3]); + String format = params[5 + i * 3]; + int duration = Integer.parseInt(params[6 + i * 3]); + int maxMatches = Integer.parseInt(params[7 + i * 3]); _series.add(new DefaultLeagueSerieData(_leaguePrizes, false, "Serie " + (i + 1), serieStart, DateUtils.offsetDate(serieStart, duration - 1), maxMatches, formatLibrary.getFormat(format), _collectionType)); @@ -91,4 +94,9 @@ public class NewConstructedLeagueData implements LeagueData { return status; } + + @Override + public int getMaxRepeatMatchesPerSerie() { + return _maxRepeatGames; + } }