* Fixed draw handling. Fixed concede handling. Fixed message generation for game end view. Added some debug messages.

This commit is contained in:
LevelX2 2014-06-25 01:34:11 +02:00
parent eb1e8dda14
commit 513b012dc0
13 changed files with 92 additions and 70 deletions

View file

@ -97,24 +97,24 @@ public class GameEndView implements Serializable {
if (matchPlayer.isMatchWinner()) { if (matchPlayer.isMatchWinner()) {
matchWinner = matchPlayer; matchWinner = matchPlayer;
} }
if (matchPlayer.hasTimerTimeout()) { if (matchPlayer.getPlayer().hasTimerTimeout()) {
if (matchPlayer.getPlayer().equals(you)) { if (matchPlayer.getPlayer().equals(you)) {
additonalText.append("You run out of time. "); additonalText.append("You run out of time. ");
} else { } else {
additonalText.append(matchPlayer.getName()).append(" runs out of time. "); 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()) { } else if (matchPlayer.getPlayer().hasIdleTimeout()) {
if (matchPlayer.getPlayer().equals(you)) { if (matchPlayer.getPlayer().equals(you)) {
additonalText.append("You lost the match for beeing idle. "); additonalText.append("You lost the match for beeing idle. ");
} else { } else {
additonalText.append(matchPlayer.getName()).append(" lost for beeing idle. "); 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. ");
}
} }
} }

View file

@ -67,6 +67,7 @@ public class MatchView implements Serializable {
this.matchName = match.getName(); this.matchName = match.getName();
this.gameType = match.getOptions().getGameType(); this.gameType = match.getOptions().getGameType();
this.deckType = match.getOptions().getDeckType(); this.deckType = match.getOptions().getDeckType();
for (Game game: match.getGames()) { for (Game game: match.getGames()) {
games.add(game.getId()); games.add(game.getId());
} }
@ -75,15 +76,22 @@ public class MatchView implements Serializable {
for (MatchPlayer matchPlayer: match.getPlayers()) { for (MatchPlayer matchPlayer: match.getPlayers()) {
sb1.append(matchPlayer.getName()); sb1.append(matchPlayer.getName());
if(matchPlayer.hasQuit()) { if(matchPlayer.hasQuit()) {
if (matchPlayer.hasTimerTimeout()) { if (matchPlayer.getPlayer().hasTimerTimeout()) {
sb1.append(" [timer] "); sb1.append(" [timer] ");
} else if (matchPlayer.getPlayer().hasIdleTimeout()) {
sb1.append(" [idle] ");
} else { } else {
sb1.append(" [quit] "); sb1.append(" [quit] ");
} }
} }
int lostGames = match.getNumGames() - (matchPlayer.getWins() + match.getDraws());
sb1.append(", "); sb1.append(", ");
sb2.append(matchPlayer.getName()).append(" "); sb2.append(matchPlayer.getName()).append(" [");
sb2.append(matchPlayer.getWins()).append("-").append(matchPlayer.getLoses()).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); players = sb1.substring(0, sb1.length() - 2);
result = sb2.substring(0, sb2.length() - 2); result = sb2.substring(0, sb2.length() - 2);

View file

@ -99,6 +99,9 @@ public class TableView implements Serializable {
sbScore.insert(0,matchPlayer.getWins()).insert(0,"Score: "); 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.controllerName += sb.toString();
this.deckType = table.getDeckType(); this.deckType = table.getDeckType();
if (table.getMatch().getGames().isEmpty()) { if (table.getMatch().getGames().isEmpty()) {

View file

@ -69,11 +69,6 @@ public class TwoPlayerDuel extends GameImpl {
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW)); state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
} }
@Override
public void quit(UUID playerId) {
super.quit(playerId);
}
@Override @Override
public Set<UUID> getOpponents(UUID playerId) { public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>(); Set<UUID> opponents = new HashSet<>();

View file

@ -238,7 +238,7 @@ public class MageServerImpl implements MageServer {
public void execute() throws MageException { public void execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().updateDeck(userId, tableId, deckList); TableManager.getInstance().updateDeck(userId, tableId, deckList);
logger.debug("Session " + sessionId + " updated deck"); logger.trace("Session " + sessionId + " updated deck");
} }
}); });
} }

View file

@ -125,7 +125,6 @@ public interface Game extends MageItem, Serializable {
boolean canPlaySorcery(UUID playerId); boolean canPlaySorcery(UUID playerId);
UUID getActivePlayerId(); UUID getActivePlayerId();
UUID getPriorityPlayerId(); UUID getPriorityPlayerId();
void leave(UUID playerId);
boolean gameOver(UUID playerId); boolean gameOver(UUID playerId);
boolean hasEnded(); boolean hasEnded();
Battlefield getBattlefield(); Battlefield getBattlefield();
@ -134,6 +133,7 @@ public interface Game extends MageItem, Serializable {
Combat getCombat(); Combat getCombat();
GameState getState(); GameState getState();
String getWinner(); String getWinner();
boolean isADraw();
ContinuousEffects getContinuousEffects(); ContinuousEffects getContinuousEffects();
GameStates getGameStates(); GameStates getGameStates();
void loadGameStates(GameStates states); void loadGameStates(GameStates states);

View file

@ -195,13 +195,6 @@ public abstract class GameCommanderImpl extends GameImpl {
return super.checkStateBasedActions(); return super.checkStateBasedActions();
} }
@Override
public void quit(UUID playerId) {
super.quit(playerId);
}
@Override @Override
public Set<UUID> getOpponents(UUID playerId) { public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>(); Set<UUID> opponents = new HashSet<>();
@ -217,10 +210,4 @@ public abstract class GameCommanderImpl extends GameImpl {
public boolean isOpponent(Player player, UUID playerToCheck) { public boolean isOpponent(Player player, UUID playerToCheck) {
return !player.getId().equals(playerToCheck); return !player.getId().equals(playerToCheck);
} }
@Override
public void leave(UUID playerId) {
super.leave(playerId);
}
} }

View file

@ -455,6 +455,7 @@ public abstract class GameImpl implements Game, Serializable {
boolean result = checkIfGameIsOver(); boolean result = checkIfGameIsOver();
return result; return result;
} else { } else {
logger.debug("game.gameOver -> player leaves " + playerId );
leave(playerId); leave(playerId);
return true; return true;
} }
@ -479,7 +480,7 @@ public abstract class GameImpl implements Game, Serializable {
end(); end();
for (Player player: state.getPlayers().values()) { for (Player player: state.getPlayers().values()) {
if (!player.hasLeft() && !player.hasLost()) { 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); player.won(this);
} }
} }
@ -494,6 +495,11 @@ public abstract class GameImpl implements Game, Serializable {
return endTime != null; return endTime != null;
} }
@Override
public boolean isADraw() {
return hasEnded() && winnerId == null;
}
@Override @Override
public String getWinner() { public String getWinner() {
if (winnerId == null) { if (winnerId == null) {
@ -1843,14 +1849,16 @@ public abstract class GameImpl implements Game, Serializable {
* @param playerId * @param playerId
*/ */
@Override protected void leave(UUID playerId) {
public void leave(UUID playerId) {
Player player = getPlayer(playerId); Player player = getPlayer(playerId);
if (player == null || player.hasLeft()) { if (player == null || player.hasLeft()) {
logger.debug("game.leave -> player already left " + (player != null ? player.getName():playerId));
return; return;
} }
logger.debug("game.leave -> start player: " + player.getName());
player.leave(); player.leave();
if (gameOver(null)) { if (checkIfGameIsOver()) {
// no need to remove objects if only one player is left so the game is over // no need to remove objects if only one player is left so the game is over
return; return;
} }

View file

@ -66,7 +66,10 @@ public interface Match {
List<Game> getGames(); List<Game> getGames();
int getWinsNeeded(); int getWinsNeeded();
int getFreeMulligans(); int getFreeMulligans();
void addDraw();
int getDraws();
int getNumGames(); int getNumGames();
void addGame();
boolean isDoneSideboarding(); boolean isDoneSideboarding();
UUID getChooser(); UUID getChooser();
MatchOptions getOptions(); MatchOptions getOptions();

View file

@ -60,12 +60,16 @@ public abstract class MatchImpl implements Match {
protected Date startTime; protected Date startTime;
protected Date endTime; protected Date endTime;
protected int draws;
protected int startedGames;
protected boolean replayAvailable; protected boolean replayAvailable;
public MatchImpl(MatchOptions options) { public MatchImpl(MatchOptions options) {
this.options = options; this.options = options;
startTime = new Date(); startTime = new Date();
replayAvailable = false; replayAvailable = false;
draws = 0;
} }
@Override @Override
@ -168,9 +172,14 @@ public abstract class MatchImpl implements Match {
return games; return games;
} }
@Override
public void addGame() {
startedGames++;
}
@Override @Override
public int getNumGames() { public int getNumGames() {
return games.size(); return startedGames;
} }
@Override @Override
@ -184,6 +193,7 @@ public abstract class MatchImpl implements Match {
} }
protected void initGame(Game game) throws GameException { protected void initGame(Game game) throws GameException {
addGame(); // raises only the number
shufflePlayers(); shufflePlayers();
for (MatchPlayer matchPlayer: this.players) { for (MatchPlayer matchPlayer: this.players) {
if (!matchPlayer.hasQuit()) { if (!matchPlayer.hasQuit()) {
@ -221,16 +231,13 @@ public abstract class MatchImpl implements Match {
if (player.hasQuit()) { if (player.hasQuit()) {
matchPlayer.setQuit(true); matchPlayer.setQuit(true);
} }
if (player.hasTimerTimeout()) {
matchPlayer.setTimerTimeout(true);
}
if (player.hasWon()) { if (player.hasWon()) {
matchPlayer.addWin(); matchPlayer.addWin();
} }
if (player.hasLost()) {
matchPlayer.addLose();
} }
} }
if (game.isADraw()) {
addDraw();
} }
checkIfMatchEnds(); checkIfMatchEnds();
game.fireGameEndInfo(); game.fireGameEndInfo();
@ -312,15 +319,17 @@ public abstract class MatchImpl implements Match {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("\nMatch score:\n"); sb.append("\nMatch score:\n");
for (MatchPlayer mp :this.getPlayers()) { for (MatchPlayer mp :this.getPlayers()) {
sb.append("- ").append(mp.getName()); sb.append(" ").append(mp.getName());
sb.append(" (").append(mp.getWins()).append(mp.getWins()==1?" win / ":" wins / "); sb.append(" - ").append(mp.getWins()).append(mp.getWins()==1?" win":" wins");
sb.append(mp.getLoses()).append(mp.getLoses()==1?" loss)":" losses)");
if (mp.hasQuit()) { if (mp.hasQuit()) {
sb.append(" QUITTED"); sb.append(" QUITTED");
} }
sb.append("\n"); 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"); sb.append("\nGame has started\n");
return sb.toString(); 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 @Override
public void cleanUp() { public void cleanUp() {
for (MatchPlayer matchPlayer: players) { for (MatchPlayer matchPlayer: players) {

View file

@ -38,7 +38,6 @@ import mage.players.Player;
*/ */
public class MatchPlayer { public class MatchPlayer {
private int wins; private int wins;
private int loses;
private boolean matchWinner; private boolean matchWinner;
private Deck deck; private Deck deck;
@ -54,7 +53,6 @@ public class MatchPlayer {
this.player = player; this.player = player;
this.deck = deck; this.deck = deck;
this.wins = 0; this.wins = 0;
this.loses = 0;
this.doneSideboarding = true; this.doneSideboarding = true;
this.quit = false; this.quit = false;
this.timerTimeout = false; this.timerTimeout = false;
@ -78,14 +76,6 @@ public class MatchPlayer {
this.wins++; this.wins++;
} }
public int getLoses() {
return loses;
}
public void addLose() {
this.loses++;
}
public Deck getDeck() { public Deck getDeck() {
return deck; return deck;
} }
@ -130,14 +120,6 @@ public class MatchPlayer {
this.quit = quit; this.quit = quit;
} }
public boolean hasTimerTimeout() {
return timerTimeout;
}
public void setTimerTimeout(boolean timerTimeout) {
this.timerTimeout = timerTimeout;
}
public boolean isMatchWinner() { public boolean isMatchWinner() {
return matchWinner; return matchWinner;
} }

View file

@ -301,15 +301,18 @@ public abstract class TournamentImpl implements Tournament {
MatchPlayer mp2 = match.getPlayer(p2.getPlayer().getId()); MatchPlayer mp2 = match.getPlayer(p2.getPlayer().getId());
StringBuilder matchResult = new StringBuilder(); StringBuilder matchResult = new StringBuilder();
matchResult.append(p2.getPlayer().getName()); matchResult.append(p2.getPlayer().getName());
matchResult.append(" (").append(mp1.getWins()); matchResult.append(" [").append(mp1.getWins());
if (mp1.hasQuit()) { 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()); matchResult.append("-").append(mp2.getWins());
if (mp2.hasQuit()) { 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(); return matchResult.toString();
} }

View file

@ -1537,8 +1537,11 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override @Override
public void concede(Game game) { public void concede(Game game) {
log.debug("playerImpl.concede -> start " + this.getName());
game.gameOver(playerId); game.gameOver(playerId);
log.debug("playerImpl.concede -> before lost " + this.getName());
lost(game); lost(game);
log.debug("playerImpl.concede -> after lost " + this.getName());
this.left = true; this.left = true;
} }
@ -1583,16 +1586,21 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override @Override
public void lost(Game game) { public void lost(Game game) {
log.debug("player lost -> start: " + this.getName());
if (canLose(game)) { if (canLose(game)) {
this.loses = true; this.loses = true;
//20100423 - 603.9 //20100423 - 603.9
if (!this.wins) { if (!this.wins) {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST, null, null, playerId)); game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST, null, null, playerId));
game.informPlayers(new StringBuilder(this.getName()).append(" has lost the game.").toString()); 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()) { // for draw first all players that have lost have to be set to lost
game.leave(playerId); // if (!hasLeft()) {
} // log.debug("player.lost -> calling leave");
// game.gameOver(playerId);
// }
} }
} }
@ -1603,6 +1611,7 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override @Override
public void won(Game game) { public void won(Game game) {
log.debug("player won -> start: " + this.getName());
if (!game.replaceEvent(new GameEvent(GameEvent.EventType.WINS, null, null, playerId))) { if (!game.replaceEvent(new GameEvent(GameEvent.EventType.WINS, null, null, playerId))) {
if (!this.loses) { if (!this.loses) {
//20130501 - 800.7, 801.16 //20130501 - 800.7, 801.16
@ -1610,6 +1619,7 @@ public abstract class PlayerImpl implements Player, Serializable {
for (UUID opponentId: game.getOpponents(playerId)) { for (UUID opponentId: game.getOpponents(playerId)) {
Player opponent = game.getPlayer(opponentId); Player opponent = game.getPlayer(opponentId);
if (opponent != null && !opponent.hasLost()) { if (opponent != null && !opponent.hasLost()) {
log.debug("player won -> calling opponent lost: " + this.getName() + " opponent: " + opponent.getName());
opponent.lost(game); opponent.lost(game);
} }
} }
@ -1622,10 +1632,13 @@ public abstract class PlayerImpl implements Player, Serializable {
} }
} }
if (opponentsAlive == 0 && !hasWon()) { 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()); game.informPlayers(new StringBuilder(this.getName()).append(" has won the game").toString());
this.wins = true; this.wins = true;
game.end(); game.end();
} }
} else {
log.debug("player won -> but already lost before: " + this.getName());
} }
} }
} }