From 513b012dc0155bd13f615887d9fcf104e2ecb8bc Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 25 Jun 2014 01:34:11 +0200 Subject: [PATCH] * Fixed draw handling. Fixed concede handling. Fixed message generation for game end view. Added some debug messages. --- Mage.Common/src/mage/view/GameEndView.java | 14 +++---- Mage.Common/src/mage/view/MatchView.java | 14 +++++-- Mage.Common/src/mage/view/TableView.java | 3 ++ .../src/mage/game/TwoPlayerDuel.java | 5 --- .../main/java/mage/server/MageServerImpl.java | 2 +- Mage/src/mage/game/Game.java | 2 +- Mage/src/mage/game/GameCommanderImpl.java | 13 ------ Mage/src/mage/game/GameImpl.java | 16 +++++-- Mage/src/mage/game/match/Match.java | 3 ++ Mage/src/mage/game/match/MatchImpl.java | 42 ++++++++++++++----- Mage/src/mage/game/match/MatchPlayer.java | 18 -------- .../mage/game/tournament/TournamentImpl.java | 11 +++-- Mage/src/mage/players/PlayerImpl.java | 19 +++++++-- 13 files changed, 92 insertions(+), 70 deletions(-) diff --git a/Mage.Common/src/mage/view/GameEndView.java b/Mage.Common/src/mage/view/GameEndView.java index 39b1fbf76c..c13d9f258a 100644 --- a/Mage.Common/src/mage/view/GameEndView.java +++ b/Mage.Common/src/mage/view/GameEndView.java @@ -97,24 +97,24 @@ public class GameEndView implements Serializable { if (matchPlayer.isMatchWinner()) { matchWinner = matchPlayer; } - if (matchPlayer.hasTimerTimeout()) { + if (matchPlayer.getPlayer().hasTimerTimeout()) { if (matchPlayer.getPlayer().equals(you)) { additonalText.append("You run out of time. "); } else { additonalText.append(matchPlayer.getName()).append(" runs out of time. "); } - } else if (matchPlayer.hasQuit()) { - if (matchPlayer.getPlayer().equals(you)) { - additonalText.append("You have quit the match. "); - } else { - additonalText.append(matchPlayer.getName()).append(" has quit the match. "); - } } else if (matchPlayer.getPlayer().hasIdleTimeout()) { if (matchPlayer.getPlayer().equals(you)) { additonalText.append("You lost the match for beeing idle. "); } else { additonalText.append(matchPlayer.getName()).append(" lost for beeing idle. "); } + } else if (matchPlayer.hasQuit()) { + if (matchPlayer.getPlayer().equals(you)) { + additonalText.append("You have quit the match. "); + } else { + additonalText.append(matchPlayer.getName()).append(" has quit the match. "); + } } } diff --git a/Mage.Common/src/mage/view/MatchView.java b/Mage.Common/src/mage/view/MatchView.java index 5bb8f0fca5..cbe13370f4 100644 --- a/Mage.Common/src/mage/view/MatchView.java +++ b/Mage.Common/src/mage/view/MatchView.java @@ -67,6 +67,7 @@ public class MatchView implements Serializable { this.matchName = match.getName(); this.gameType = match.getOptions().getGameType(); this.deckType = match.getOptions().getDeckType(); + for (Game game: match.getGames()) { games.add(game.getId()); } @@ -75,15 +76,22 @@ public class MatchView implements Serializable { for (MatchPlayer matchPlayer: match.getPlayers()) { sb1.append(matchPlayer.getName()); if(matchPlayer.hasQuit()) { - if (matchPlayer.hasTimerTimeout()) { + if (matchPlayer.getPlayer().hasTimerTimeout()) { sb1.append(" [timer] "); + } else if (matchPlayer.getPlayer().hasIdleTimeout()) { + sb1.append(" [idle] "); } else { sb1.append(" [quit] "); } } + int lostGames = match.getNumGames() - (matchPlayer.getWins() + match.getDraws()); sb1.append(", "); - sb2.append(matchPlayer.getName()).append(" "); - sb2.append(matchPlayer.getWins()).append("-").append(matchPlayer.getLoses()).append(", "); + sb2.append(matchPlayer.getName()).append(" ["); + sb2.append(matchPlayer.getWins()).append("-"); + if (match.getDraws() > 0) { + sb2.append(match.getDraws()).append("-"); + } + sb2.append(lostGames).append("], "); } players = sb1.substring(0, sb1.length() - 2); result = sb2.substring(0, sb2.length() - 2); diff --git a/Mage.Common/src/mage/view/TableView.java b/Mage.Common/src/mage/view/TableView.java index 86a814a2b3..5ba39a3ed4 100644 --- a/Mage.Common/src/mage/view/TableView.java +++ b/Mage.Common/src/mage/view/TableView.java @@ -99,6 +99,9 @@ public class TableView implements Serializable { sbScore.insert(0,matchPlayer.getWins()).insert(0,"Score: "); } } + if (table.getMatch().getDraws() > 0) { + sbScore.append(" Draws: ").append(table.getMatch().getDraws()); + } this.controllerName += sb.toString(); this.deckType = table.getDeckType(); if (table.getMatch().getGames().isEmpty()) { diff --git a/Mage.Server.Plugins/Mage.Game.TwoPlayerDuel/src/mage/game/TwoPlayerDuel.java b/Mage.Server.Plugins/Mage.Game.TwoPlayerDuel/src/mage/game/TwoPlayerDuel.java index d71b96f003..5559663984 100644 --- a/Mage.Server.Plugins/Mage.Game.TwoPlayerDuel/src/mage/game/TwoPlayerDuel.java +++ b/Mage.Server.Plugins/Mage.Game.TwoPlayerDuel/src/mage/game/TwoPlayerDuel.java @@ -69,11 +69,6 @@ public class TwoPlayerDuel extends GameImpl { state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW)); } - @Override - public void quit(UUID playerId) { - super.quit(playerId); - } - @Override public Set getOpponents(UUID playerId) { Set opponents = new HashSet<>(); diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index ccf1fd076d..64beecf42a 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -238,7 +238,7 @@ public class MageServerImpl implements MageServer { public void execute() throws MageException { UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); TableManager.getInstance().updateDeck(userId, tableId, deckList); - logger.debug("Session " + sessionId + " updated deck"); + logger.trace("Session " + sessionId + " updated deck"); } }); } diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index d7d2256f42..497dcb7a8b 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -125,7 +125,6 @@ public interface Game extends MageItem, Serializable { boolean canPlaySorcery(UUID playerId); UUID getActivePlayerId(); UUID getPriorityPlayerId(); - void leave(UUID playerId); boolean gameOver(UUID playerId); boolean hasEnded(); Battlefield getBattlefield(); @@ -134,6 +133,7 @@ public interface Game extends MageItem, Serializable { Combat getCombat(); GameState getState(); String getWinner(); + boolean isADraw(); ContinuousEffects getContinuousEffects(); GameStates getGameStates(); void loadGameStates(GameStates states); diff --git a/Mage/src/mage/game/GameCommanderImpl.java b/Mage/src/mage/game/GameCommanderImpl.java index 1c04b0535a..c18d84dd3d 100644 --- a/Mage/src/mage/game/GameCommanderImpl.java +++ b/Mage/src/mage/game/GameCommanderImpl.java @@ -195,13 +195,6 @@ public abstract class GameCommanderImpl extends GameImpl { return super.checkStateBasedActions(); } - - - @Override - public void quit(UUID playerId) { - super.quit(playerId); - } - @Override public Set getOpponents(UUID playerId) { Set opponents = new HashSet<>(); @@ -217,10 +210,4 @@ public abstract class GameCommanderImpl extends GameImpl { public boolean isOpponent(Player player, UUID playerToCheck) { return !player.getId().equals(playerToCheck); } - - @Override - public void leave(UUID playerId) { - super.leave(playerId); - } - } diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 45341f6cf0..a98c99dffa 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -455,6 +455,7 @@ public abstract class GameImpl implements Game, Serializable { boolean result = checkIfGameIsOver(); return result; } else { + logger.debug("game.gameOver -> player leaves " + playerId ); leave(playerId); return true; } @@ -479,7 +480,7 @@ public abstract class GameImpl implements Game, Serializable { end(); for (Player player: state.getPlayers().values()) { if (!player.hasLeft() && !player.hasLost()) { - logger.debug(new StringBuilder("Player ").append(player.getName()).append(" won the game ").append(this.getId())); + logger.debug(new StringBuilder("game.checkIfGameIsOver ->Player ").append(player.getName()).append(" won the game ").append(this.getId())); player.won(this); } } @@ -494,6 +495,11 @@ public abstract class GameImpl implements Game, Serializable { return endTime != null; } + @Override + public boolean isADraw() { + return hasEnded() && winnerId == null; + } + @Override public String getWinner() { if (winnerId == null) { @@ -1843,14 +1849,16 @@ public abstract class GameImpl implements Game, Serializable { * @param playerId */ - @Override - public void leave(UUID playerId) { + protected void leave(UUID playerId) { + Player player = getPlayer(playerId); if (player == null || player.hasLeft()) { + logger.debug("game.leave -> player already left " + (player != null ? player.getName():playerId)); return; } + logger.debug("game.leave -> start player: " + player.getName()); player.leave(); - if (gameOver(null)) { + if (checkIfGameIsOver()) { // no need to remove objects if only one player is left so the game is over return; } diff --git a/Mage/src/mage/game/match/Match.java b/Mage/src/mage/game/match/Match.java index a9917638de..3c3eb44989 100644 --- a/Mage/src/mage/game/match/Match.java +++ b/Mage/src/mage/game/match/Match.java @@ -66,7 +66,10 @@ public interface Match { List getGames(); int getWinsNeeded(); int getFreeMulligans(); + void addDraw(); + int getDraws(); int getNumGames(); + void addGame(); boolean isDoneSideboarding(); UUID getChooser(); MatchOptions getOptions(); diff --git a/Mage/src/mage/game/match/MatchImpl.java b/Mage/src/mage/game/match/MatchImpl.java index b4caf5e9b8..3ec77c794f 100644 --- a/Mage/src/mage/game/match/MatchImpl.java +++ b/Mage/src/mage/game/match/MatchImpl.java @@ -60,12 +60,16 @@ public abstract class MatchImpl implements Match { protected Date startTime; protected Date endTime; + protected int draws; + protected int startedGames; + protected boolean replayAvailable; public MatchImpl(MatchOptions options) { this.options = options; startTime = new Date(); replayAvailable = false; + draws = 0; } @Override @@ -168,9 +172,14 @@ public abstract class MatchImpl implements Match { return games; } + @Override + public void addGame() { + startedGames++; + } + @Override public int getNumGames() { - return games.size(); + return startedGames; } @Override @@ -184,6 +193,7 @@ public abstract class MatchImpl implements Match { } protected void initGame(Game game) throws GameException { + addGame(); // raises only the number shufflePlayers(); for (MatchPlayer matchPlayer: this.players) { if (!matchPlayer.hasQuit()) { @@ -221,17 +231,14 @@ public abstract class MatchImpl implements Match { if (player.hasQuit()) { matchPlayer.setQuit(true); } - if (player.hasTimerTimeout()) { - matchPlayer.setTimerTimeout(true); - } if (player.hasWon()) { matchPlayer.addWin(); } - if (player.hasLost()) { - matchPlayer.addLose(); - } } } + if (game.isADraw()) { + addDraw(); + } checkIfMatchEnds(); game.fireGameEndInfo(); } @@ -312,15 +319,17 @@ public abstract class MatchImpl implements Match { StringBuilder sb = new StringBuilder(); sb.append("\nMatch score:\n"); for (MatchPlayer mp :this.getPlayers()) { - sb.append("- ").append(mp.getName()); - sb.append(" (").append(mp.getWins()).append(mp.getWins()==1?" win / ":" wins / "); - sb.append(mp.getLoses()).append(mp.getLoses()==1?" loss)":" losses)"); + sb.append(" ").append(mp.getName()); + sb.append(" - ").append(mp.getWins()).append(mp.getWins()==1?" win":" wins"); if (mp.hasQuit()) { sb.append(" QUITTED"); } sb.append("\n"); } - sb.append("\n").append(this.getWinsNeeded()).append(this.getWinsNeeded() == 1 ? " win":" wins").append(" needed to win the match\n"); + if (getDraws() > 0) { + sb.append(" Draws: ").append(getDraws()).append("\n"); + } + sb.append("\n").append("You have to win ").append(this.getWinsNeeded()).append(this.getWinsNeeded() == 1 ? " game":" games").append(" to win the complete match\n"); sb.append("\nGame has started\n"); return sb.toString(); } @@ -360,6 +369,17 @@ public abstract class MatchImpl implements Match { } } + @Override + public void addDraw() { + ++draws; + } + + @Override + public int getDraws() { + return draws; + } + + @Override public void cleanUp() { for (MatchPlayer matchPlayer: players) { diff --git a/Mage/src/mage/game/match/MatchPlayer.java b/Mage/src/mage/game/match/MatchPlayer.java index b9a5438227..3e91349f7b 100644 --- a/Mage/src/mage/game/match/MatchPlayer.java +++ b/Mage/src/mage/game/match/MatchPlayer.java @@ -38,7 +38,6 @@ import mage.players.Player; */ public class MatchPlayer { private int wins; - private int loses; private boolean matchWinner; private Deck deck; @@ -54,7 +53,6 @@ public class MatchPlayer { this.player = player; this.deck = deck; this.wins = 0; - this.loses = 0; this.doneSideboarding = true; this.quit = false; this.timerTimeout = false; @@ -78,14 +76,6 @@ public class MatchPlayer { this.wins++; } - public int getLoses() { - return loses; - } - - public void addLose() { - this.loses++; - } - public Deck getDeck() { return deck; } @@ -130,14 +120,6 @@ public class MatchPlayer { this.quit = quit; } - public boolean hasTimerTimeout() { - return timerTimeout; - } - - public void setTimerTimeout(boolean timerTimeout) { - this.timerTimeout = timerTimeout; - } - public boolean isMatchWinner() { return matchWinner; } diff --git a/Mage/src/mage/game/tournament/TournamentImpl.java b/Mage/src/mage/game/tournament/TournamentImpl.java index 80487c9f22..70ba37f9ad 100644 --- a/Mage/src/mage/game/tournament/TournamentImpl.java +++ b/Mage/src/mage/game/tournament/TournamentImpl.java @@ -301,15 +301,18 @@ public abstract class TournamentImpl implements Tournament { MatchPlayer mp2 = match.getPlayer(p2.getPlayer().getId()); StringBuilder matchResult = new StringBuilder(); matchResult.append(p2.getPlayer().getName()); - matchResult.append(" (").append(mp1.getWins()); + matchResult.append(" [").append(mp1.getWins()); if (mp1.hasQuit()) { - matchResult.append(mp1.hasTimerTimeout()?"T":"Q"); + matchResult.append(mp1.getPlayer().hasIdleTimeout()? "I" :(mp1.getPlayer().hasTimerTimeout()?"T":"Q")); + } + if (match.getDraws() > 0) { + matchResult.append(match.getDraws()).append("-"); } matchResult.append("-").append(mp2.getWins()); if (mp2.hasQuit()) { - matchResult.append(mp2.hasTimerTimeout()?"T":"Q"); + matchResult.append(mp2.getPlayer().hasIdleTimeout()? "I" :(mp2.getPlayer().hasTimerTimeout()?"T":"Q")); } - matchResult.append(") "); + matchResult.append("] "); return matchResult.toString(); } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 4cc5435acb..88d1ec071a 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -1537,8 +1537,11 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public void concede(Game game) { + log.debug("playerImpl.concede -> start " + this.getName()); game.gameOver(playerId); + log.debug("playerImpl.concede -> before lost " + this.getName()); lost(game); + log.debug("playerImpl.concede -> after lost " + this.getName()); this.left = true; } @@ -1583,16 +1586,21 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public void lost(Game game) { + log.debug("player lost -> start: " + this.getName()); if (canLose(game)) { this.loses = true; //20100423 - 603.9 if (!this.wins) { game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST, null, null, playerId)); game.informPlayers(new StringBuilder(this.getName()).append(" has lost the game.").toString()); + } else { + log.debug("player.lost -> stop setting lost because he already has won!: " + this.getName()); } - if (!hasLeft()) { - game.leave(playerId); - } + // for draw first all players that have lost have to be set to lost +// if (!hasLeft()) { +// log.debug("player.lost -> calling leave"); +// game.gameOver(playerId); +// } } } @@ -1603,6 +1611,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public void won(Game game) { + log.debug("player won -> start: " + this.getName()); if (!game.replaceEvent(new GameEvent(GameEvent.EventType.WINS, null, null, playerId))) { if (!this.loses) { //20130501 - 800.7, 801.16 @@ -1610,6 +1619,7 @@ public abstract class PlayerImpl implements Player, Serializable { for (UUID opponentId: game.getOpponents(playerId)) { Player opponent = game.getPlayer(opponentId); if (opponent != null && !opponent.hasLost()) { + log.debug("player won -> calling opponent lost: " + this.getName() + " opponent: " + opponent.getName()); opponent.lost(game); } } @@ -1622,10 +1632,13 @@ public abstract class PlayerImpl implements Player, Serializable { } } if (opponentsAlive == 0 && !hasWon()) { + log.debug("player won -> No more oppononets alive game won: " + this.getName()); game.informPlayers(new StringBuilder(this.getName()).append(" has won the game").toString()); this.wins = true; game.end(); } + } else { + log.debug("player won -> but already lost before: " + this.getName()); } } }