mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
Fixed that won effect did not work if winning player was not first player in player list.
This commit is contained in:
parent
a0c3f32b9b
commit
94109b5e2e
2 changed files with 26 additions and 16 deletions
|
@ -439,7 +439,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
if (winnerId == null) {
|
||||
return "Game is a draw";
|
||||
}
|
||||
return "Player " + state.getPlayer(winnerId).getName() + " is the winner";
|
||||
return new StringBuilder("Player ").append(state.getPlayer(winnerId).getName()).append(" is the winner").toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -708,14 +708,18 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
protected UUID findWinnersAndLosers() {
|
||||
UUID winner = null;
|
||||
for (Player player: state.getPlayers().values()) {
|
||||
if (player.hasWon() || (!player.hasLost() && !player.hasLeft())) {
|
||||
if (player.hasWon()) {
|
||||
winner = player.getId();
|
||||
break;
|
||||
}
|
||||
if (!player.hasLost() && !player.hasLeft()) {
|
||||
player.won(this);
|
||||
winner = player.getId();
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (Player player: state.getPlayers().values()) {
|
||||
if (winner != null && !player.getId().equals(winner)) {
|
||||
if (winner != null && !player.getId().equals(winner) && !player.hasLost()) {
|
||||
player.lost(this);
|
||||
}
|
||||
}
|
||||
|
@ -1937,12 +1941,12 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
|
||||
@Override
|
||||
public Date getStartTime() {
|
||||
return startTime;
|
||||
return new Date(startTime.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getEndTime() {
|
||||
return endTime;
|
||||
return new Date(endTime.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -111,10 +111,10 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
private static Random rnd = new Random();
|
||||
|
||||
/**
|
||||
* Means what exactly?
|
||||
* No more actions?
|
||||
* Used to cancel waiting requests send to the player
|
||||
*/
|
||||
protected boolean abort;
|
||||
|
||||
protected final UUID playerId;
|
||||
protected String name;
|
||||
protected boolean human;
|
||||
|
@ -1333,17 +1333,23 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
public void won(Game game) {
|
||||
if (!game.replaceEvent(new GameEvent(GameEvent.EventType.WINS, null, null, playerId))) {
|
||||
if (!this.loses) {
|
||||
//20100423 - 800.6, 801.16
|
||||
if (game.getPlayers().size() > 2) {
|
||||
//20130501 - 800.7, 801.16
|
||||
// all opponents in range loose the game
|
||||
for (UUID opponentId: game.getOpponents(playerId)) {
|
||||
Player opponent = game.getPlayer(opponentId);
|
||||
if (opponent != null && !opponent.hasLost()) {
|
||||
opponent.lost(game);
|
||||
}
|
||||
}
|
||||
this.wins = true;
|
||||
// if no more opponents alive, you win and the game ends
|
||||
int opponentsAlive = 0;
|
||||
for (UUID opponentId: game.getOpponents(playerId)) {
|
||||
Player opponent = game.getPlayer(opponentId);
|
||||
if (!opponent.hasLost()) {
|
||||
opponentsAlive++;
|
||||
}
|
||||
else {
|
||||
}
|
||||
if (opponentsAlive == 0) {
|
||||
this.wins = true;
|
||||
game.end();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue