diff --git a/src/java/com/threerings/parlor/game/data/GameObject.java b/src/java/com/threerings/parlor/game/data/GameObject.java index 639b9c3b7..66e6ad5d7 100644 --- a/src/java/com/threerings/parlor/game/data/GameObject.java +++ b/src/java/com/threerings/parlor/game/data/GameObject.java @@ -60,6 +60,9 @@ public class GameObject extends PlaceObject /** The field name of the creator field. */ public static final String CREATOR = "creator"; + + /** The field name of the playerStatus field. */ + public static final String PLAYER_STATUS = "playerStatus"; // AUTO-GENERATED: FIELDS END /** A game state constant indicating that the game has not yet started @@ -75,6 +78,14 @@ public class GameObject extends PlaceObject /** A game state constant indicating that the game was cancelled. */ public static final int CANCELLED = 3; + /** The player status constant for a player whose game is in play. */ + public static final int PLAYER_IN_PLAY = 0; + + /** The player status constant for a player whose has been knocked out + * of the game. NOTE: This can include a player choosing to leave a + * game prematurely. */ + public static final int PLAYER_LEFT_GAME = 1; + /** Provides general game invocation services. */ public GameMarshaller gameService; @@ -98,6 +109,11 @@ public class GameObject extends PlaceObject /** The player index of the creating player if this is a party game. */ public int creator; + /** The status of each of the players in the game. The status value + * is one of {@link #PLAYER_LEFT_GAME} or {@link + * #PLAYER_IN_PLAY}. */ + public int[] playerStatus; + /** * Returns the number of players in the game. */ @@ -113,6 +129,32 @@ public class GameObject extends PlaceObject return count; } + /** + * Returns the number of active players in the game. + */ + public int getActivePlayerCount () + { + int count = 0; + int size = players.length; + for (int ii = 0; ii < size; ii++) { + if (isActivePlayer(ii)) { + count++; + } + } + return count; + } + + /** + * Returns whether the given player is still an active player in + * the game. (Ie. whether or not they are still participating.) + */ + public boolean isActivePlayer (int pidx) + { + return (isOccupiedPlayer(pidx) && + playerStatus != null && playerStatus[pidx] == PLAYER_IN_PLAY); + } + + /** * Returns the player index of the given user in the game, or * -1 if the player is not involved in the game. @@ -349,5 +391,38 @@ public class GameObject extends PlaceObject CREATOR, new Integer(value), new Integer(ovalue)); this.creator = value; } + + /** + * Requests that the playerStatus field be set to the + * specified value. The local value will be updated immediately and an + * event will be propagated through the system to notify all listeners + * that the attribute did change. Proxied copies of this object (on + * clients) will apply the value change when they received the + * attribute changed notification. + */ + public void setPlayerStatus (int[] value) + { + int[] ovalue = this.playerStatus; + requestAttributeChange( + PLAYER_STATUS, value, ovalue); + this.playerStatus = (value == null) ? null : (int[])value.clone(); + } + + /** + * Requests that the indexth element of + * playerStatus field be set to the specified value. + * The local value will be updated immediately and an event will be + * propagated through the system to notify all listeners that the + * attribute did change. Proxied copies of this object (on clients) + * will apply the value change when they received the attribute + * changed notification. + */ + public void setPlayerStatusAt (int value, int index) + { + int ovalue = this.playerStatus[index]; + requestElementUpdate( + PLAYER_STATUS, index, new Integer(value), new Integer(ovalue)); + this.playerStatus[index] = value; + } // AUTO-GENERATED: METHODS END } diff --git a/src/java/com/threerings/puzzle/client/PuzzleController.java b/src/java/com/threerings/puzzle/client/PuzzleController.java index c941d6ac8..4249c09db 100644 --- a/src/java/com/threerings/puzzle/client/PuzzleController.java +++ b/src/java/com/threerings/puzzle/client/PuzzleController.java @@ -49,6 +49,7 @@ import com.threerings.crowd.client.PlaceControllerDelegate; import com.threerings.crowd.data.PlaceObject; import com.threerings.parlor.game.client.GameController; +import com.threerings.parlor.game.data.GameObject; import com.threerings.puzzle.Log; import com.threerings.puzzle.data.Board; @@ -879,7 +880,7 @@ public abstract class PuzzleController extends GameController public void elementUpdated (ElementUpdatedEvent event) { String name = event.getName(); if (name.equals(PuzzleObject.PLAYER_STATUS)) { - if (event.getIntValue() == PuzzleObject.PLAYER_KNOCKED_OUT) { + if (event.getIntValue() == GameObject.PLAYER_LEFT_GAME) { playerKnockedOut(event.getIndex()); } } diff --git a/src/java/com/threerings/puzzle/data/PuzzleObject.java b/src/java/com/threerings/puzzle/data/PuzzleObject.java index 8288aaa6a..0af07365a 100644 --- a/src/java/com/threerings/puzzle/data/PuzzleObject.java +++ b/src/java/com/threerings/puzzle/data/PuzzleObject.java @@ -39,9 +39,6 @@ public class PuzzleObject extends GameObject /** The field name of the difficulty field. */ public static final String DIFFICULTY = "difficulty"; - /** The field name of the playerStatus field. */ - public static final String PLAYER_STATUS = "playerStatus"; - /** The field name of the summaries field. */ public static final String SUMMARIES = "summaries"; @@ -49,24 +46,12 @@ public class PuzzleObject extends GameObject public static final String SEED = "seed"; // AUTO-GENERATED: FIELDS END - /** The player status constant for a player whose game is in play. */ - public static final int PLAYER_IN_PLAY = 0; - - /** The player status constant for a player whose has been knocked out - * of the game. */ - public static final int PLAYER_KNOCKED_OUT = 1; - /** Provides general puzzle game invocation services. */ public PuzzleGameMarshaller puzzleGameService; /** The puzzle difficulty level. */ public int difficulty; - /** The status of each of the players in the game. The status value - * is one of {@link #PLAYER_KNOCKED_OUT} or {@link - * #PLAYER_IN_PLAY}. */ - public int[] playerStatus; - /** Summaries of the boards of all players in this puzzle (may be null * if the puzzle doesn't support individual player boards). */ public BoardSummary[] summaries; @@ -74,31 +59,6 @@ public class PuzzleObject extends GameObject /** The seed used to germinate the boards. */ public long seed; - /** - * Returns the number of active players in the game. - */ - public int getActivePlayerCount () - { - int count = 0; - int size = players.length; - for (int ii = 0; ii < size; ii++) { - if (isActivePlayer(ii)) { - count++; - } - } - return count; - } - - /** - * Returns whether the given player is still an active player, e.g., - * their game has not ended. - */ - public boolean isActivePlayer (int pidx) - { - return (isOccupiedPlayer(pidx) && - playerStatus != null && playerStatus[pidx] == PLAYER_IN_PLAY); - } - // AUTO-GENERATED: METHODS START /** * Requests that the puzzleGameService field be set to the @@ -132,39 +92,6 @@ public class PuzzleObject extends GameObject this.difficulty = value; } - /** - * Requests that the playerStatus field be set to the - * specified value. The local value will be updated immediately and an - * event will be propagated through the system to notify all listeners - * that the attribute did change. Proxied copies of this object (on - * clients) will apply the value change when they received the - * attribute changed notification. - */ - public void setPlayerStatus (int[] value) - { - int[] ovalue = this.playerStatus; - requestAttributeChange( - PLAYER_STATUS, value, ovalue); - this.playerStatus = (value == null) ? null : (int[])value.clone(); - } - - /** - * Requests that the indexth element of - * playerStatus field be set to the specified value. - * The local value will be updated immediately and an event will be - * propagated through the system to notify all listeners that the - * attribute did change. Proxied copies of this object (on clients) - * will apply the value change when they received the attribute - * changed notification. - */ - public void setPlayerStatusAt (int value, int index) - { - int ovalue = this.playerStatus[index]; - requestElementUpdate( - PLAYER_STATUS, index, new Integer(value), new Integer(ovalue)); - this.playerStatus[index] = value; - } - /** * Requests that the summaries field be set to the * specified value. The local value will be updated immediately and an diff --git a/src/java/com/threerings/puzzle/server/PuzzleManager.java b/src/java/com/threerings/puzzle/server/PuzzleManager.java index 21710a048..60003d846 100644 --- a/src/java/com/threerings/puzzle/server/PuzzleManager.java +++ b/src/java/com/threerings/puzzle/server/PuzzleManager.java @@ -34,6 +34,7 @@ import com.threerings.presents.dobj.OidList; import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.server.CrowdServer; +import com.threerings.parlor.game.data.GameObject; import com.threerings.parlor.game.server.GameManager; import com.threerings.util.MessageBundle; @@ -127,7 +128,7 @@ public abstract class PuzzleManager extends GameManager _puzobj.startTransaction(); try { // end the player's game - _puzobj.setPlayerStatusAt(PuzzleObject.PLAYER_KNOCKED_OUT, pidx); + _puzobj.setPlayerStatusAt(GameObject.PLAYER_LEFT_GAME, pidx); // let derived classes do some business playerGameDidEnd(pidx);