diff --git a/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java b/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java index 010e8064..8d9bd57e 100644 --- a/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java +++ b/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java @@ -69,11 +69,12 @@ public class EZGameTurnDelegate extends TurnGameManagerDelegate return; } - } else if (_turnIdx == -1) { - // If it's nobody's turn, and the user does not specify a next-turn, randomize. - // We set turnIdx to the player we want - 1, so that when it gets inc'd it'll - // be right. - _turnIdx = RandomUtil.getInt(_turnGame.getPlayers().length) - 1; + } + + // Otherwise, if it's nobody's turn randomly pick a turn holder + if (_turnIdx == -1) { + assignTurnRandomly(); + return; } // otherwise, do the default behavior diff --git a/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java b/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java index 77b96a2d..920219f5 100644 --- a/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java +++ b/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java @@ -194,18 +194,7 @@ public class TurnGameManagerDelegate extends GameManagerDelegate */ protected void setFirstTurnHolder () { - int size = _turnGame.getPlayers().length; - if (size > 0) { - int firstPick = _turnIdx = RandomUtil.getInt(size); - while (!_tgmgr.isActivePlayer(_turnIdx)) { - _turnIdx = (_turnIdx + 1) % size; - if (_turnIdx == firstPick) { - Log.warning("No players eligible for first turn. Choking. " + - "[game=" + where() + "]."); - return; - } - } - } + assignTurnRandomly(); } /** @@ -237,6 +226,25 @@ public class TurnGameManagerDelegate extends GameManagerDelegate } while (!_tgmgr.isActivePlayer(_turnIdx)); } + /** + * Convenience function to randomly assign the turn. + */ + protected void assignTurnRandomly () + { + int size = _turnGame.getPlayers().length; + if (size > 0) { + int firstPick = _turnIdx = RandomUtil.getInt(size); + while (!_tgmgr.isActivePlayer(_turnIdx)) { + _turnIdx = (_turnIdx + 1) % size; + if (_turnIdx == firstPick) { + Log.warning("No players eligible for randomly-assigned turn. Choking. " + + "[game=" + where() + "]."); + return; + } + } + } + } + /** The game manager for which we are delegating. */ protected TurnGameManager _tgmgr;