Fix mulligan process (rule 103.4)

This commit is contained in:
Quercitron 2014-05-26 03:21:14 +04:00
parent 9267fbc763
commit b007242761

View file

@ -757,25 +757,44 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
} }
//20091005 - 103.4 //20091005 - 103.4
for (UUID playerId: state.getPlayerList(startingPlayerId)) { List<UUID> keepPlayers = new ArrayList<>();
Player player = getPlayer(playerId); List<UUID> mulliganPlayers = new ArrayList<>();
GameEvent event = new GameEvent(GameEvent.EventType.CAN_TAKE_MULLIGAN, null, null, playerId); do {
while (player.getHand().size() > 0) { mulliganPlayers.clear();
if (replaceEvent(event)) { for (UUID playerId : state.getPlayerList(startingPlayerId)) {
continue; 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); saveState(false);
} } while (!mulliganPlayers.isEmpty());
// add watchers
for (UUID playerId : state.getPlayerList(startingPlayerId)) { for (UUID playerId : state.getPlayerList(startingPlayerId)) {
state.getWatchers().add(new PlayerDamagedBySourceWatcher(playerId)); state.getWatchers().add(new PlayerDamagedBySourceWatcher(playerId));
} }