From 5a3020857c91bae079002b9cc0ebf0376f485de9 Mon Sep 17 00:00:00 2001 From: "jakub.salavec" Date: Thu, 24 Apr 2025 12:57:13 +0200 Subject: [PATCH] Added - draft json files may contain timer preference (to allow hobbit draft to be slower) --- .../async/handler/AdminRequestHandler.java | 4 +- .../async/handler/DeckRequestHandler.java | 4 +- .../draft-table/hobbitTableDraft.json | 1 + .../lotro/draft3/TableDraftDefinition.java | 2 + .../draft3/TableDraftDefinitionBuilder.java | 10 ++++ .../lotro/draft3/timer/DraftTimer.java | 55 ++++++++++++++++++- .../lotro/draft3/timer/DraftTimerClassic.java | 27 --------- .../lotro/draft3/timer/DraftTimerFactory.java | 42 -------------- .../lotro/draft3/timer/DraftTimerFast.java | 43 --------------- .../tournament/TableDraftTournament.java | 4 +- .../TableDraftTournamentParams.java | 4 +- .../lotro/tournament/TournamentService.java | 7 +-- 12 files changed, 77 insertions(+), 126 deletions(-) delete mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerClassic.java delete mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerFactory.java delete mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerFast.java 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 636c747e3..f5cd88884 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 @@ -12,7 +12,7 @@ import com.gempukku.lotro.db.vo.CollectionType; import com.gempukku.lotro.db.vo.League; import com.gempukku.lotro.draft2.SoloDraftDefinitions; import com.gempukku.lotro.draft3.TableDraftDefinitions; -import com.gempukku.lotro.draft3.timer.DraftTimerFactory; +import com.gempukku.lotro.draft3.timer.DraftTimer; import com.gempukku.lotro.game.CardCollection; import com.gempukku.lotro.game.LotroCardBlueprintLibrary; import com.gempukku.lotro.game.Player; @@ -1049,7 +1049,7 @@ public class AdminRequestHandler extends LotroServerRequestHandler implements Ur tableDraftParams.tableDraftFormatCode = tableDraftFormatCodeStr; tableDraftParams.format = tableDraftDefinition.getFormat(); tableDraftParams.requiresDeck = false; - tableDraftParams.draftTimerType = DraftTimerFactory.getTypeFromString(tableDraftTimer); + tableDraftParams.draftTimerType = DraftTimer.getTypeFromString(tableDraftTimer); tableDraftParams.maximumPlayers = tableDraftDefinition.getMaxPlayers(); params = tableDraftParams; } diff --git a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/DeckRequestHandler.java b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/DeckRequestHandler.java index 8c9539c76..f3b26e5c0 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/DeckRequestHandler.java +++ b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/DeckRequestHandler.java @@ -10,7 +10,7 @@ import com.gempukku.lotro.db.DeckDAO; import com.gempukku.lotro.db.DeckSerialization; import com.gempukku.lotro.draft2.SoloDraftDefinitions; import com.gempukku.lotro.draft3.TableDraftDefinitions; -import com.gempukku.lotro.draft3.timer.DraftTimerFactory; +import com.gempukku.lotro.draft3.timer.DraftTimer; import com.gempukku.lotro.game.*; import com.gempukku.lotro.game.formats.LotroFormatLibrary; import com.gempukku.lotro.league.SealedEventDefinition; @@ -120,7 +120,7 @@ public class DeckRequestHandler extends LotroServerRequestHandler implements Uri data.TableDraftTemplates = _tableDraftDefinitions.getAllTableDrafts().stream() .map(tableDraftDefinition -> new JSONDefs.ItemStub(tableDraftDefinition.getCode(), tableDraftDefinition.getName())) .collect(Collectors.toMap(itemStub -> itemStub.name, itemStub -> itemStub)); - data.TableDraftTimerTypes = DraftTimerFactory.getAllTypes(); + data.TableDraftTimerTypes = DraftTimer.getAllTypes(); json = JsonUtils.Serialize(data); } diff --git a/gemp-lotr/gemp-lotr-cards/src/main/resources/draft-table/hobbitTableDraft.json b/gemp-lotr/gemp-lotr-cards/src/main/resources/draft-table/hobbitTableDraft.json index d1528988f..08aed02ec 100644 --- a/gemp-lotr/gemp-lotr-cards/src/main/resources/draft-table/hobbitTableDraft.json +++ b/gemp-lotr/gemp-lotr-cards/src/main/resources/draft-table/hobbitTableDraft.json @@ -3,6 +3,7 @@ "code": "hobbit_table_draft", "format": "limited_hobbit", "max-players": 4, + "timer": "SLOW", "starting-collection": [ { "size": 68, diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/TableDraftDefinition.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/TableDraftDefinition.java index acd3e5119..ac2d5c2b1 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/TableDraftDefinition.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/TableDraftDefinition.java @@ -11,4 +11,6 @@ public interface TableDraftDefinition { String getName(); String getCode(); String getFormat(); + + DraftTimer.Type getRecommendedTimer(); } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/TableDraftDefinitionBuilder.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/TableDraftDefinitionBuilder.java index f6a4f66d8..ae31be97a 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/TableDraftDefinitionBuilder.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/TableDraftDefinitionBuilder.java @@ -43,6 +43,7 @@ public class TableDraftDefinitionBuilder { String name = (String) definition.get("name"); String code = (String) definition.get("code"); String format = (String) definition.get("format"); + String timer = (String) definition.get("timer"); int maxPlayers = ((Number) definition.get("max-players")).intValue(); @@ -79,6 +80,15 @@ public class TableDraftDefinitionBuilder { public String getFormat() { return format; } + + @Override + public DraftTimer.Type getRecommendedTimer() { + if (timer == null) { + return DraftTimer.Type.CLASSIC; + } else { + return DraftTimer.getTypeFromString(timer); + } + } }; } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimer.java index 5a7a986a3..23f46eb07 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimer.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimer.java @@ -1,5 +1,56 @@ package com.gempukku.lotro.draft3.timer; -public interface DraftTimer { - int getSecondsAllotted(int cardsInPack); + +import java.util.ArrayList; +import java.util.List; + +public class DraftTimer { + private static final int CLASSIC_SECS_PER_CARD = 6; + private static final int SLOW_SECS_PER_CARD = 10; + + public enum Type { + CLASSIC, SLOW, NO_TIMER + } + + private final int secsPerCard; + + public static DraftTimer get(DraftTimer.Type type) { + if (type == DraftTimer.Type.CLASSIC) { + return new DraftTimer(CLASSIC_SECS_PER_CARD); + } else if (type == DraftTimer.Type.SLOW) { + return new DraftTimer(SLOW_SECS_PER_CARD); + } else { + return null; + } + } + + + private DraftTimer(int secsPerCard) { + this.secsPerCard = secsPerCard; + } + + public int getSecondsAllotted(int cardsInPack) { + int tbr = secsPerCard * (cardsInPack - 1); + if (tbr <= 0) { + return secsPerCard; + } else { + return tbr; + } + } + + public static DraftTimer.Type getTypeFromString(String type) { + try { + return DraftTimer.Type.valueOf(type); + } catch (IllegalArgumentException ignored) { + return DraftTimer.Type.NO_TIMER; + } + } + + public static List getAllTypes() { + List tbr = new ArrayList<>(); + for (DraftTimer.Type value : DraftTimer.Type.values()) { + tbr.add(value.name()); + } + return tbr; + } } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerClassic.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerClassic.java deleted file mode 100644 index 7843cff72..000000000 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerClassic.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.gempukku.lotro.draft3.timer; - -import java.util.HashMap; -import java.util.Map; - -public class DraftTimerClassic implements DraftTimer{ - private Map durations = new HashMap<>(); - private static final int SECS_PER_CARD = 6; - - public DraftTimerClassic() { - durations.put(1, 5); - for (int i = 2; i <= 20; i++) { - durations.put(i, (i - 1) * SECS_PER_CARD); - } - } - - @Override - public int getSecondsAllotted(int cardsInPack) { - // Unknown duration - if (!durations.containsKey(cardsInPack)) { - return -1; - } - - // Look to map for info - return durations.get(cardsInPack); - } -} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerFactory.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerFactory.java deleted file mode 100644 index 9a4103511..000000000 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.gempukku.lotro.draft3.timer; - -import java.util.ArrayList; -import java.util.List; - -public class DraftTimerFactory { - private DraftTimerFactory() { - - } - - public enum Type { - CLASSIC, FAST, NO_TIMER - } - - public static DraftTimer getDraftTimer(Type type) { - if (type == Type.FAST) { - return new DraftTimerFast(); - } else if (type == Type.CLASSIC) { - return new DraftTimerClassic(); - } else { - return null; - } - } - - public static Type getTypeFromString(String type) { - try { - return Type.valueOf(type); - } catch (IllegalArgumentException ignored) { - return Type.NO_TIMER; - } - } - - public static List getAllTypes() { - List tbr = new ArrayList<>(); - for (Type value : Type.values()) { - tbr.add(value.name()); - } - return tbr; - } - - -} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerFast.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerFast.java deleted file mode 100644 index a11a38977..000000000 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft3/timer/DraftTimerFast.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.gempukku.lotro.draft3.timer; - -import java.util.HashMap; -import java.util.Map; - -public class DraftTimerFast implements DraftTimer{ - private Map durations = new HashMap<>(); - - public DraftTimerFast() { - // MtG timer from Tournament Guides until 15 cards, then extended to 20 - durations.put(1, 5); - durations.put(2, 5); - durations.put(3, 5); - durations.put(4, 5); - durations.put(5, 10); - durations.put(6, 10); - durations.put(7, 15); - durations.put(8, 20); - durations.put(9, 20); - durations.put(10, 25); - durations.put(11, 25); - durations.put(12, 30); - durations.put(13, 35); - durations.put(14, 40); - durations.put(15, 40); - durations.put(16, 45); - durations.put(17, 45); - durations.put(18, 50); - durations.put(19, 50); - durations.put(20, 55); - } - - @Override - public int getSecondsAllotted(int cardsInPack) { - // Unknown duration - if (!durations.containsKey(cardsInPack)) { - return -1; - } - - // Look to map for info - return durations.get(cardsInPack); - } -} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TableDraftTournament.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TableDraftTournament.java index e2f69d630..f89e89da6 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TableDraftTournament.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TableDraftTournament.java @@ -9,7 +9,7 @@ import com.gempukku.lotro.draft.Draft; import com.gempukku.lotro.draft2.SoloDraftDefinitions; import com.gempukku.lotro.draft3.TableDraft; import com.gempukku.lotro.draft3.TableDraftDefinitions; -import com.gempukku.lotro.draft3.timer.DraftTimerFactory; +import com.gempukku.lotro.draft3.timer.DraftTimer; import com.gempukku.lotro.game.formats.LotroFormatLibrary; import com.gempukku.lotro.hall.TableHolder; import com.gempukku.lotro.logic.vo.LotroDeck; @@ -131,7 +131,7 @@ public class TableDraftTournament extends BaseTournament implements Tournament { private void createTable() { // Create one table for all players and start if (table == null) { - table = _tableDraftLibrary.getTableDraftDefinition(tableDraftInfo.tableDraftParams.tableDraftFormatCode).getTableDraft(_collectionsManager, getCollectionType(), DraftTimerFactory.getDraftTimer(tableDraftInfo.tableDraftParams.draftTimerType)); + table = _tableDraftLibrary.getTableDraftDefinition(tableDraftInfo.tableDraftParams.tableDraftFormatCode).getTableDraft(_collectionsManager, getCollectionType(), DraftTimer.get(tableDraftInfo.tableDraftParams.draftTimerType)); for (String playerName : _players) { table.registerPlayer(playerName); } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TableDraftTournamentParams.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TableDraftTournamentParams.java index 91f8a7c5a..a9284a3d2 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TableDraftTournamentParams.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TableDraftTournamentParams.java @@ -1,9 +1,9 @@ package com.gempukku.lotro.tournament; -import com.gempukku.lotro.draft3.timer.DraftTimerFactory; +import com.gempukku.lotro.draft3.timer.DraftTimer; public class TableDraftTournamentParams extends TournamentParams { - public DraftTimerFactory.Type draftTimerType; + public DraftTimer.Type draftTimerType; public int deckbuildingDuration; public int turnInDuration; public String tableDraftFormatCode; diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TournamentService.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TournamentService.java index 31c0e83da..ff43247c5 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TournamentService.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/TournamentService.java @@ -9,7 +9,6 @@ import com.gempukku.lotro.db.vo.CollectionType; import com.gempukku.lotro.draft2.SoloDraftDefinitions; import com.gempukku.lotro.draft3.TableDraftDefinition; import com.gempukku.lotro.draft3.TableDraftDefinitions; -import com.gempukku.lotro.draft3.timer.DraftTimerFactory; import com.gempukku.lotro.game.LotroCardBlueprintLibrary; import com.gempukku.lotro.game.Player; import com.gempukku.lotro.game.formats.LotroFormatLibrary; @@ -139,7 +138,7 @@ public class TournamentService { ); } - private void addImmediateRecurringTableDraft(String queueId, String queueName, String prefix, String formatCode, int players, DraftTimerFactory.Type draftTimer) { + private void addImmediateRecurringTableDraft(String queueId, String queueName, String prefix, String formatCode, int players) { TournamentQueueCallback callback = tournament -> _activeTournaments.put(tournament.getTournamentId(), tournament); TableDraftTournamentParams draftParams = new TableDraftTournamentParams(); @@ -147,11 +146,11 @@ public class TournamentService { draftParams.deckbuildingDuration = 15; draftParams.turnInDuration = 2; - draftParams.draftTimerType = draftTimer; TableDraftDefinition tableDraft = _tableDraftLibrary.getTableDraftDefinition(formatCode); draftParams.tableDraftFormatCode = formatCode; draftParams.format = tableDraft.getFormat(); + draftParams.draftTimerType = tableDraft.getRecommendedTimer(); draftParams.requiresDeck = false; draftParams.tournamentId = prefix; @@ -216,7 +215,7 @@ public class TournamentService { _tableDraftLibrary.getAllTableDrafts().forEach(tableDraftDefinition -> { String code = tableDraftDefinition.getCode(); - addImmediateRecurringTableDraft(code + "_queue", casual + tableDraftDefinition.getName(), code + "-", code, tableDraftDefinition.getMaxPlayers(), DraftTimerFactory.Type.CLASSIC); + addImmediateRecurringTableDraft(code + "_queue", casual + tableDraftDefinition.getName(), code + "-", code, tableDraftDefinition.getMaxPlayers()); }); addImmediateRecurringDraft("fotr_solo_draft_queue", casual + "FotR Solo Draft", "fotrSoloDraft-", "fotr_draft");