mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Added a game end dialog, that shows the result of the finished game.
This commit is contained in:
parent
19726268ff
commit
ae44981cfa
19 changed files with 922 additions and 4 deletions
|
|
@ -155,6 +155,10 @@ public class TableController {
|
|||
tournament.addPlayer(player, seat.getPlayerType());
|
||||
table.joinTable(player, seat);
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user == null) {
|
||||
logger.fatal(new StringBuilder("couldn't get user ").append(name).append(" for join tornament userId = ").append(userId).toString());
|
||||
return false;
|
||||
}
|
||||
user.addTable(player.getId(), table);
|
||||
logger.info("player joined " + player.getId());
|
||||
//only inform human players and add them to sessionPlayerMap
|
||||
|
|
|
|||
|
|
@ -160,6 +160,10 @@ public class User {
|
|||
fireCallback(new ClientCallback("showTournament", tournamentId));
|
||||
}
|
||||
|
||||
public void showGameEndDialog(final UUID gameId) {
|
||||
fireCallback(new ClientCallback("showGameEndDialog", gameId));
|
||||
}
|
||||
|
||||
public void watchGame(final UUID gameId) {
|
||||
fireCallback(new ClientCallback("watchGame", gameId));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ import mage.cards.repository.CardRepository;
|
|||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameException;
|
||||
import mage.game.Table;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.PlayerQueryEvent;
|
||||
import mage.game.events.TableEvent;
|
||||
|
|
@ -141,6 +142,9 @@ public class GameController implements GameCallback {
|
|||
case ERROR:
|
||||
error(event.getMessage(), event.getException());
|
||||
break;
|
||||
case END_GAME_INFO:
|
||||
endGameInfo();
|
||||
break;
|
||||
case INIT_TIMER:
|
||||
final UUID initPlayerId = event.getPlayerId();
|
||||
if (initPlayerId == null) {
|
||||
|
|
@ -475,6 +479,21 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
}
|
||||
|
||||
private synchronized void endGameInfo() {
|
||||
Table table = TableManager.getInstance().getTable(tableId);
|
||||
if (table != null) {
|
||||
if (table.getMatch() != null) {
|
||||
for (final GameSession gameSession: gameSessions.values()) {
|
||||
gameSession.endGameInfo(table.getMatch());
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: inform watchers
|
||||
// for (final GameWatcher gameWatcher: watchers.values()) {
|
||||
// gameWatcher.update();
|
||||
// }
|
||||
}
|
||||
|
||||
private synchronized void ask(UUID playerId, final String question) throws MageException {
|
||||
perform(playerId, new Command() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import mage.cards.Cards;
|
||||
import mage.game.Game;
|
||||
import mage.game.match.Match;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.players.Player;
|
||||
import mage.players.net.UserData;
|
||||
|
|
@ -160,6 +161,15 @@ public class GameSession extends GameWatcher {
|
|||
}
|
||||
}
|
||||
|
||||
public void endGameInfo(Match match) {
|
||||
if (!killed) {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
user.fireCallback(new ClientCallback("endGameInfo", game.getId(), getGameEndView(playerId, match)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void setupTimeout() {
|
||||
if (!useTimeout) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.UUID;
|
||||
import mage.game.match.Match;
|
||||
import mage.view.GameEndView;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -124,5 +126,9 @@ public class GameWatcher {
|
|||
public GameView getGameView() {
|
||||
return new GameView(game.getState(), game);
|
||||
}
|
||||
|
||||
public GameEndView getGameEndView(UUID playerId, Match match) {
|
||||
return new GameEndView(game.getState(), game, playerId, match);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue