From e2953ed181a68b40d35f487d395f86504cfea26d Mon Sep 17 00:00:00 2001 From: "jakub.salavec" Date: Tue, 11 Feb 2025 15:49:46 +0100 Subject: [PATCH] Recurring Scheduled Queue now supports limited sealed and solo draft tourneys --- .../tournament/RecurringScheduledQueue.java | 234 +++++++++++------- 1 file changed, 143 insertions(+), 91 deletions(-) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/RecurringScheduledQueue.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/RecurringScheduledQueue.java index 3d69ab46a..bbf9ccfc6 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/RecurringScheduledQueue.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/RecurringScheduledQueue.java @@ -1,92 +1,144 @@ -package com.gempukku.lotro.tournament; - -import com.gempukku.lotro.common.DateUtils; -import com.gempukku.lotro.collection.CollectionsManager; - -import java.io.IOException; -import java.sql.SQLException; -import java.time.Duration; -import java.time.ZonedDateTime; -import java.time.temporal.ChronoUnit; - -public class RecurringScheduledQueue extends AbstractTournamentQueue implements TournamentQueue { - private static final Duration _signupTimeBeforeStart = Duration.ofMinutes(60); - - private final Duration _repeatEvery; - private ZonedDateTime _nextStart; - private String _nextStartText; - - private final int _minimumPlayers; - - public RecurringScheduledQueue(TournamentService tournamentService, String queueId, String queueName, TournamentInfo info, Duration repeatEvery, int minPlayers) { - super(tournamentService, queueId, queueName, info); - _minimumPlayers = minPlayers; - - _repeatEvery = repeatEvery; - var sinceOriginal = Duration.between(info.StartTime, ZonedDateTime.now()); - long intervals = (sinceOriginal.getSeconds() / repeatEvery.getSeconds()) + 1; - - _nextStart = info.StartTime.plus(intervals * repeatEvery.getSeconds(), ChronoUnit.SECONDS); - _nextStartText = DateUtils.FormatDateTime(_nextStart); - - _tournamentInfo.StartTime = _nextStart; - } - - @Override - public String getStartCondition() { - return _nextStartText; - } - - @Override - public String getTournamentQueueName() { - return _tournamentQueueName; - } - - @Override - public String getPairingDescription() { - return _tournamentInfo.PairingMechanism.getPlayOffSystem() + ", minimum players: " + _minimumPlayers; - } - - @Override - public boolean isJoinable() { - return ZonedDateTime.now().isAfter(_nextStart.minus(_signupTimeBeforeStart)); - } - - @Override - public boolean process(TournamentQueueCallback tournamentQueueCallback, CollectionsManager collectionsManager) throws SQLException, IOException { - if (ZonedDateTime.now().isAfter(_nextStart)) { - if (_players.size() >= _minimumPlayers) { - String tid = _tournamentInfo.generateTimestampId(); - String tournamentName = _tournamentQueueName + " - " + DateUtils.getStringDateWithHour(); - - for (String player : _players) { - _tournamentService.recordTournamentPlayer(tid, player, _playerDecks.get(player)); - } - - var params = new TournamentParams() {{ - this.tournamentId = tid; - this.name = tournamentName; - this.format = getFormatCode(); - this.startTime = DateUtils.Now().toLocalDateTime(); - this.type = Tournament.TournamentType.CONSTRUCTED; - this.playoff = Tournament.PairingType.SINGLE_ELIMINATION; - this.manualKickoff = false; - this.cost = getCost(); - this.minimumPlayers = _minimumPlayers; - }}; - - var newInfo = new TournamentInfo(_tournamentInfo, params); - var tournament = _tournamentService.addTournament(newInfo); - tournamentQueueCallback.createTournament(tournament); - - _players.clear(); - _playerDecks.clear(); - } else { - leaveAllPlayers(collectionsManager); - } - _nextStart = _nextStart.plus(_repeatEvery); - _nextStartText = DateUtils.FormatDateTime(_nextStart); - } - return false; - } +package com.gempukku.lotro.tournament; + +import com.gempukku.lotro.common.DateUtils; +import com.gempukku.lotro.collection.CollectionsManager; + +import java.io.IOException; +import java.sql.SQLException; +import java.time.Duration; +import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; + +public class RecurringScheduledQueue extends AbstractTournamentQueue implements TournamentQueue { + private static final Duration _signupTimeBeforeStart = Duration.ofMinutes(60); + + private final Duration _repeatEvery; + private ZonedDateTime _nextStart; + private String _nextStartText; + + private final int _minimumPlayers; + + public RecurringScheduledQueue(TournamentService tournamentService, String queueId, String queueName, TournamentInfo info, Duration repeatEvery, int minPlayers) { + super(tournamentService, queueId, queueName, info); + _minimumPlayers = minPlayers; + + _repeatEvery = repeatEvery; + var sinceOriginal = Duration.between(info.StartTime, ZonedDateTime.now()); + long intervals = (sinceOriginal.getSeconds() / repeatEvery.getSeconds()) + 1; + + _nextStart = info.StartTime.plus(intervals * repeatEvery.getSeconds(), ChronoUnit.SECONDS); + _nextStartText = DateUtils.FormatDateTime(_nextStart); + + _tournamentInfo.StartTime = _nextStart; + } + + @Override + public String getStartCondition() { + return _nextStartText; + } + + @Override + public String getTournamentQueueName() { + return _tournamentQueueName; + } + + @Override + public String getPairingDescription() { + return _tournamentInfo.PairingMechanism.getPlayOffSystem() + ", minimum players: " + _minimumPlayers; + } + + @Override + public boolean isJoinable() { + return ZonedDateTime.now().isAfter(_nextStart.minus(_signupTimeBeforeStart)); + } + + @Override + public boolean process(TournamentQueueCallback tournamentQueueCallback, CollectionsManager collectionsManager) throws SQLException, IOException { + if (ZonedDateTime.now().isAfter(_nextStart)) { + if (_players.size() >= _minimumPlayers) { + String tid = _tournamentInfo.generateTimestampId(); + String tournamentName = _tournamentQueueName + " - " + DateUtils.getStringDateWithHour(); + + for (String player : _players) { + _tournamentService.recordTournamentPlayer(tid, player, _playerDecks.get(player)); + } + + boolean isSealed = _tournamentInfo instanceof SealedTournamentInfo; + boolean isSoloDraft = _tournamentInfo instanceof SoloDraftTournamentInfo; + + TournamentParams params; + TournamentInfo newInfo; + if (isSealed) { + params = new SealedTournamentParams() {{ + this.type = Tournament.TournamentType.SEALED; + + this.deckbuildingDuration = ((SealedTournamentParams) _tournamentInfo._params).deckbuildingDuration; + this.turnInDuration = ((SealedTournamentParams) _tournamentInfo._params).turnInDuration; + + this.sealedFormatCode = ((SealedTournamentParams) _tournamentInfo._params).sealedFormatCode; + this.format = _tournamentInfo._params.format; + this.requiresDeck = false; + + this.tournamentId = tid; + this.playoff = _tournamentInfo._params.playoff; + this.prizes = _tournamentInfo._params.prizes; + this.name = tournamentName; + this.format = getFormatCode(); + this.startTime = DateUtils.Now().toLocalDateTime(); + this.manualKickoff = false; + this.cost = getCost(); + this.minimumPlayers = _minimumPlayers; + }}; + newInfo = new SealedTournamentInfo((SealedTournamentInfo) _tournamentInfo, (SealedTournamentParams) params); + } else if (isSoloDraft) { + params = new SoloDraftTournamentParams() {{ + this.type = Tournament.TournamentType.SOLODRAFT; + + this.deckbuildingDuration = ((SoloDraftTournamentParams) _tournamentInfo._params).deckbuildingDuration; + this.turnInDuration = ((SoloDraftTournamentParams) _tournamentInfo._params).turnInDuration; + + this.soloDraftFormatCode = ((SoloDraftTournamentParams) _tournamentInfo._params).soloDraftFormatCode; + this.format = _tournamentInfo._params.format; + this.requiresDeck = false; + + this.tournamentId = tid; + this.playoff = _tournamentInfo._params.playoff; + this.prizes = _tournamentInfo._params.prizes; + this.name = tournamentName; + this.format = getFormatCode(); + this.startTime = DateUtils.Now().toLocalDateTime(); + this.manualKickoff = false; + this.cost = getCost(); + this.minimumPlayers = _minimumPlayers; + }}; + newInfo = new SoloDraftTournamentInfo((SoloDraftTournamentInfo) _tournamentInfo, (SoloDraftTournamentParams) params); + } else { + params = new TournamentParams() {{ + this.tournamentId = tid; + this.name = tournamentName; + this.format = getFormatCode(); + this.startTime = DateUtils.Now().toLocalDateTime(); + this.type = Tournament.TournamentType.CONSTRUCTED; + this.playoff = _tournamentInfo._params.playoff; + this.manualKickoff = false; + this.cost = getCost(); + this.minimumPlayers = _minimumPlayers; + }}; + newInfo = new TournamentInfo(_tournamentInfo, params); + } + + + var tournament = _tournamentService.addTournament(newInfo); + tournamentQueueCallback.createTournament(tournament); + + _players.clear(); + _playerDecks.clear(); + } else { + leaveAllPlayers(collectionsManager); + } + _nextStart = _nextStart.plus(_repeatEvery); + _nextStartText = DateUtils.FormatDateTime(_nextStart); + } + return false; + } } \ No newline at end of file