|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.crowd.server.PlaceManager
com.threerings.parlor.game.server.GameManager
public class GameManager
The game manager handles the server side management of a game. It manipulates the game state in accordance with the logic of the game flow and generally manages the whole game playing process.
The game manager extends the place manager because games are implicitly played in a location, the players of the game implicitly bodies in that location.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class com.threerings.crowd.server.PlaceManager |
|---|
PlaceManager.DelegateOp, PlaceManager.MessageHandler |
| Field Summary | |
|---|---|
protected GameAI[] |
_AIs
If AIs are present, contains their configuration, or null at human player indexes. |
protected Interval |
_aiTicker
The interval for the AI tick. |
protected int |
_committedState
The state of the game that has been propagated to our subscribers. |
protected GameConfig |
_gameconfig
A reference to our game config. |
protected RepeatCallTracker |
_gameEndTracker
TEMP: debugging the pending rating double release bug. |
protected GameObject |
_gameobj
A reference to our game object. |
protected Interval |
_noShowInterval
The interval used to check for no-shows. |
protected ArrayIntSet |
_pendingOids
The list of players that have arrived in the room, but are not ready to play. |
protected int |
_playerCount
The number of players in the game. |
protected int[] |
_playerOids
The oids of our player and AI body objects. |
protected boolean |
_postponedStart
Whether we have already postponed the start of the game. |
protected List<Tuple<String,String>> |
_startmsgs
If non-null, contains bundles and messages that should be sent as system messages once the game has started. |
protected NamedAttributeListener |
_stateListener
Listens for game state changes. |
protected Interval |
_tickInterval
The interval for the game manager tick. |
protected static long |
AI_TICK_DELAY
The frequency with which we dispatch AI game ticks. |
protected static long |
DEFAULT_NOSHOW_DELAY
The default value returned by getNoShowTime(). |
protected static long |
TICK_DELAY
The delay in milliseconds between ticking of all game managers. |
| Fields inherited from class com.threerings.crowd.server.PlaceManager |
|---|
_bodyUpdater, _config, _deathListener, _delegates, _dispatcher, _dispatcherFinders, _injector, _invmgr, _locator, _marshallers, _msghandlers, _occInfo, _occListener, _omgr, _plobj, _registry, _shutdownInterval |
| Fields inherited from interface com.threerings.parlor.data.ParlorCodes |
|---|
ALREADY_AT_TABLE, BANNED_FROM_TABLE, GAME_ALREADY_STARTED, INVALID_TABLE_POSITION, INVITATION_ACCEPTED, INVITATION_COUNTERED, INVITATION_REFUSED, INVITEE_NOT_ONLINE, MUST_BE_CREATOR, NO_SELF_BOOT, NO_SUCH_TABLE, NOT_AT_TABLE, PARLOR_GROUP, TABLE_POSITION_OCCUPIED |
| Fields inherited from interface com.threerings.parlor.game.data.GameCodes |
|---|
GAME_CHAT_TYPE, GAME_MESSAGE_BUNDLE, PLAYER_KNOCKED_OUT, WINNERS_AND_LOSERS |
| Fields inherited from interface com.threerings.presents.data.InvocationCodes |
|---|
ACCESS_DENIED, E_ACCESS_DENIED, E_INTERNAL_ERROR, GLOBAL_GROUP, INTERNAL_ERROR |
| Constructor Summary | |
|---|---|
GameManager()
|
|
| Method Summary | |
|---|---|
int |
addPlayer(Name player)
Adds the given player to the game at the first available player index. |
boolean |
addPlayerAt(Name player,
int pidx)
Adds the given player to the game at the specified player index. |
boolean |
allPlayersReady()
Returns true if all (non-AI) players have delivered their playerReady(com.threerings.crowd.data.BodyObject)
notifications, false if they have not. |
protected void |
announcePlayerGameOver(int pidx)
Announce to everyone in the game that a player's game has ended. |
protected void |
assignWinners(boolean[] winners)
Assigns the final winning status for each player to their respect player index in the supplied array. |
protected void |
bodyLeft(int bodyOid)
|
boolean |
cancelGame()
Sets the state of the game to GameObject.CANCELLED. |
protected void |
checkForNoShows()
Called after the no-show delay has expired following the delivery of notifications to all players that the game is ready. |
protected void |
checkShutdownInterval()
|
BodyObject |
checkWritePermission(ClientObject client,
int playerId)
Make sure that the given caller is a player or an agent and can write to the data of the given playerId. |
protected void |
didInit()
|
protected void |
didShutdown()
|
protected void |
didStartup()
|
void |
endGame()
Called when the game is known to be over. |
void |
endPlayerGame(int pidx)
Ends the game for the given player. |
protected void |
gameDidEnd()
Called after the game has transitioned to the GameObject.GAME_OVER state. |
protected void |
gameDidStart()
Called after the game start notification was dispatched. |
protected void |
gameWasCancelled()
Called to let the manager know that the game was cancelled (and may be about to be shutdown if there's no one in the room). |
protected void |
gameWillEnd()
Called when the game is about to end, but before the game end notification has been delivered to the players. |
protected void |
gameWillReset()
Called when the game is about to reset, but before the board has been re-initialized or any other clearing out of game data has taken place. |
protected void |
gameWillStart()
Called when the game is about to start, but before the game start notification has been delivered to the players. |
GameConfig |
getGameConfig()
Returns the configuration object for the game being managed by this manager. |
int |
getGameId()
Returns the unique numeric identifier for our managed game. |
int |
getMatchType()
A convenience method for getting the game type. |
protected long |
getNoShowTime()
Returns the time after which we consider any player that has not yet reported into the game as a no-show and try to start the game anyway. |
BodyObject |
getPlayer(int playerIdx)
Returns the user object for the player with the specified index or null if the player at that index is not online. |
int |
getPlayerCount()
Returns the number of players in the game. |
Name |
getPlayerDisplayName(int index)
Returns the name that should be shown in the client for the player with the specified index or null if no player exists at that index. |
protected String |
getPlayerGameOverMessage(int pidx)
Gets the untranslated string to show when a player's game has ended. |
int |
getPlayerIndex(Name username)
Returns the player index of the given user in the game, or -1 if the player is
not involved in the game. |
Name |
getPlayerName(int index)
Returns the name of the player with the specified index or null if no player exists at that index. |
int |
getPlayerOid(int index)
Returns the user object oid of the player with the specified index. |
int |
getPlayerPersistentId(BodyObject body)
Convenience for getting the persistent id from a body. |
int |
getPlayerPersistentId(Name name)
Returns the persistent user id for the supplied player name. |
int |
getPlayerSlots()
Returns the number of players allowed in this game. |
int |
getPresentPlayerIndex(int bodyOid)
Get the player index of the specified oid, or -1 if the oid is not a player or is a player that is not presently in the game. |
int |
getSessionId()
Returns the unique session identifier for this game session. |
protected void |
handlePartialNoShow()
This is called when some, but not all, players failed to show up for a game. |
boolean |
isActivePlayer(int pidx)
Returns whether the player at the specified player index is actively playing the game |
boolean |
isAgent(ClientObject client)
Return true if the given client is a server-side agent in this place. |
boolean |
isAI(int pidx)
Returns whether the player at the specified player index is an AI. |
boolean |
isPlayer(ClientObject client)
Return true if the given client is a player in this place. |
protected boolean |
needsAITick()
Derived classes that need their AIs to be ticked periodically should override this method and return true. |
protected boolean |
needsNoShowTimer()
Returns true if this game requires a no-show timer. |
void |
occupantInRoom(BodyObject caller)
Called by the client when an occupant has arrived in the game room and has loaded their bits. |
protected void |
placeBecameEmpty()
When a game room becomes empty, we cancel the game if it's still in progress and close down the game room. |
protected void |
playerGameDidEnd(int pidx)
Called when a player has been marked as knocked out but before the knock-out status update has been sent to the players. |
boolean |
playerIsReady(int pidx)
Returns true if the player at the specified slot is ready (or if there is meant to be no player in that slot), false if there is meant to be a player in the specified slot and they have not yet reported that they are ready. |
void |
playerReady(BodyObject caller)
Called by the client when the player is ready for the game to start. |
protected void |
playersAllHere()
Called when all players have arrived in the game room. |
protected void |
playerWasAdded(Name player,
int pidx)
Called when a player was added to the game. |
protected void |
playerWasRemoved(Name player,
int pidx)
Called when a player was removed from the game. |
protected void |
playerWasReplaced(int pidx,
Name oldPlayer,
Name newPlayer)
Called when a player has been replaced via a call to replacePlayer(int, com.threerings.util.Name). |
boolean |
removePlayer(Name player)
Removes the given player from the game. |
void |
replacePlayer(int pidx,
Name player)
Replaces the player at the specified index and calls playerWasReplaced(int, com.threerings.util.Name, com.threerings.util.Name) to let
derived classes and delegates know what's going on. |
protected void |
reportPlayerKnockedOut(int pidx)
Report to the knocked-out player's room that they were knocked out. |
protected void |
reportWinnersAndLosers()
Report winner and loser oids to each room that any of the winners/losers is in. |
void |
resetGame()
Called when the game is to be reset to its starting state in preparation for a new game without actually ending the current game. |
void |
setAI(int pidx,
GameAI ai)
Sets the specified player as an AI with the specified configuration. |
boolean |
shouldConcludeGame()
Returns whether game conclusion antics such as rating updates should be performed when an in-play game is ended. |
protected boolean |
shouldEndGame()
Called when a player leaves the game in order to determine whether the game should be ended based on its current state, which will include updated player status for the player in question. |
protected void |
startAITicker()
Starts our AI ticker if it is not already started. |
boolean |
startGame()
This is called when the game is ready to start (all players involved have delivered their "am ready" notifications). |
protected boolean |
startWithoutHumans()
|
protected void |
stateDidChange(int state,
int oldState)
Called when the game state changes. |
protected void |
stopAITicker()
Stops our AI ticker if it's running. |
void |
systemMessage(String msgbundle,
String msg)
Sends a system message to the players in the game room. |
void |
systemMessage(String msgbundle,
String msg,
boolean waitForStart)
Sends a system message to the players in the game room. |
protected void |
tick(long tickStamp)
Gives game managers an opportunity to perform periodic processing that is not driven by events generated by the player. |
protected void |
tickAI(int pidx,
GameAI ai)
Called by tickAIs() to tick each AI in the game. |
protected void |
tickAIs()
Called by the AI ticker if we're registered as an AI game. |
| Methods inherited from class com.threerings.crowd.server.PlaceManager |
|---|
addDelegate, addDispatcher, addOccupantInfo, addProvider, applyToDelegates, applyToOccupants, bodyEntered, bodyUpdated, bodyWillEnter, bodyWillLeave, cancelShutdowner, checkPermissions, createPlaceObject, createSpeakHandler, getAccessController, getConfig, getLocation, getPlaceObject, getPlaceObjectClass, idleUnloadPeriod, init, isValidSpeaker, messageReceived, permissionsFailed, ratifyBodyEntry, registerMessageHandler, shouldCreateSpeakService, shouldDeclareEmpty, shutdown, startup, toString, toString, updateOccupantInfo, where |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected NamedAttributeListener _stateListener
protected GameConfig _gameconfig
protected GameObject _gameobj
protected int _playerCount
protected int[] _playerOids
protected ArrayIntSet _pendingOids
protected GameAI[] _AIs
protected List<Tuple<String,String>> _startmsgs
protected int _committedState
protected RepeatCallTracker _gameEndTracker
protected Interval _noShowInterval
protected boolean _postponedStart
protected Interval _tickInterval
protected Interval _aiTicker
protected static final long DEFAULT_NOSHOW_DELAY
getNoShowTime().
protected static final long TICK_DELAY
protected static final long AI_TICK_DELAY
| Constructor Detail |
|---|
public GameManager()
| Method Detail |
|---|
public GameConfig getGameConfig()
public int getGameId()
GameConfig.getGameId().
public int getMatchType()
public int addPlayer(Name player)
player - the username of the player to add to this game.
-1 if the player
could not be added to the game.
public boolean addPlayerAt(Name player,
int pidx)
player - the username of the player to add to this game.pidx - the player index at which the player is to be added.
public boolean removePlayer(Name player)
player - the username of the player to remove from this game.
public void replacePlayer(int pidx,
Name player)
playerWasReplaced(int, com.threerings.util.Name, com.threerings.util.Name) to let
derived classes and delegates know what's going on.
public BodyObject getPlayer(int playerIdx)
public void setAI(int pidx,
GameAI ai)
pidx - the player index of the AI.ai - the AI configuration.public Name getPlayerName(int index)
public Name getPlayerDisplayName(int index)
getPlayerName(int), which is the player's unique name in the server.
public int getPlayerIndex(Name username)
-1 if the player is
not involved in the game.
public int getPresentPlayerIndex(int bodyOid)
public int getPlayerOid(int index)
public int getPlayerPersistentId(Name name)
public int getPlayerPersistentId(BodyObject body)
public int getPlayerCount()
public int getPlayerSlots()
public boolean isAI(int pidx)
public boolean isActivePlayer(int pidx)
public int getSessionId()
public void systemMessage(String msgbundle,
String msg)
public void systemMessage(String msgbundle,
String msg,
boolean waitForStart)
waitForStart - if true, the message will not be sent until the game has started.public boolean startGame()
gameWillStart(), sets the necessary wheels in
motion and then calls gameDidStart(). Derived classes should override one or both of
the calldown functions (rather than this function) if they need to do things before or after
the game starts.
public void endPlayerGame(int pidx)
public void endGame()
GameObject.GAME_OVER state.
public boolean cancelGame()
GameObject.CANCELLED.
public boolean shouldConcludeGame()
public void resetGame()
gameWillReset() followed by the
standard game start processing (gameWillStart() and gameDidStart()). Derived
classes should override these calldown functions (rather than this function) if they need to
do things before or after the game resets.
public void occupantInRoom(BodyObject caller)
playerReady(com.threerings.crowd.data.BodyObject) but games that wish to delay their
actual start until players take some action must report ASAP with a call to occupantInRoom(com.threerings.crowd.data.BodyObject) to let the server know that they have arrived and will later be calling
playerReady(com.threerings.crowd.data.BodyObject) when they are ready for the game to actually start.
public void playerReady(BodyObject caller)
PlaceManager.messageReceived(com.threerings.presents.dobj.MessageEvent).
public boolean allPlayersReady()
playerReady(com.threerings.crowd.data.BodyObject)
notifications, false if they have not.
public boolean playerIsReady(int pidx)
public boolean isPlayer(ClientObject client)
PlayManager
isPlayer in interface PlayManagerpublic boolean isAgent(ClientObject client)
PlayManager
isAgent in interface PlayManager
public BodyObject checkWritePermission(ClientObject client,
int playerId)
PlayManager
checkWritePermission in interface PlayManagerprotected boolean needsNoShowTimer()
protected long getNoShowTime()
protected boolean needsAITick()
tickAIs()
protected void playerWasAdded(Name player,
int pidx)
super.playerWasAdded().
player - the username of the player added to the game.pidx - the player index of the player added to the game.
protected void playerWasRemoved(Name player,
int pidx)
super.playerWasRemoved().
player - the username of the player removed from the game.pidx - the player index of the player before they were removed from the game.
protected void playerWasReplaced(int pidx,
Name oldPlayer,
Name newPlayer)
replacePlayer(int, com.threerings.util.Name).
protected void reportPlayerKnockedOut(int pidx)
protected void didInit()
didInit in class PlaceManagerprotected void didStartup()
didStartup in class PlaceManagerprotected void didShutdown()
didShutdown in class PlaceManagerprotected void bodyLeft(int bodyOid)
bodyLeft in class PlaceManagerprotected void placeBecameEmpty()
placeBecameEmpty in class PlaceManagerprotected void playersAllHere()
protected void checkShutdownInterval()
checkShutdownInterval in class PlaceManagerprotected void checkForNoShows()
protected void handlePartialNoShow()
protected boolean startWithoutHumans()
protected void gameWillStart()
super.gameWillStart().
protected void stateDidChange(int state,
int oldState)
state - the new game state.oldState - the previous game state.protected void gameDidStart()
GameObject.IN_PLAY is necessary), but should be
sure to call super.gameDidStart().
protected void startAITicker()
protected void stopAITicker()
protected void tickAIs()
protected void tickAI(int pidx,
GameAI ai)
tickAIs() to tick each AI in the game.
protected void announcePlayerGameOver(int pidx)
protected String getPlayerGameOverMessage(int pidx)
protected void playerGameDidEnd(int pidx)
protected boolean shouldEndGame()
protected void assignWinners(boolean[] winners)
endGame() when the game is over. The default
implementation marks no players as winners. Derived classes should override this method in
order to customize the winning conditions.
protected void gameWillEnd()
super.gameWillEnd().
protected void gameDidEnd()
GameObject.GAME_OVER state. Derived
classes should override this to perform any post-game activities, but should be sure to call
super.gameDidEnd().
protected void gameWasCancelled()
gameWillStart(), etc. will never have been called and thus gameWillEnd(), etc. will not be called. However, if a game chooses to cancel itself for
whatever reason, no effort will be made to call endGame() and the game ending call
backs so that game can override this method to do anything it needs. Note that didShutdown() will be called in every case and that's generally the best place to free
resources so this method may not be needed.
protected void reportWinnersAndLosers()
protected void gameWillReset()
protected void tick(long tickStamp)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||