mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 11:32:00 -08:00
added draft timing
This commit is contained in:
parent
982ee064a6
commit
cb73d4a25d
11 changed files with 419 additions and 31 deletions
|
|
@ -108,7 +108,7 @@ public class DraftController {
|
|||
|
||||
public void join(UUID sessionId) {
|
||||
UUID playerId = sessionPlayerMap.get(sessionId);
|
||||
DraftSession draftSession = new DraftSession(sessionId, draft.getId());
|
||||
DraftSession draftSession = new DraftSession(draft, sessionId, playerId);
|
||||
draftSessions.put(playerId, draftSession);
|
||||
logger.info("player " + playerId + " has joined draft " + draft.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, "", draft.getPlayer(playerId).getPlayer().getName() + " has joined the draft", MessageColor.BLACK);
|
||||
|
|
@ -183,7 +183,7 @@ public class DraftController {
|
|||
}
|
||||
|
||||
public void sendCardPick(UUID sessionId, UUID cardId) {
|
||||
draft.addPick(sessionPlayerMap.get(sessionId), cardId);
|
||||
draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId);
|
||||
}
|
||||
|
||||
private synchronized void updateDraft() {
|
||||
|
|
@ -194,15 +194,15 @@ public class DraftController {
|
|||
|
||||
private synchronized void pickCard(UUID playerId, int timeout) {
|
||||
if (draftSessions.containsKey(playerId))
|
||||
draftSessions.get(playerId).pickCard(getDraftPickView(playerId), timeout);
|
||||
draftSessions.get(playerId).pickCard(getDraftPickView(playerId, timeout), timeout);
|
||||
}
|
||||
|
||||
private DraftView getDraftView() {
|
||||
return new DraftView(draft);
|
||||
}
|
||||
|
||||
private DraftPickView getDraftPickView(UUID playerId) {
|
||||
return new DraftPickView(draft.getPlayer(playerId));
|
||||
private DraftPickView getDraftPickView(UUID playerId, int timeout) {
|
||||
return new DraftPickView(draft.getPlayer(playerId), timeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
|
|
@ -54,15 +55,17 @@ public class DraftSession {
|
|||
protected final static Logger logger = Logging.getLogger(GameWatcher.class.getName());
|
||||
|
||||
protected UUID sessionId;
|
||||
protected UUID draftId;
|
||||
protected UUID playerId;
|
||||
protected Draft draft;
|
||||
protected boolean killed = false;
|
||||
|
||||
private ScheduledFuture<?> futureTimeout;
|
||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||
|
||||
public DraftSession(UUID sessionId, UUID draftId) {
|
||||
public DraftSession(Draft draft, UUID sessionId, UUID playerId) {
|
||||
this.sessionId = sessionId;
|
||||
this.draftId = draftId;
|
||||
this.draft = draft;
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
public boolean init(final DraftView draftView) {
|
||||
|
|
@ -121,15 +124,17 @@ public class DraftSession {
|
|||
|
||||
private synchronized void setupTimeout(int seconds) {
|
||||
cancelTimeout();
|
||||
futureTimeout = timeoutExecutor.schedule(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DraftManager.getInstance().timeout(draftId, sessionId);
|
||||
}
|
||||
},
|
||||
seconds, TimeUnit.SECONDS
|
||||
);
|
||||
if (seconds > 0) {
|
||||
futureTimeout = timeoutExecutor.schedule(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DraftManager.getInstance().timeout(draft.getId(), sessionId);
|
||||
}
|
||||
},
|
||||
seconds, TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void cancelTimeout() {
|
||||
|
|
@ -140,11 +145,16 @@ public class DraftSession {
|
|||
|
||||
protected void handleRemoteException(RemoteException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
DraftManager.getInstance().kill(draftId, sessionId);
|
||||
DraftManager.getInstance().kill(draft.getId(), sessionId);
|
||||
}
|
||||
|
||||
public void setKilled() {
|
||||
killed = true;
|
||||
}
|
||||
|
||||
public void sendCardPick(UUID cardId) {
|
||||
cancelTimeout();
|
||||
draft.addPick(playerId, cardId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue