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<>();
List<UUID> mulliganPlayers = new ArrayList<>();
do {
mulliganPlayers.clear();
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
if (!keepPlayers.contains(playerId)) {
Player player = getPlayer(playerId); Player player = getPlayer(playerId);
GameEvent event = new GameEvent(GameEvent.EventType.CAN_TAKE_MULLIGAN, null, null, playerId); boolean keep = true;
while (player.getHand().size() > 0) { while (true) {
if (replaceEvent(event)) { if (player.getHand().isEmpty()) {
continue;
}
fireEvent(event);
if (!player.chooseMulligan(this)) {
endMulligan(player.getId());
break; break;
} }
GameEvent event = new GameEvent(GameEvent.EventType.CAN_TAKE_MULLIGAN, null, null, playerId);
mulligan(player.getId()); 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"); fireInformEvent(player.getName() + " keeps hand");
saveState(false); } else {
mulliganPlayers.add(playerId);
fireInformEvent(player.getName() + " decides to take mulligan");
} }
}
}
for (UUID mulliganPlayerId : mulliganPlayers) {
mulligan(mulliganPlayerId);
}
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));
} }