From afc6a5aadcf763cc98acf6f53f5127ede24b409f Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 15 Sep 2015 12:41:07 +0200 Subject: [PATCH] * Fixed that if in a multiplayer game the player that selects the starting player concedes before he selects a starting player, a starting player is slected by the game. The game starts now correctly with all remaining players. --- .../common/LookLibraryControllerEffect.java | 4 +- Mage/src/mage/game/GameImpl.java | 64 ++++++++++++++----- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/Mage/src/mage/abilities/effects/common/LookLibraryControllerEffect.java b/Mage/src/mage/abilities/effects/common/LookLibraryControllerEffect.java index c32ff30e18..087323a12c 100644 --- a/Mage/src/mage/abilities/effects/common/LookLibraryControllerEffect.java +++ b/Mage/src/mage/abilities/effects/common/LookLibraryControllerEffect.java @@ -108,12 +108,12 @@ public class LookLibraryControllerEffect extends OneShotEffect { if (source instanceof SpellAbility) { Card sourceCard = game.getCard(source.getSourceId()); if (sourceCard != null) { - windowName = sourceCard.getName(); + windowName = sourceCard.getIdName(); } } else { Permanent sourcePermanent = game.getPermanent(source.getSourceId()); if (sourcePermanent != null) { - windowName = sourcePermanent.getName(); + windowName = sourcePermanent.getIdName(); } } diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index f1d6cf8b25..a4b11aa88b 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -851,28 +851,53 @@ public abstract class GameImpl implements Game, Serializable { Player choosingPlayer = null; if (choosingPlayerId != null) { choosingPlayer = this.getPlayer(choosingPlayerId); + if (choosingPlayer != null && !choosingPlayer.isInGame()) { + choosingPlayer = null; + } } if (choosingPlayer == null) { choosingPlayerId = pickChoosingPlayer(); + if (choosingPlayerId == null) { + return; + } choosingPlayer = getPlayer(choosingPlayerId); } + if (choosingPlayer == null) { + return; + } getState().setChoosingPlayerId(choosingPlayerId); // needed to start/stop the timer if active if (choosingPlayer != null && choosingPlayer.choose(Outcome.Benefit, targetPlayer, null, this)) { startingPlayerId = targetPlayer.getTargets().get(0); - Player startingPlayer = state.getPlayer(startingPlayerId); - StringBuilder message = new StringBuilder(choosingPlayer.getLogName()).append(" chooses that "); - if (choosingPlayer.getId().equals(startingPlayerId)) { - message.append("he or she"); - } else { - message.append(startingPlayer.getLogName()); - } - message.append(" takes the first turn"); - - this.informPlayers(message.toString()); - } else { - // not possible to choose starting player, stop here + } else if (getState().getPlayers().size() < 3) { + // not possible to choose starting player, choosing player has probably conceded, so stop here return; } + if (startingPlayerId == null) { + // choose any available player as starting player + for (Player player : state.getPlayers().values()) { + if (player.isInGame()) { + startingPlayerId = player.getId(); + break; + } + } + if (startingPlayerId == null) { + return; + } + } + Player startingPlayer = state.getPlayer(startingPlayerId); + if (startingPlayer == null) { + logger.debug("Starting player not found. playerId:" + startingPlayerId); + return; + } + StringBuilder message = new StringBuilder(choosingPlayer.getLogName()).append(" chooses that "); + if (choosingPlayer.getId().equals(startingPlayerId)) { + message.append("he or she"); + } else { + message.append(startingPlayer.getLogName()); + } + message.append(" takes the first turn"); + + this.informPlayers(message.toString()); //20091005 - 103.3 int startingHandSize = 7; @@ -980,6 +1005,7 @@ public abstract class GameImpl implements Game, Serializable { } } } + } protected UUID findWinnersAndLosers() { @@ -1014,9 +1040,17 @@ public abstract class GameImpl implements Game, Serializable { protected UUID pickChoosingPlayer() { UUID[] players = getPlayers().keySet().toArray(new UUID[0]); - UUID playerId = players[rnd.nextInt(players.length)]; - fireInformEvent(state.getPlayer(playerId).getLogName() + " won the toss"); - return playerId; + UUID playerId; + while (!hasEnded()) { + playerId = players[rnd.nextInt(players.length)]; + Player player = getPlayer(playerId); + if (player != null && player.isInGame()) { + fireInformEvent(state.getPlayer(playerId).getLogName() + " won the toss"); + return player.getId(); + } + } + logger.debug("Game was not possible to pick a choosing player. GameId:" + getId()); + return null; } @Override