mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
* Fixed draw handling. Fixed concede handling. Fixed message generation for game end view. Added some debug messages.
This commit is contained in:
parent
eb1e8dda14
commit
513b012dc0
13 changed files with 92 additions and 70 deletions
|
@ -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. ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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<UUID> getOpponents(UUID playerId) {
|
||||
Set<UUID> opponents = new HashSet<>();
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<UUID> getOpponents(UUID playerId) {
|
||||
Set<UUID> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,10 @@ public interface Match {
|
|||
List<Game> getGames();
|
||||
int getWinsNeeded();
|
||||
int getFreeMulligans();
|
||||
void addDraw();
|
||||
int getDraws();
|
||||
int getNumGames();
|
||||
void addGame();
|
||||
boolean isDoneSideboarding();
|
||||
UUID getChooser();
|
||||
MatchOptions getOptions();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue