From b00724276156eb008857007dc364be92c2315c86 Mon Sep 17 00:00:00 2001 From: Quercitron Date: Mon, 26 May 2014 03:21:14 +0400 Subject: [PATCH] Fix mulligan process (rule 103.4) --- Mage/src/mage/game/GameImpl.java | 49 ++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 8d3d70cc0f..5d6b230bb1 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -757,25 +757,44 @@ public abstract class GameImpl> implements Game, Serializa } //20091005 - 103.4 - for (UUID playerId: state.getPlayerList(startingPlayerId)) { - Player player = getPlayer(playerId); - GameEvent event = new GameEvent(GameEvent.EventType.CAN_TAKE_MULLIGAN, null, null, playerId); - while (player.getHand().size() > 0) { - if (replaceEvent(event)) { - continue; + List keepPlayers = new ArrayList<>(); + List mulliganPlayers = new ArrayList<>(); + do { + mulliganPlayers.clear(); + for (UUID playerId : state.getPlayerList(startingPlayerId)) { + if (!keepPlayers.contains(playerId)) { + Player player = getPlayer(playerId); + boolean keep = true; + while (true) { + if (player.getHand().isEmpty()) { + break; + } + GameEvent event = new GameEvent(GameEvent.EventType.CAN_TAKE_MULLIGAN, null, null, playerId); + if (!replaceEvent(event)) { + fireEvent(event); + if (player.chooseMulligan(this)) { + keep = false; + } + break; + } + } + if (keep) { + endMulligan(player.getId()); + keepPlayers.add(playerId); + fireInformEvent(player.getName() + " keeps hand"); + } else { + mulliganPlayers.add(playerId); + fireInformEvent(player.getName() + " decides to take mulligan"); + } } - fireEvent(event); - if (!player.chooseMulligan(this)) { - endMulligan(player.getId()); - break; - } - - mulligan(player.getId()); } - fireInformEvent(player.getName() + " keeps hand"); + for (UUID mulliganPlayerId : mulliganPlayers) { + mulligan(mulliganPlayerId); + } saveState(false); - } + } while (!mulliganPlayers.isEmpty()); + // add watchers for (UUID playerId : state.getPlayerList(startingPlayerId)) { state.getWatchers().add(new PlayerDamagedBySourceWatcher(playerId)); }