diff --git a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java index 33a5b979617..0735d589723 100644 --- a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java +++ b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java @@ -62,12 +62,13 @@ private List setCodes; // Number of the current booster (for draft log writing). - // starts with 1 - private int packNo; + private int packNo = 1; // Number of the current card pick (for draft log writing). - // starts with 1 - private int pickNo; + private int pickNo = 1; + + // Number of the latest card pick for which the timeout has been set. + private int timeoutPickNo = 0; // Cached booster data to be written into the log (see logLastPick). private String[] currentBooster; @@ -297,12 +298,16 @@ MageTray.instance.displayMessage("Pick the next card."); MageTray.instance.blink(); } - - countdown.stop(); - this.timeout = draftPickView.getTimeout(); - setTimeout(timeout); - if (timeout != 0) { - countdown.start(); + + int newTimeout = draftPickView.getTimeout(); + if (pickNo != timeoutPickNo || newTimeout < timeout) { // if the timeout would increase the current pick's timer, don't set it (might happen if the client or server is lagging) + timeoutPickNo = pickNo; + countdown.stop(); + timeout = newTimeout; + setTimeout(timeout); + if (timeout != 0) { + countdown.start(); + } } if (!draftBooster.isEmptyGrid()) { diff --git a/Mage.Server/src/main/java/mage/server/draft/DraftSession.java b/Mage.Server/src/main/java/mage/server/draft/DraftSession.java index 150ac7a4282..352feae7c00 100644 --- a/Mage.Server/src/main/java/mage/server/draft/DraftSession.java +++ b/Mage.Server/src/main/java/mage/server/draft/DraftSession.java @@ -31,7 +31,10 @@ public class DraftSession { protected final Draft draft; protected boolean killed = false; protected UUID markedCard; + protected int timeoutCardNum; // the pick number for which the current timeout has been set up + protected int timeoutCounter = 0; // increments every second that the player has run out of picking time + protected final int AUTOPICK_BUFFER = 2; // seconds - when the player has run out of picking time, the autopick happens after this many seconds (to account for client timer possibly lagging behind server) private ScheduledFuture futureTimeout; protected final ScheduledExecutorService timeoutExecutor; @@ -92,11 +95,16 @@ public class DraftSession { private synchronized void setupTimeout(int seconds) { cancelTimeout(); if (seconds > 0) { + if (seconds > 1 ) { + timeoutCounter = 0; + } futureTimeout = timeoutExecutor.schedule( () -> { try { if (timeoutCardNum == draft.getCardNum()) { - managerFactory.draftManager().timeout(draft.getId(), userId); + if (timeoutCounter++ > AUTOPICK_BUFFER) { // the autopick happens after n seconds (to account for client timer possibly lagging behind server) + managerFactory.draftManager().timeout(draft.getId(), userId); + } setupTimeout(1); // The timeout keeps happening at a 1 second interval to make sure that the draft moves onto the next pick } } catch (Exception e) { diff --git a/Mage/src/main/java/mage/game/draft/DraftImpl.java b/Mage/src/main/java/mage/game/draft/DraftImpl.java index 251463d54b4..9d55f48b18f 100644 --- a/Mage/src/main/java/mage/game/draft/DraftImpl.java +++ b/Mage/src/main/java/mage/game/draft/DraftImpl.java @@ -34,7 +34,7 @@ public abstract class DraftImpl implements Draft { protected int cardNum = 1; // starts with card number 1, increases by +1 after each picking protected TimingOption timing; protected int boosterLoadingCounter; // number of times the boosters have been sent to players until all are confirmed to have received them - protected final int BOOSTER_LOADING_INTERVAL = 3; // interval in seconds + protected final int BOOSTER_LOADING_INTERVAL = 2; // interval in seconds protected boolean abort = false; protected boolean started = false;