From 94109b5e2e8b28259fad8c464f3860ad266de668 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 23 Jul 2013 17:22:49 +0200 Subject: [PATCH] Fixed that won effect did not work if winning player was not first player in player list. --- Mage/src/mage/game/GameImpl.java | 14 +++++++++----- Mage/src/mage/players/PlayerImpl.java | 28 ++++++++++++++++----------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 670a9f265b..2de86fab79 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -439,7 +439,7 @@ public abstract class GameImpl> 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> 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> 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 diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 171a955f12..0973a9abf8 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -111,10 +111,10 @@ public abstract class PlayerImpl> 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> 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) { - for (UUID opponentId: game.getOpponents(playerId)) { - Player opponent = game.getPlayer(opponentId); - if (opponent != null && !opponent.hasLost()) { - opponent.lost(game); - } + //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; } - else { + // 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++; + } + } + if (opponentsAlive == 0) { this.wins = true; game.end(); }