mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
Wait 2 seconds before making the draft pick for a timed out player (#10733)
* The draft session waits for 5 seconds before making the pick for the timed out player * Formatting * Renamed constant * Tweak * If the draft pick's timeout value would increase the client's pick's timer, don't set it (might happen if the client or server is lagging) * Lowered BOOSTER_LOADING_INTERVAL and AUTOPICK_BUFFER --------- Co-authored-by: sprangg <a@b.c>
This commit is contained in:
parent
456ea87107
commit
287df7af21
3 changed files with 25 additions and 12 deletions
|
|
@ -62,12 +62,13 @@
|
|||
private List<String> 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;
|
||||
|
|
@ -298,11 +299,15 @@
|
|||
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()) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue