mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
* Fixed a bug that sometimes a conceding player could be set as the winner of the game.
This commit is contained in:
parent
5a2b445e43
commit
663c31cec6
2 changed files with 9 additions and 9 deletions
|
|
@ -436,7 +436,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isGameOver() {
|
public synchronized boolean isGameOver() {
|
||||||
if (state.isGameOver()) {
|
if (state.isGameOver()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -451,13 +451,13 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (remainingPlayers <= 1 || numLosers >= state.getPlayers().size() - 1) {
|
if (remainingPlayers <= 1 || numLosers >= state.getPlayers().size() - 1) {
|
||||||
|
end();
|
||||||
for (Player player: state.getPlayers().values()) {
|
for (Player player: state.getPlayers().values()) {
|
||||||
if (!player.hasLeft() && !player.hasLost()) {
|
if (!player.hasLeft() && !player.hasLost()) {
|
||||||
logger.info(new StringBuilder("Player ").append(player.getName()).append(" won the game ").append(this.getId()));
|
logger.debug(new StringBuilder("Player ").append(player.getName()).append(" won the game ").append(this.getId()));
|
||||||
player.won(this);
|
player.won(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end();
|
|
||||||
endTime = new Date();
|
endTime = new Date();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -559,8 +559,6 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
boolean wasPaused = state.isPaused();
|
boolean wasPaused = state.isPaused();
|
||||||
state.resume();
|
state.resume();
|
||||||
if (!isGameOver()) {
|
if (!isGameOver()) {
|
||||||
// if (simulation)
|
|
||||||
// logger.info("Turn " + Integer.toString(state.getTurnNum()));
|
|
||||||
fireInformEvent("Turn " + Integer.toString(state.getTurnNum()));
|
fireInformEvent("Turn " + Integer.toString(state.getTurnNum()));
|
||||||
if (checkStopOnTurnOption()) {
|
if (checkStopOnTurnOption()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -599,6 +597,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
}
|
}
|
||||||
if (isGameOver()) {
|
if (isGameOver()) {
|
||||||
winnerId = findWinnersAndLosers();
|
winnerId = findWinnersAndLosers();
|
||||||
|
logger.info(new StringBuilder("Game with gameId ").append(this.getId()).append(" ended."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -878,7 +877,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
public synchronized void concede(UUID playerId) {
|
public synchronized void concede(UUID playerId) {
|
||||||
Player player = state.getPlayer(playerId);
|
Player player = state.getPlayer(playerId);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
logger.info(new StringBuilder("Player ").append(player.getName()).append(" concedes game ").append(this.getId()));
|
logger.debug(new StringBuilder("Player ").append(player.getName()).append(" concedes game ").append(this.getId()));
|
||||||
player.concede(this);
|
player.concede(this);
|
||||||
fireInformEvent(player.getName() + " has conceded.");
|
fireInformEvent(player.getName() + " has conceded.");
|
||||||
}
|
}
|
||||||
|
|
@ -1707,7 +1706,6 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
if (player.hasLeft()) {
|
if (player.hasLeft()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.info(new StringBuilder("Player ").append(player.getName()).append(" left game ").append(this.getId()));
|
|
||||||
player.leave();
|
player.leave();
|
||||||
if (this.isGameOver()) {
|
if (this.isGameOver()) {
|
||||||
// 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
|
||||||
|
|
|
||||||
|
|
@ -714,9 +714,11 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
||||||
resetStoredBookmark(game);
|
resetStoredBookmark(game);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!game.isGameOver()) { // if player left or game is over no undo is possible - this could lead to wrong winner
|
||||||
game.restoreState(bookmark);
|
game.restoreState(bookmark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue