mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 12:02:01 -08:00
update deck every 5 seconds while constructing or sideboarding
This commit is contained in:
parent
beb2eb8e27
commit
fe79ee97a9
15 changed files with 161 additions and 16 deletions
|
|
@ -217,6 +217,22 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException {
|
||||
try {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
TableManager.getInstance().updateDeck(userId, tableId, deckList);
|
||||
logger.debug("Session " + sessionId + " updated deck");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof GameException)
|
||||
throw (GameException)ex;
|
||||
handleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableView> getTables(UUID roomId) throws MageException {
|
||||
try {
|
||||
return GamesRoomManager.getInstance().getRoom(roomId).getTables();
|
||||
|
|
|
|||
|
|
@ -209,7 +209,16 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void submitDeck(UUID userId, UUID playerId, Deck deck) {
|
||||
public void updateDeck(UUID userId, DeckCardLists deckList) throws MageException {
|
||||
UUID playerId = userPlayerMap.get(userId);
|
||||
if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
|
||||
return;
|
||||
}
|
||||
Deck deck = Deck.load(deckList);
|
||||
updateDeck(userId, playerId, deck);
|
||||
}
|
||||
|
||||
private void submitDeck(UUID userId, UUID playerId, Deck deck) {
|
||||
if (table.getState() == TableState.SIDEBOARDING) {
|
||||
match.submitDeck(playerId, deck);
|
||||
UserManager.getInstance().getUser(userId).removeSideboarding(table.getId());
|
||||
|
|
@ -220,7 +229,16 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID userId) {
|
||||
private void updateDeck(UUID userId, UUID playerId, Deck deck) {
|
||||
if (table.getState() == TableState.SIDEBOARDING) {
|
||||
match.updateDeck(playerId, deck);
|
||||
}
|
||||
else {
|
||||
TournamentManager.getInstance().updateDeck(tournament.getId(), playerId, deck);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID userId) {
|
||||
if (table.getState() != TableState.DUELING) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,7 +118,12 @@ public class TableManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void removeSession(UUID userId) {
|
||||
public void updateDeck(UUID userId, UUID tableId, DeckCardLists deckList) throws MageException {
|
||||
if (controllers.containsKey(tableId))
|
||||
controllers.get(tableId).updateDeck(userId, deckList);
|
||||
}
|
||||
|
||||
public void removeSession(UUID userId) {
|
||||
for (TableController controller: controllers.values()) {
|
||||
controller.kill(userId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,7 +220,11 @@ public class TournamentController {
|
|||
tournamentSessions.get(playerId).submitDeck(deck);
|
||||
}
|
||||
|
||||
public void timeout(UUID userId) {
|
||||
public void updateDeck(UUID playerId, Deck deck) {
|
||||
tournamentSessions.get(playerId).updateDeck(deck);
|
||||
}
|
||||
|
||||
public void timeout(UUID userId) {
|
||||
if (userPlayerMap.containsKey(userId)) {
|
||||
TournamentPlayer player = tournament.getPlayer(userPlayerMap.get(userId));
|
||||
tournament.autoSubmit(userPlayerMap.get(userId), player.generateDeck());
|
||||
|
|
|
|||
|
|
@ -69,7 +69,11 @@ public class TournamentManager {
|
|||
controllers.get(tournamentId).submitDeck(playerId, deck);
|
||||
}
|
||||
|
||||
public TournamentView getTournamentView(UUID tournamentId) {
|
||||
public void updateDeck(UUID tournamentId, UUID playerId, Deck deck) {
|
||||
controllers.get(tournamentId).updateDeck(playerId, deck);
|
||||
}
|
||||
|
||||
public TournamentView getTournamentView(UUID tournamentId) {
|
||||
return controllers.get(tournamentId).getTournamentView();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -112,7 +112,11 @@ public class TournamentSession {
|
|||
tournament.submitDeck(playerId, deck);
|
||||
}
|
||||
|
||||
protected void handleRemoteException(RemoteException ex) {
|
||||
public void updateDeck(Deck deck) {
|
||||
tournament.updateDeck(playerId, deck);
|
||||
}
|
||||
|
||||
protected void handleRemoteException(RemoteException ex) {
|
||||
logger.fatal("TournamentSession error ", ex);
|
||||
TournamentManager.getInstance().kill(tournament.getId(), userId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue