com.threerings.parlor.rating.server
Class RatingDelegate

java.lang.Object
  extended by com.threerings.crowd.server.PlaceManagerDelegate
      extended by com.threerings.parlor.server.PlayManagerDelegate
          extended by com.threerings.parlor.game.server.GameManagerDelegate
              extended by com.threerings.parlor.rating.server.RatingDelegate
All Implemented Interfaces:
RatingCodes

public abstract class RatingDelegate
extends GameManagerDelegate
implements RatingCodes

Rates players after each game and handles persisting the results.


Nested Class Summary
protected static class RatingDelegate.PlayerRating
          Encapsulates the rating/experience tuple representing a player's rating for a game.
 
Field Summary
protected  GameManager _gmgr
          An appropriately casted reference to our GameManager.
protected  GameObject _gobj
          An appropriately casted reference to our GameObject.
protected  Invoker _invoker
           
protected  int[] _playerIds
          Contains the persistent id of the players in this game.
protected  IntMap<RatingDelegate.PlayerRating> _ratings
          The ratings for each player as they were at the beginning of the game.
protected  RatingRepository _repo
           
protected  long _startStamp
          A timestamp set at the beginning of the game, used to calculate its duration.
 
Fields inherited from class com.threerings.crowd.server.PlaceManagerDelegate
_invmgr, _omgr, _plmgr
 
Fields inherited from interface com.threerings.parlor.rating.data.RatingCodes
DEFAULT_RATING, MAXIMUM_RATING, MINIMUM_RATING
 
Constructor Summary
RatingDelegate()
           
 
Method Summary
 void bodyEntered(int bodyOid)
           
 void bodyLeft(int bodyOid)
           
 void didInit(PlaceConfig config)
           
 void didStartup(PlaceObject plobj)
           
 void gameDidEnd()
          Called by the game manager after the game ended.
 void gameWillStart()
          Called by the game manager when the game is about to start.
protected  int getGameId()
          Returns the game id to use when reading and writing ratings.
protected  void loadRatings(Collection<RatingDelegate.PlayerRating> ratings)
          Loads up rating information for the specified set of player ids and stores them in the _ratings table.
protected  RatingDelegate.PlayerRating maybeCreateRating(BodyObject bobj)
           
protected abstract  int minimumRatedDuration()
          Return the minimum time (in seconds) a game must've lasted for it to count towards rating.
protected  void saveRatings(Collection<RatingDelegate.PlayerRating> ratings)
           
protected  boolean shouldRateGame()
          Returns true if this game should be rated, false otherwise.
protected abstract  void updateRatingInMemory(int gameId, RatingDelegate.PlayerRating rating)
          Optionally store update ratings in memory e.g. in the user object.
protected  void updateRatings()
          Computes updated ratings for the players of this game.
 
Methods inherited from class com.threerings.parlor.game.server.GameManagerDelegate
gameDidStart, gameWillEnd, gameWillReset, playerWasReplaced, setAI, tickAI
 
Methods inherited from class com.threerings.parlor.server.PlayManagerDelegate
isAgent, isPlayer, verifyIsPlayer, verifyIsPlayerOrAgent, verifyWritePermission
 
Methods inherited from class com.threerings.crowd.server.PlaceManagerDelegate
addDispatcher, addProvider, bodyUpdated, didShutdown, init, placeBecameEmpty, where
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_gmgr

protected GameManager _gmgr
An appropriately casted reference to our GameManager.


_gobj

protected GameObject _gobj
An appropriately casted reference to our GameObject.


_playerIds

protected int[] _playerIds
Contains the persistent id of the players in this game.


_ratings

protected IntMap<RatingDelegate.PlayerRating> _ratings
The ratings for each player as they were at the beginning of the game.


_startStamp

protected long _startStamp
A timestamp set at the beginning of the game, used to calculate its duration.


_repo

@Inject
protected RatingRepository _repo

_invoker

@Inject
protected Invoker _invoker
Constructor Detail

RatingDelegate

public RatingDelegate()
Method Detail

didInit

public void didInit(PlaceConfig config)
Overrides:
didInit in class PlayManagerDelegate

didStartup

public void didStartup(PlaceObject plobj)
Overrides:
didStartup in class PlaceManagerDelegate

bodyEntered

public void bodyEntered(int bodyOid)
Overrides:
bodyEntered in class PlaceManagerDelegate

bodyLeft

public void bodyLeft(int bodyOid)
Overrides:
bodyLeft in class PlaceManagerDelegate

gameWillStart

public void gameWillStart()
Description copied from class: GameManagerDelegate
Called by the game manager when the game is about to start.

Overrides:
gameWillStart in class GameManagerDelegate

gameDidEnd

public void gameDidEnd()
Description copied from class: GameManagerDelegate
Called by the game manager after the game ended.

Overrides:
gameDidEnd in class GameManagerDelegate

maybeCreateRating

protected RatingDelegate.PlayerRating maybeCreateRating(BodyObject bobj)

loadRatings

protected void loadRatings(Collection<RatingDelegate.PlayerRating> ratings)
Loads up rating information for the specified set of player ids and stores them in the _ratings table.


saveRatings

protected void saveRatings(Collection<RatingDelegate.PlayerRating> ratings)

updateRatings

protected void updateRatings()
Computes updated ratings for the players of this game. The default implementation uses the GameObject.winners field to determine winners and losers and uses a FIDE/ELO algorithm to compute updated ratings.


getGameId

protected int getGameId()
Returns the game id to use when reading and writing ratings.


shouldRateGame

protected boolean shouldRateGame()
Returns true if this game should be rated, false otherwise.


minimumRatedDuration

protected abstract int minimumRatedDuration()
Return the minimum time (in seconds) a game must've lasted for it to count towards rating.


updateRatingInMemory

protected abstract void updateRatingInMemory(int gameId,
                                             RatingDelegate.PlayerRating rating)
Optionally store update ratings in memory e.g. in the user object. This method is called on the dobj thread.