mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
* 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.
This commit is contained in:
parent
e36a2819f5
commit
afc6a5aadc
2 changed files with 51 additions and 17 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue