From 1c24354e5236c519c9a50cfb0515f05743a98371 Mon Sep 17 00:00:00 2001 From: "jakub.salavec" Date: Mon, 16 Jun 2025 17:38:29 +0200 Subject: [PATCH] Added - queue configurator supports constructed games --- .../handler/TournamentRequestHandler.java | 53 ++++++++++++++----- .../src/main/web/css/gemp-001/hall.css | 6 +-- .../gemp-lotr-async/src/main/web/hall.html | 7 +-- .../src/main/web/js/gemp-022/communication.js | 8 +-- .../src/main/web/js/gemp-022/hallUi.js | 36 +++++++++---- .../com/gempukku/lotro/common/JSONDefs.java | 1 + .../com/gempukku/lotro/hall/HallServer.java | 9 +++- ...LimitedQueue.java => PlayerMadeQueue.java} | 6 +-- .../gempukku/lotro/tournament/Tournament.java | 6 +-- .../lotro/tournament/TournamentService.java | 19 +++---- ....java => WinForAwardTournamentPrizes.java} | 4 +- 11 files changed, 100 insertions(+), 55 deletions(-) rename gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/{PlayerMadeLimitedQueue.java => PlayerMadeQueue.java} (78%) rename gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/{LimitedTournamentPrizes.java => WinForAwardTournamentPrizes.java} (89%) diff --git a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/TournamentRequestHandler.java b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/TournamentRequestHandler.java index 11291de2d..395e8a2fb 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/TournamentRequestHandler.java +++ b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/TournamentRequestHandler.java @@ -13,6 +13,7 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary; import com.gempukku.lotro.game.Player; import com.gempukku.lotro.game.SortAndFilterCards; import com.gempukku.lotro.game.formats.LotroFormatLibrary; +import com.gempukku.lotro.hall.HallException; import com.gempukku.lotro.hall.HallServer; import com.gempukku.lotro.logic.vo.LotroDeck; import com.gempukku.lotro.packs.ProductLibrary; @@ -84,8 +85,8 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen getTournamentReport(request, uri.substring(1, uri.indexOf("/report/")), responseWriter); } else if (uri.equals("/create") && request.method() == HttpMethod.POST) { processPlayerMadeTournament(request, responseWriter); - } else if (uri.equals("/limitedFormats") && request.method() == HttpMethod.GET) { - getLimitedFormats(request, responseWriter); + } else if (uri.equals("/tournamentFormats") && request.method() == HttpMethod.GET) { + getTournamentFormats(request, responseWriter); } else if (uri.startsWith("/") && request.method() == HttpMethod.GET) { getTournamentInfo(request, uri.substring(1), responseWriter); } else { @@ -93,8 +94,9 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen } } - private void getLimitedFormats(HttpRequest request, ResponseWriter responseWriter) { + private void getTournamentFormats(HttpRequest request, ResponseWriter responseWriter) { JSONDefs.PlayerMadeTournamentAvailableFormats data = new JSONDefs.PlayerMadeTournamentAvailableFormats(); + Map availableSealedFormats = new HashMap<>(); availableSealedFormats.put("single_fotr_block_sealed", "Fellowship Block Sealed"); availableSealedFormats.put("single_ttt_block_sealed", "Towers Block Sealed"); @@ -103,11 +105,16 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen availableSealedFormats.put("single_movie_sealed", "Movie Sealed"); availableSealedFormats.put("single_wotr_block_sealed", "War of the Ring Block Sealed"); availableSealedFormats.put("single_th_block_sealed", "Hunters Block Sealed"); + Map availableSoloDraftFormats = new HashMap<>(); availableSoloDraftFormats.put("fotr_draft", "Fellowship Block"); availableSoloDraftFormats.put("ttt_draft", "Towers Block"); availableSoloDraftFormats.put("hobbit_random_draft", "Hobbit"); List orderedSoloDrafts = List.of("fotr_draft", "ttt_draft", "hobbit_random_draft"); + + data.constructed = _formatLibrary.getHallFormats().values().stream() + .map(constructedFormat -> new JSONDefs.ItemStub(constructedFormat.getCode(), constructedFormat.getName())) + .collect(Collectors.toList()); data.sealed = _formatLibrary.GetAllSealedTemplates().values().stream() .filter(sealedEventDefinition -> availableSealedFormats.containsKey(sealedEventDefinition.GetID())) .map(sealed -> new JSONDefs.ItemStub(sealed.GetID(), availableSealedFormats.get(sealed.GetID()))) @@ -128,6 +135,7 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen String participantId = getFormParameterSafely(postDecoder, "participantId"); Player resourceOwner = getResourceOwnerSafely(request, participantId); + String deckName = getFormParameterSafely(postDecoder, "deckName"); String typeStr = getFormParameterSafely(postDecoder, "type"); String deckbuildingDurationStr = getFormParameterSafely(postDecoder, "deckbuildingDuration"); @@ -144,6 +152,8 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen String readyCheckStr = getFormParameterSafely(postDecoder, "readyCheck"); int readyCheck = Throw400IfNullOrNonInteger("readyCheck", readyCheckStr); + String constructedFormatCodeStr = getFormParameterSafely(postDecoder, "constructedFormatCode"); + String sealedFormatCodeStr = getFormParameterSafely(postDecoder, "sealedFormatCode"); String soloDraftFormatCodeStr = getFormParameterSafely(postDecoder, "soloDraftFormatCode"); @@ -168,7 +178,14 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen String competitivePrefix = "Competitive "; String prefix = competitive ? competitivePrefix : casualPrefix; - if(type == Tournament.TournamentType.SEALED) { + if (type == Tournament.TournamentType.CONSTRUCTED) { + params.type = Tournament.TournamentType.CONSTRUCTED; + var format = _formatLibrary.getFormat(constructedFormatCodeStr); + Throw400IfValidationFails("constructedFormatCodeStr", constructedFormatCodeStr,format != null); + params.format = constructedFormatCodeStr; + params.name = prefix + format.getName(); + params.requiresDeck = true; + } else if(type == Tournament.TournamentType.SEALED) { var sealedParams = new SealedTournamentParams(); sealedParams.type = Tournament.TournamentType.SEALED; @@ -181,6 +198,7 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen sealedParams.sealedFormatCode = sealedFormatCodeStr; sealedParams.format = sealedFormat.GetFormat().getCode(); sealedParams.name = prefix + sealedFormat.GetName().substring(3); // Strip the ordering number for sealed formats + sealedParams.requiresDeck = false; params = sealedParams; } else if (type == Tournament.TournamentType.SOLODRAFT) { @@ -201,6 +219,7 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen case "hobbit_random_draft" -> soloDraftParams.name = prefix + "Hobbit Solo Draft"; default -> soloDraftParams.name = prefix + soloDraftFormatCodeStr; } + soloDraftParams.requiresDeck = false; params = soloDraftParams; } else if (type == Tournament.TournamentType.TABLE_SOLODRAFT) { @@ -216,6 +235,7 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen soloTableDraftParams.soloTableDraftFormatCode = soloTableDraftFormatCodeStr; soloTableDraftParams.format = tableDraftDefinition.getFormat(); soloTableDraftParams.name = prefix + tableDraftDefinition.getName(); + soloTableDraftParams.requiresDeck = false; params = soloTableDraftParams; } else if (type == Tournament.TournamentType.TABLE_DRAFT) { @@ -234,24 +254,26 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen tableDraftParams.format = tableDraftDefinition.getFormat(); tableDraftParams.draftTimerType = DraftTimer.getTypeFromString(tableDraftTimer); tableDraftParams.name = prefix + tableDraftDefinition.getName(); + tableDraftParams.requiresDeck = false; params = tableDraftParams; } else { - Throw400IfValidationFails("type", typeStr, false, "Only limited games"); + Throw400IfValidationFails("type", typeStr, false, "Unknown game type"); return; } - params.requiresDeck = false; params.tournamentId = params.format + System.currentTimeMillis(); params.cost = 0; // Gold is not being used, they can be free to enter params.playoff = Tournament.PairingType.parse(playoff); params.tiebreaker = "owr"; - params.prizes = Tournament.PrizeType.LIMITED; // At 4+ players, get one Event Award for each win or bye + params.prizes = Tournament.PrizeType.WIN_GAME_FOR_AWARD; // At 4+ players, get one Event Award for each win or bye params.maximumPlayers = maxPlayers; params.manualKickoff = false; TournamentInfo info; - if(type == Tournament.TournamentType.SEALED) { + if (type == Tournament.TournamentType.CONSTRUCTED) { + info = new TournamentInfo(_tournamentService, _productLibrary, _formatLibrary, DateUtils.Today(), params); + } else if (type == Tournament.TournamentType.SEALED) { info = new SealedTournamentInfo(_tournamentService, _productLibrary, _formatLibrary, DateUtils.Today(), (SealedTournamentParams)params); } else if (type == Tournament.TournamentType.SOLODRAFT) { @@ -264,14 +286,17 @@ public class TournamentRequestHandler extends LotroServerRequestHandler implemen info = new TableDraftTournamentInfo(_tournamentService, _productLibrary, _formatLibrary, DateUtils.Today(), ((TableDraftTournamentParams) params), _tableDraftLibrary); } else { - Throw400IfValidationFails("type", typeStr, false, "Only limited games"); + Throw400IfValidationFails("type", typeStr, false, "Unknown game type"); return; } - - if (_hallServer.addPlayerMadeLimitedQueue(info, resourceOwner, startable, readyCheck)) { - responseWriter.sendJsonOK(); - } else { - Throw400IfValidationFails("Error", "Error", false, "Error while creating queue or joining"); + try { + if (_hallServer.addPlayerMadeQueue(info, resourceOwner, deckName, startable, readyCheck)) { + responseWriter.sendJsonOK(); + } else { + Throw400IfValidationFails("Error", "Error", false, "Error while creating queue or joining"); + } + } catch (HallException badDeck) { + Throw400IfValidationFails("deckName", deckName, false, "Select valid deck for the requested format"); } } diff --git a/gemp-lotr/gemp-lotr-async/src/main/web/css/gemp-001/hall.css b/gemp-lotr/gemp-lotr-async/src/main/web/css/gemp-001/hall.css index 5e00cd073..d595acb96 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/web/css/gemp-001/hall.css +++ b/gemp-lotr/gemp-lotr-async/src/main/web/css/gemp-001/hall.css @@ -850,7 +850,7 @@ table.standings { margin-bottom: 5px; } -#limitedGameForm { +#queueSpawnerForm { display: grid; margin-left: 20px; padding-top: 8px; @@ -859,12 +859,12 @@ table.standings { max-width: 400px; } -form#limitedGameForm select { +form#queueSpawnerForm select { width: 100%; box-sizing: border-box; } -form#limitedGameForm input { +form#queueSpawnerForm input { width: 100%; box-sizing: border-box; } diff --git a/gemp-lotr/gemp-lotr-async/src/main/web/hall.html b/gemp-lotr/gemp-lotr-async/src/main/web/hall.html index afb922d71..3ebefa626 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/web/hall.html +++ b/gemp-lotr/gemp-lotr-async/src/main/web/hall.html @@ -226,14 +226,15 @@ -
Limited Games
-
-
+
Tournaments & Limited Games
+
+