Basic implementation of the PlayManager interface.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@692 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Par Winzell
2008-07-31 05:49:33 +00:00
parent aae3a0152a
commit a3232d645e
3 changed files with 44 additions and 30 deletions
@@ -33,6 +33,7 @@ import com.samskivert.util.StringUtil;
import com.samskivert.util.Tuple;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.dobj.AttributeChangeListener;
import com.threerings.presents.dobj.AttributeChangedEvent;
import com.threerings.presents.dobj.DObject;
@@ -41,6 +42,7 @@ import com.threerings.crowd.chat.server.SpeakUtil;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.server.PlaceManager;
import com.threerings.crowd.server.PlaceManagerDelegate;
import com.threerings.crowd.server.PlayManager;
import com.threerings.parlor.data.ParlorCodes;
import com.threerings.parlor.game.data.GameAI;
@@ -61,7 +63,7 @@ import static com.threerings.parlor.Log.log;
* location, the players of the game implicitly bodies in that location.
*/
public class GameManager extends PlaceManager
implements ParlorCodes, GameCodes
implements ParlorCodes, GameCodes, PlayManager
{
/**
* An interface for identifying users. A larger system using the Parlor game services can
@@ -652,6 +654,43 @@ public class GameManager extends PlaceManager
isAI(pidx)); // player is AI
}
// from PlayManager
public boolean isPlayer (ClientObject client)
{
// players must have bodies
if (client != null && client instanceof BodyObject) {
BodyObject body = (BodyObject) client;
// players must be occupants
if (_gameobj.occupants.contains(body.getOid())) {
// in a party game, all occupants are players
if (getGameConfig().getMatchType() == GameConfig.PARTY) {
return true;
}
// else they must be seated
return _gameobj.getPlayerIndex(body.getVisibleName()) >= 0;
}
}
return false;
}
// from PlayManager
public boolean isAgent (ClientObject client)
{
// agent-savvy subclasses override this
return false;
}
// from PlayManager
public BodyObject checkWritePermission (ClientObject client, int playerId)
{
// subclasses can be more restrictive here
return true;
}
/**
* Returns true if this game requires a no-show timer. The default implementation returns true
* for non-party games and false for party games. Derived classes may wish to change or augment
@@ -21,16 +21,16 @@
package com.threerings.parlor.game.server;
import com.threerings.util.Name;
import com.threerings.crowd.server.PlayManagerDelegate;
import com.threerings.crowd.server.PlaceManagerDelegate;
import com.threerings.util.Name;
import com.threerings.parlor.game.data.GameAI;
/**
* Extends the {@link PlaceManagerDelegate} mechanism with game manager specific methods.
* Extends the {@link PlayManagerDelegate} mechanism with game manager specific methods.
*/
public class GameManagerDelegate extends PlaceManagerDelegate
public class GameManagerDelegate extends PlayManagerDelegate
{
public GameManagerDelegate ()
{
@@ -46,7 +46,6 @@ import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.parlor.game.data.GameConfig;
import com.threerings.parlor.game.data.GameObject;
import com.threerings.parlor.game.server.GameManager;
import com.threerings.parlor.game.server.GameManagerDelegate;
@@ -181,30 +180,6 @@ public abstract class RatingDelegate extends GameManagerDelegate
return new Rating(bobj, playerId);
}
/**
* Returns true if the supplied occupant is a player, false if not.
*/
protected boolean isPlayer (BodyObject occupant)
{
// avoid having to do this check all over the damned place
if (occupant == null) {
return false;
}
// if this is a seated table game, ask the game object
if (_gobj.getPlayerIndex(occupant.getVisibleName()) != -1) {
return true;
}
// if this is a party game, everyone's a player!
if (_gmgr.getGameConfig().getMatchType() == GameConfig.PARTY) {
return true;
}
// otherwise, sorry pardner
return false;
}
/**
* Loads up rating information for the specified set of player ids and stores them in the
* {@link #_ratings} table.