mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
* Draft - Added possibility to mark a card to draft on timeout. Added sounds to draft. Changed compression of some sound files.
This commit is contained in:
parent
c3adb1337b
commit
e6c7fa5f96
28 changed files with 317 additions and 90 deletions
|
|
@ -682,6 +682,21 @@ public class MageServerImpl implements MageServer {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCardMark(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
|
||||
execute("sendCardMark", sessionId, new Action() {
|
||||
@Override
|
||||
public void execute() {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
DraftManager.getInstance().sendCardMark(draftId, session.getUserId(), cardPick);
|
||||
} else{
|
||||
logger.error("Session not found sessionId: "+ sessionId + " draftId:" + draftId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void quitMatch(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("quitMatch", sessionId, new Action() {
|
||||
|
|
|
|||
|
|
@ -60,12 +60,14 @@ public class DraftController {
|
|||
private final UUID draftSessionId;
|
||||
private final Draft draft;
|
||||
private final UUID tableId;
|
||||
private UUID markedCard;
|
||||
|
||||
public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||
draftSessionId = UUID.randomUUID();
|
||||
this.userPlayerMap = userPlayerMap;
|
||||
this.draft = draft;
|
||||
this.tableId = tableId;
|
||||
this.markedCard = null;
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -208,6 +210,14 @@ public class DraftController {
|
|||
|
||||
public void timeout(UUID userId) {
|
||||
if (userPlayerMap.containsKey(userId)) {
|
||||
DraftSession draftSession = draftSessions.get(userPlayerMap.get(userId));
|
||||
if (draftSession != null) {
|
||||
UUID cardId = draftSession.getMarkedCard();
|
||||
if (cardId != null) {
|
||||
sendCardPick(userId, cardId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
draft.autoPick(userPlayerMap.get(userId));
|
||||
logger.debug("Draft pick timeout - autopick for player: " + userPlayerMap.get(userId));
|
||||
}
|
||||
|
|
@ -218,7 +228,16 @@ public class DraftController {
|
|||
}
|
||||
|
||||
public DraftPickView sendCardPick(UUID userId, UUID cardId) {
|
||||
return draftSessions.get(userPlayerMap.get(userId)).sendCardPick(cardId);
|
||||
DraftSession draftSession = draftSessions.get(userPlayerMap.get(userId));
|
||||
if (draftSession != null) {
|
||||
draftSession.setMarkedCard(null);
|
||||
return draftSession.sendCardPick(cardId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sendCardMark(UUID userId, UUID cardId) {
|
||||
draftSessions.get(userPlayerMap.get(userId)).setMarkedCard(cardId);
|
||||
}
|
||||
|
||||
private synchronized void updateDraft() throws MageException {
|
||||
|
|
|
|||
|
|
@ -66,6 +66,10 @@ public class DraftManager {
|
|||
return draftControllers.get(draftId).sendCardPick(userId, cardId);
|
||||
}
|
||||
|
||||
public void sendCardMark(UUID draftId, UUID userId, UUID cardId) {
|
||||
draftControllers.get(draftId).sendCardMark(userId, cardId);
|
||||
}
|
||||
|
||||
public void removeSession(UUID userId) {
|
||||
for (DraftController controller: draftControllers.values()) {
|
||||
controller.kill(userId);
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ public class DraftSession {
|
|||
protected UUID playerId;
|
||||
protected Draft draft;
|
||||
protected boolean killed = false;
|
||||
protected UUID markedCard;
|
||||
|
||||
private ScheduledFuture<?> futureTimeout;
|
||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||
|
|
@ -63,6 +64,7 @@ public class DraftSession {
|
|||
this.userId = userId;
|
||||
this.draft = draft;
|
||||
this.playerId = playerId;
|
||||
this.markedCard = null;
|
||||
}
|
||||
|
||||
public boolean init() {
|
||||
|
|
@ -175,4 +177,12 @@ public class DraftSession {
|
|||
return draft.getId();
|
||||
}
|
||||
|
||||
public UUID getMarkedCard() {
|
||||
return markedCard;
|
||||
}
|
||||
|
||||
public void setMarkedCard(UUID markedCard) {
|
||||
this.markedCard = markedCard;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue