Moved player status tracking and in/out of game status from puzzles to
games. Updated the PLAYER_KNOCKED_OUT variable name to prevent some namespace contention issues. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3386 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -60,6 +60,9 @@ public class GameObject extends PlaceObject
|
||||
|
||||
/** The field name of the <code>creator</code> field. */
|
||||
public static final String CREATOR = "creator";
|
||||
|
||||
/** The field name of the <code>playerStatus</code> 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
|
||||
* <code>-1</code> 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 <code>playerStatus</code> 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 <code>index</code>th element of
|
||||
* <code>playerStatus</code> 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
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +39,6 @@ public class PuzzleObject extends GameObject
|
||||
/** The field name of the <code>difficulty</code> field. */
|
||||
public static final String DIFFICULTY = "difficulty";
|
||||
|
||||
/** The field name of the <code>playerStatus</code> field. */
|
||||
public static final String PLAYER_STATUS = "playerStatus";
|
||||
|
||||
/** The field name of the <code>summaries</code> 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 <code>puzzleGameService</code> field be set to the
|
||||
@@ -132,39 +92,6 @@ public class PuzzleObject extends GameObject
|
||||
this.difficulty = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>playerStatus</code> 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 <code>index</code>th element of
|
||||
* <code>playerStatus</code> 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 <code>summaries</code> field be set to the
|
||||
* specified value. The local value will be updated immediately and an
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user