No longer pass the manager in the constructor. As many of these delegates are
in the wild, we'll deprecate the old constructors rather than remove them. Yay cruft! git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@487 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -73,7 +73,7 @@ public class EZGameManager extends GameManager
|
|||||||
{
|
{
|
||||||
public EZGameManager ()
|
public EZGameManager ()
|
||||||
{
|
{
|
||||||
addDelegate(_turnDelegate = new EZGameTurnDelegate(this));
|
addDelegate(_turnDelegate = new EZGameTurnDelegate());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,11 +33,6 @@ import com.threerings.parlor.turn.server.TurnGameManagerDelegate;
|
|||||||
*/
|
*/
|
||||||
public class EZGameTurnDelegate extends TurnGameManagerDelegate
|
public class EZGameTurnDelegate extends TurnGameManagerDelegate
|
||||||
{
|
{
|
||||||
public EZGameTurnDelegate (EZGameManager mgr)
|
|
||||||
{
|
|
||||||
super(mgr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A form of endTurn where you can specify the next turn holder oid.
|
* A form of endTurn where you can specify the next turn holder oid.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+99
-98
@@ -37,7 +37,8 @@ import com.threerings.presents.server.PresentsServer;
|
|||||||
|
|
||||||
import com.threerings.crowd.data.BodyObject;
|
import com.threerings.crowd.data.BodyObject;
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
import com.threerings.crowd.data.PlaceObject;
|
||||||
import com.threerings.parlor.game.server.GameManager;
|
import com.threerings.crowd.server.PlaceManager;
|
||||||
|
|
||||||
import com.threerings.parlor.turn.server.TurnGameManagerDelegate;
|
import com.threerings.parlor.turn.server.TurnGameManagerDelegate;
|
||||||
|
|
||||||
import com.threerings.parlor.card.Log;
|
import com.threerings.parlor.card.Log;
|
||||||
@@ -56,34 +57,38 @@ import com.threerings.parlor.card.trick.data.TrickCardGameObject;
|
|||||||
public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||||
implements TrickCardGameProvider
|
implements TrickCardGameProvider
|
||||||
{
|
{
|
||||||
/**
|
public TrickCardGameManagerDelegate ()
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param manager the game manager
|
|
||||||
*/
|
|
||||||
public TrickCardGameManagerDelegate (CardGameManager manager)
|
|
||||||
{
|
{
|
||||||
super(manager);
|
|
||||||
|
|
||||||
_cgmgr = manager;
|
|
||||||
_deck = new Deck();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Documentation inherited.
|
/**
|
||||||
|
* @deprecated use the zero-argument constructor.
|
||||||
|
*/
|
||||||
|
@Deprecated public TrickCardGameManagerDelegate (CardGameManager manager)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from PlaceManagerDelegate
|
||||||
|
public void setPlaceManager (PlaceManager plmgr)
|
||||||
|
{
|
||||||
|
super.setPlaceManager(plmgr);
|
||||||
|
_cgmgr = (CardGameManager)plmgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from PlaceManagerDelegate
|
||||||
public void didStartup (PlaceObject plobj)
|
public void didStartup (PlaceObject plobj)
|
||||||
{
|
{
|
||||||
super.didStartup(plobj);
|
super.didStartup(plobj);
|
||||||
|
|
||||||
|
_deck = new Deck();
|
||||||
_trickCardGame = (TrickCardGameObject)plobj;
|
_trickCardGame = (TrickCardGameObject)plobj;
|
||||||
|
|
||||||
_cardGame = (CardGameObject)plobj;
|
_cardGame = (CardGameObject)plobj;
|
||||||
|
|
||||||
_trickCardGame.setTrickCardGameService(
|
_trickCardGame.setTrickCardGameService(
|
||||||
(TrickCardGameMarshaller)PresentsServer.invmgr.registerDispatcher(
|
(TrickCardGameMarshaller)PresentsServer.invmgr.registerDispatcher(
|
||||||
new TrickCardGameDispatcher(this)));
|
new TrickCardGameDispatcher(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Documentation inherited.
|
@Override // from PlaceManagerDelegate
|
||||||
public void didShutdown ()
|
public void didShutdown ()
|
||||||
{
|
{
|
||||||
super.didShutdown();
|
super.didShutdown();
|
||||||
@@ -91,7 +96,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
PresentsServer.invmgr.clearDispatcher(_trickCardGame.getTrickCardGameService());
|
PresentsServer.invmgr.clearDispatcher(_trickCardGame.getTrickCardGameService());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Documentation inherited.
|
@Override // from GameManagerDelegate
|
||||||
public void gameWillStart ()
|
public void gameWillStart ()
|
||||||
{
|
{
|
||||||
super.gameWillStart();
|
super.gameWillStart();
|
||||||
@@ -116,7 +121,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
startHand();
|
startHand();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Documentation inherited.
|
@Override // from GameManagerDelegate
|
||||||
public void gameDidEnd ()
|
public void gameDidEnd ()
|
||||||
{
|
{
|
||||||
super.gameDidEnd();
|
super.gameDidEnd();
|
||||||
@@ -134,7 +139,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
_trickCardGame.setRematchRequests(new int[_cardGame.getPlayerCount()]);
|
_trickCardGame.setRematchRequests(new int[_cardGame.getPlayerCount()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Documentation inherited.
|
@Override // from TurnGameManagerDelegate
|
||||||
public void startTurn ()
|
public void startTurn ()
|
||||||
{
|
{
|
||||||
super.startTurn();
|
super.startTurn();
|
||||||
@@ -144,7 +149,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
_turnTimeoutInterval.schedule(_trickCardGame.getTurnDuration());
|
_turnTimeoutInterval.schedule(_trickCardGame.getTurnDuration());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Documentation inherited.
|
@Override // from TurnGameManagerDelegate
|
||||||
public void endTurn ()
|
public void endTurn ()
|
||||||
{
|
{
|
||||||
// cancel the timeout interval
|
// cancel the timeout interval
|
||||||
@@ -205,11 +210,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
trickDidEnd();
|
trickDidEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// from interface TrickCardGameProvider
|
||||||
* Processes a request to transfer a group of cards between players.
|
|
||||||
* Default implementation verifies that the user's hand contains the
|
|
||||||
* specified cards, then calls {@link #sendCardsToPlayer(int, int, Card[])}.
|
|
||||||
*/
|
|
||||||
public void sendCardsToPlayer (ClientObject client, int toidx, Card[] cards)
|
public void sendCardsToPlayer (ClientObject client, int toidx, Card[] cards)
|
||||||
{
|
{
|
||||||
// make sure they're actually a player
|
// make sure they're actually a player
|
||||||
@@ -231,25 +232,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
sendCardsToPlayer(fromidx, toidx, cards);
|
sendCardsToPlayer(fromidx, toidx, cards);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// from interface TrickCardGameProvider
|
||||||
* Sends cards between players without error checking. Default
|
|
||||||
* implementation transfers the cards between hands and notifies
|
|
||||||
* everyone of the transfer using {@link
|
|
||||||
* CardGameManager#transferCardsBetweenPlayers(int, int, Card[])}.
|
|
||||||
*/
|
|
||||||
protected void sendCardsToPlayer (int fromidx, int toidx, Card[] cards)
|
|
||||||
{
|
|
||||||
// remove from sending player's hand
|
|
||||||
_hands[fromidx].removeAll(cards);
|
|
||||||
|
|
||||||
// add to receiving player's hand
|
|
||||||
_hands[toidx].addAll(cards);
|
|
||||||
|
|
||||||
// notify everyone of the transfer
|
|
||||||
_cgmgr.transferCardsBetweenPlayers(fromidx, toidx, cards);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Documentation inherited.
|
|
||||||
public void playCard (ClientObject client, Card card, int handSize)
|
public void playCard (ClientObject client, Card card, int handSize)
|
||||||
{
|
{
|
||||||
// make sure we're playing a trick
|
// make sure we're playing a trick
|
||||||
@@ -286,39 +269,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
// play the card
|
// play the card
|
||||||
playCard(pidx, card);
|
playCard(pidx, card);
|
||||||
}
|
}
|
||||||
|
// from interface TrickCardGameProvider
|
||||||
/**
|
|
||||||
* Plays a card for a player without error checking.
|
|
||||||
*/
|
|
||||||
protected void playCard (int pidx, Card card)
|
|
||||||
{
|
|
||||||
((DObject) _trickCardGame).startTransaction();
|
|
||||||
try {
|
|
||||||
// play the card by removing it from the hand and adding it
|
|
||||||
// to the end of the cards played array
|
|
||||||
_hands[pidx].remove(card);
|
|
||||||
PlayerCard[] cards = (PlayerCard[])ArrayUtil.append(
|
|
||||||
_trickCardGame.getCardsPlayed(), new PlayerCard(pidx, card));
|
|
||||||
_trickCardGame.setCardsPlayed(cards);
|
|
||||||
|
|
||||||
// end the user's turn
|
|
||||||
endTurn();
|
|
||||||
|
|
||||||
// end the trick if everyone has played a card
|
|
||||||
if (_turnIdx == -1) {
|
|
||||||
if (_endTrickDelay == 0) {
|
|
||||||
endTrick();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
_endTrickInterval.schedule(_endTrickDelay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
((DObject) _trickCardGame).commitTransaction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Documentation inherited.
|
|
||||||
public void requestRematch (ClientObject client)
|
public void requestRematch (ClientObject client)
|
||||||
{
|
{
|
||||||
// make sure the game is over
|
// make sure the game is over
|
||||||
@@ -354,6 +305,56 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends cards between players without error checking. Default
|
||||||
|
* implementation transfers the cards between hands and notifies
|
||||||
|
* everyone of the transfer using {@link
|
||||||
|
* CardGameManager#transferCardsBetweenPlayers(int, int, Card[])}.
|
||||||
|
*/
|
||||||
|
protected void sendCardsToPlayer (int fromidx, int toidx, Card[] cards)
|
||||||
|
{
|
||||||
|
// remove from sending player's hand
|
||||||
|
_hands[fromidx].removeAll(cards);
|
||||||
|
|
||||||
|
// add to receiving player's hand
|
||||||
|
_hands[toidx].addAll(cards);
|
||||||
|
|
||||||
|
// notify everyone of the transfer
|
||||||
|
_cgmgr.transferCardsBetweenPlayers(fromidx, toidx, cards);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plays a card for a player without error checking.
|
||||||
|
*/
|
||||||
|
protected void playCard (int pidx, Card card)
|
||||||
|
{
|
||||||
|
((DObject) _trickCardGame).startTransaction();
|
||||||
|
try {
|
||||||
|
// play the card by removing it from the hand and adding it
|
||||||
|
// to the end of the cards played array
|
||||||
|
_hands[pidx].remove(card);
|
||||||
|
PlayerCard[] cards = (PlayerCard[])ArrayUtil.append(
|
||||||
|
_trickCardGame.getCardsPlayed(), new PlayerCard(pidx, card));
|
||||||
|
_trickCardGame.setCardsPlayed(cards);
|
||||||
|
|
||||||
|
// end the user's turn
|
||||||
|
endTurn();
|
||||||
|
|
||||||
|
// end the trick if everyone has played a card
|
||||||
|
if (_turnIdx == -1) {
|
||||||
|
if (_endTrickDelay == 0) {
|
||||||
|
endTrick();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_endTrickInterval.schedule(_endTrickDelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
((DObject) _trickCardGame).commitTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of players currently requesting or accepting a rematch.
|
* Returns the number of players currently requesting or accepting a rematch.
|
||||||
*/
|
*/
|
||||||
@@ -377,7 +378,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
return _trickCardGame.getCardsPlayed().length == _cardGame.getPlayerCount();
|
return _trickCardGame.getCardsPlayed().length == _cardGame.getPlayerCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Documentation inherited.
|
@Override // from TurnGameManagerDelegate
|
||||||
protected void setFirstTurnHolder ()
|
protected void setFirstTurnHolder ()
|
||||||
{
|
{
|
||||||
if (_trickCardGame.getTrickState() == TrickCardGameObject.PLAYING_TRICK) {
|
if (_trickCardGame.getTrickState() == TrickCardGameObject.PLAYING_TRICK) {
|
||||||
@@ -388,7 +389,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Documentation inherited.
|
@Override // from TurnGameManagerDelegate
|
||||||
protected void setNextTurnHolder ()
|
protected void setNextTurnHolder ()
|
||||||
{
|
{
|
||||||
if (_trickCardGame.getTrickState() == TrickCardGameObject.PLAYING_TRICK &&
|
if (_trickCardGame.getTrickState() == TrickCardGameObject.PLAYING_TRICK &&
|
||||||
@@ -455,7 +456,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
* Notifies the object that a new hand is about to start.
|
* Notifies the object that a new hand is about to start.
|
||||||
*/
|
*/
|
||||||
protected void handWillStart ()
|
protected void handWillStart ()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies the object that a new hand has just started. Default
|
* Notifies the object that a new hand has just started. Default
|
||||||
@@ -530,7 +532,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
* Notifies the object that the trick is about to end.
|
* Notifies the object that the trick is about to end.
|
||||||
*/
|
*/
|
||||||
protected void trickWillEnd ()
|
protected void trickWillEnd ()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies the object that the trick has ended. Default implementation
|
* Notifies the object that the trick has ended. Default implementation
|
||||||
@@ -568,6 +571,21 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The all-purpose turn timeout interval. */
|
||||||
|
protected Interval _turnTimeoutInterval = new Interval(PresentsServer.omgr) {
|
||||||
|
public void expired () {
|
||||||
|
_turnTimedOut = true;
|
||||||
|
turnTimedOut();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Calls {@link #endTrick} upon expiration. */
|
||||||
|
protected Interval _endTrickInterval = new Interval(PresentsServer.omgr) {
|
||||||
|
public void expired () {
|
||||||
|
endTrick();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** The card game manager. */
|
/** The card game manager. */
|
||||||
protected CardGameManager _cgmgr;
|
protected CardGameManager _cgmgr;
|
||||||
|
|
||||||
@@ -589,27 +607,10 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
/** Whether or not the turn timed out. */
|
/** Whether or not the turn timed out. */
|
||||||
protected boolean _turnTimedOut;
|
protected boolean _turnTimedOut;
|
||||||
|
|
||||||
/** The all-purpose turn timeout interval. */
|
|
||||||
protected Interval _turnTimeoutInterval = new Interval(PresentsServer.omgr) {
|
|
||||||
public void expired () {
|
|
||||||
_turnTimedOut = true;
|
|
||||||
turnTimedOut();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Calls {@link #endTrick} upon expiration. */
|
|
||||||
protected Interval _endTrickInterval = new Interval(PresentsServer.omgr) {
|
|
||||||
public void expired () {
|
|
||||||
endTrick();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Reduce turn duration scales by this amount each time the player times out. */
|
/** Reduce turn duration scales by this amount each time the player times out. */
|
||||||
protected static final float TURN_DURATION_SCALE_REDUCTION = 0.25f;
|
protected static final float TURN_DURATION_SCALE_REDUCTION = 0.25f;
|
||||||
|
|
||||||
/**
|
/** Turn duration scales increase by this amount each time the player doesn't time out. */
|
||||||
* Increase turn duration scales by this amount each time the player
|
|
||||||
* manages not to time out. */
|
|
||||||
protected static final float TURN_DURATION_SCALE_INCREASE = 0.5f;
|
protected static final float TURN_DURATION_SCALE_INCREASE = 0.5f;
|
||||||
|
|
||||||
/** Don't let turn duration scales get below this level. */
|
/** Don't let turn duration scales get below this level. */
|
||||||
|
|||||||
@@ -28,18 +28,19 @@ import com.threerings.crowd.server.PlaceManagerDelegate;
|
|||||||
import com.threerings.parlor.game.data.GameAI;
|
import com.threerings.parlor.game.data.GameAI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends the {@link PlaceManagerDelegate} mechanism with game manager
|
* Extends the {@link PlaceManagerDelegate} mechanism with game manager specific methods.
|
||||||
* specific methods.
|
|
||||||
*/
|
*/
|
||||||
public class GameManagerDelegate extends PlaceManagerDelegate
|
public class GameManagerDelegate extends PlaceManagerDelegate
|
||||||
{
|
{
|
||||||
/**
|
public GameManagerDelegate ()
|
||||||
* Provides the delegate with a reference to the game manager for
|
{
|
||||||
* which it is delegating.
|
}
|
||||||
*/
|
|
||||||
public GameManagerDelegate (GameManager gmgr)
|
/**
|
||||||
|
* @deprecated use the zero-argument constructor.
|
||||||
|
*/
|
||||||
|
@Deprecated public GameManagerDelegate (GameManager gmgr)
|
||||||
{
|
{
|
||||||
super(gmgr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,16 +58,15 @@ public class GameManagerDelegate extends PlaceManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player in the game has been replaced by a call to
|
* Called when a player in the game has been replaced by a call to {@link
|
||||||
* {@link GameManager#replacePlayer}.
|
* GameManager#replacePlayer}.
|
||||||
*/
|
*/
|
||||||
public void playerWasReplaced (int pidx, Name oldPlayer, Name newPlayer)
|
public void playerWasReplaced (int pidx, Name oldPlayer, Name newPlayer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the manager when we should do some AI. Only called while
|
* Called by the manager when we should do some AI. Only called while the game is IN_PLAY.
|
||||||
* the game is IN_PLAY.
|
|
||||||
*
|
*
|
||||||
* @param pidx the player index to fake some gameplay for.
|
* @param pidx the player index to fake some gameplay for.
|
||||||
* @param ai a record indicating the AI's configuration.
|
* @param ai a record indicating the AI's configuration.
|
||||||
@@ -90,17 +90,16 @@ public class GameManagerDelegate extends PlaceManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the game is about to reset, but before any other
|
* Called when the game is about to reset, but before any other clearing out of game data has
|
||||||
* clearing out of game data has taken place. Derived classes should
|
* taken place. Derived classes should override this if they need to perform some pre-reset
|
||||||
* override this if they need to perform some pre-reset activities.
|
* activities.
|
||||||
*/
|
*/
|
||||||
public void gameWillReset ()
|
public void gameWillReset ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the specified player has been set as an AI with the
|
* Called when the specified player has been set as an AI with the supplied AI configuration.
|
||||||
* supplied AI configuration.
|
|
||||||
*/
|
*/
|
||||||
public void setAI (int pidx, GameAI ai)
|
public void setAI (int pidx, GameAI ai)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,8 +42,10 @@ import com.threerings.util.Name;
|
|||||||
import com.threerings.media.util.MathUtil;
|
import com.threerings.media.util.MathUtil;
|
||||||
|
|
||||||
import com.threerings.crowd.data.BodyObject;
|
import com.threerings.crowd.data.BodyObject;
|
||||||
|
import com.threerings.crowd.data.PlaceConfig;
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
import com.threerings.crowd.data.PlaceObject;
|
||||||
import com.threerings.crowd.server.CrowdServer;
|
import com.threerings.crowd.server.CrowdServer;
|
||||||
|
import com.threerings.crowd.server.PlaceManager;
|
||||||
|
|
||||||
import com.threerings.parlor.game.data.GameConfig;
|
import com.threerings.parlor.game.data.GameConfig;
|
||||||
import com.threerings.parlor.game.data.GameObject;
|
import com.threerings.parlor.game.data.GameObject;
|
||||||
@@ -60,13 +62,17 @@ import com.threerings.parlor.rating.server.persist.RatingRepository;
|
|||||||
public abstract class RatingManagerDelegate extends GameManagerDelegate
|
public abstract class RatingManagerDelegate extends GameManagerDelegate
|
||||||
implements RatingCodes
|
implements RatingCodes
|
||||||
{
|
{
|
||||||
/**
|
@Override // from PlaceManagerDelegate
|
||||||
* Constructs a rating manager delegate.
|
public void setPlaceManager (PlaceManager plmgr)
|
||||||
*/
|
|
||||||
public RatingManagerDelegate (GameManager gmgr)
|
|
||||||
{
|
{
|
||||||
super(gmgr);
|
super.setPlaceManager(plmgr);
|
||||||
_gmgr = gmgr;
|
_gmgr = (GameManager)plmgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from PlaceManagerDelegate
|
||||||
|
public void didInit (PlaceConfig config)
|
||||||
|
{
|
||||||
|
super.didInit(config);
|
||||||
_repo = getRatingRepository();
|
_repo = getRatingRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import com.samskivert.util.RandomUtil;
|
|||||||
import com.threerings.util.Name;
|
import com.threerings.util.Name;
|
||||||
|
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
import com.threerings.crowd.data.PlaceObject;
|
||||||
|
import com.threerings.crowd.server.PlaceManager;
|
||||||
|
|
||||||
import com.threerings.parlor.Log;
|
import com.threerings.parlor.Log;
|
||||||
import com.threerings.parlor.game.server.GameManager;
|
import com.threerings.parlor.game.server.GameManager;
|
||||||
@@ -33,31 +34,36 @@ import com.threerings.parlor.game.server.GameManagerDelegate;
|
|||||||
import com.threerings.parlor.turn.data.TurnGameObject;
|
import com.threerings.parlor.turn.data.TurnGameObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the server-side turn-based game processing for a turn based game.
|
* Performs the server-side turn-based game processing for a turn based game. Game managers which
|
||||||
* Game managers which wish to make use of the turn services must implement
|
* wish to make use of the turn services must implement {@link TurnGameManager} and either create
|
||||||
* {@link TurnGameManager} and either create an instance of this class, or an
|
* an instance of this class, or an instance of a derivation which customizes the behavior, either
|
||||||
* instance of a derivation which customizes the behavior, either of which
|
* of which would be passed to {@link GameManager#addDelegate} to be activated.
|
||||||
* would be passed to {@link GameManager#addDelegate} to be activated.
|
|
||||||
*/
|
*/
|
||||||
public class TurnGameManagerDelegate extends GameManagerDelegate
|
public class TurnGameManagerDelegate extends GameManagerDelegate
|
||||||
{
|
{
|
||||||
/**
|
public TurnGameManagerDelegate ()
|
||||||
* Constructs a delegate that will manage the turn game state and call back
|
|
||||||
* to the supplied {@link TurnGameManager} implementation to let it in on
|
|
||||||
* the progression of the game.
|
|
||||||
*/
|
|
||||||
public TurnGameManagerDelegate (TurnGameManager tgmgr)
|
|
||||||
{
|
{
|
||||||
super((GameManager)tgmgr);
|
|
||||||
_tgmgr = tgmgr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the index of the current turn holder as configured in the game
|
* @deprecated use the zero-argument constructor.
|
||||||
* object.
|
*/
|
||||||
|
@Deprecated public TurnGameManagerDelegate (TurnGameManager tgmgr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from PlaceManagerDelegate
|
||||||
|
public void setPlaceManager (PlaceManager plmgr)
|
||||||
|
{
|
||||||
|
super.setPlaceManager(plmgr);
|
||||||
|
_tgmgr = (TurnGameManager)plmgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the index of the current turn holder as configured in the game object.
|
||||||
*
|
*
|
||||||
* @return the index into the players array of the current turn holder or
|
* @return the index into the players array of the current turn holder or <code>-1</code> if
|
||||||
* <code>-1</code> if there is no current turn holder.
|
* there is no current turn holder.
|
||||||
*/
|
*/
|
||||||
public int getTurnHolderIndex ()
|
public int getTurnHolderIndex ()
|
||||||
{
|
{
|
||||||
@@ -67,8 +73,7 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
/** Test if it's the inputted player's turn. */
|
/** Test if it's the inputted player's turn. */
|
||||||
public boolean isPlayersTurn (int playerIndex)
|
public boolean isPlayersTurn (int playerIndex)
|
||||||
{
|
{
|
||||||
// Don't accidently match a visitor's id of -1 with the "no one's
|
// Don't accidently match a visitor's id of -1 with the "no one's turn" state of turn -1.
|
||||||
// turn" state of turn -1.
|
|
||||||
int turnHolder = getTurnHolderIndex();
|
int turnHolder = getTurnHolderIndex();
|
||||||
if (turnHolder < 0) {
|
if (turnHolder < 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -79,22 +84,20 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to start the next turn. It calls {@link
|
* Called to start the next turn. It calls {@link TurnGameManager#turnWillStart} to allow our
|
||||||
* TurnGameManager#turnWillStart} to allow our owning manager to perform
|
* owning manager to perform any pre-start turn processing, sets the turn holder that was
|
||||||
* any pre-start turn processing, sets the turn holder that was configured
|
* configured either when the game started or when finishing up the last turn, and then calls
|
||||||
* either when the game started or when finishing up the last turn, and
|
* {@link TurnGameManager#turnDidStart} to allow the manager to perform any post-start turn
|
||||||
* then calls {@link TurnGameManager#turnDidStart} to allow the manager to
|
* processing. This assumes that a valid turn holder has been assigned. If some pre-game
|
||||||
* perform any post-start turn processing. This assumes that a valid turn
|
* preparation needs to take place in a non-turn-based manner, this function should not be
|
||||||
* holder has been assigned. If some pre-game preparation needs to take
|
* called until it is time to start the first turn.
|
||||||
* place in a non-turn-based manner, this function should not be called
|
|
||||||
* until it is time to start the first turn.
|
|
||||||
*/
|
*/
|
||||||
public void startTurn ()
|
public void startTurn ()
|
||||||
{
|
{
|
||||||
// sanity check
|
// sanity check
|
||||||
if (_turnIdx < 0 || _turnIdx >= _turnGame.getPlayers().length) {
|
if (_turnIdx < 0 || _turnIdx >= _turnGame.getPlayers().length) {
|
||||||
Log.warning("startTurn() called with invalid turn index " +
|
Log.warning("startTurn() called with invalid turn index [game=" + where() +
|
||||||
"[game=" + where() + ", turnIdx=" + _turnIdx + "].");
|
", turnIdx=" + _turnIdx + "].");
|
||||||
// abort, abort
|
// abort, abort
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -102,8 +105,8 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
// get the player name and sanity-check again
|
// get the player name and sanity-check again
|
||||||
Name name = _tgmgr.getPlayerName(_turnIdx);
|
Name name = _tgmgr.getPlayerName(_turnIdx);
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
Log.warning("startTurn() called with invalid player " +
|
Log.warning("startTurn() called with invalid player [game=" + where() +
|
||||||
"[game=" + where() + ", turnIdx=" + _turnIdx + "].");
|
", turnIdx=" + _turnIdx + "].");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,21 +121,18 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to end the turn. Whatever indication a game manager has that the
|
* Called to end the turn. Whatever indication a game manager has that the turn has ended
|
||||||
* turn has ended (probably the submission of a valid move of some sort by
|
* (probably the submission of a valid move of some sort by the turn holding player), it should
|
||||||
* the turn holding player), it should call this function to cause this
|
* call this function to cause this turn to end and the next to begin.
|
||||||
* turn to end and the next to begin.
|
|
||||||
*
|
*
|
||||||
* <p> If the game is no longer in play (see {@link TurnGame#isInPlay})
|
* <p> If the game is no longer in play (see {@link TurnGame#isInPlay}) after having called
|
||||||
* after having called {@link TurnGameManager#turnDidEnd} and {@link
|
* {@link TurnGameManager#turnDidEnd} and {@link #setNextTurnHolder}, then the next turn will
|
||||||
* #setNextTurnHolder}, then the next turn will not automatically be
|
* not automatically be started.
|
||||||
* started.
|
|
||||||
*
|
*
|
||||||
* <p> If the game is in play, but the next turn should not be started
|
* <p> If the game is in play, but the next turn should not be started immediately, the game
|
||||||
* immediately, the game manager should have {@link #setNextTurnHolder} set
|
* manager should have {@link #setNextTurnHolder} set the {@link #_turnIdx} field to
|
||||||
* the {@link #_turnIdx} field to <code>-1</code> which will cause us to
|
* <code>-1</code> which will cause us to not start the next turn. To start things back up
|
||||||
* not start the next turn. To start things back up again it would set
|
* again it would set {@link #_turnIdx} to the next turn holder and call {@link #startTurn}
|
||||||
* {@link #_turnIdx} to the next turn holder and call {@link #startTurn}
|
|
||||||
* itself.
|
* itself.
|
||||||
*/
|
*/
|
||||||
public void endTurn ()
|
public void endTurn ()
|
||||||
@@ -162,20 +162,20 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void playerWasReplaced (int pidx, Name oplayer, Name nplayer)
|
public void playerWasReplaced (int pidx, Name oplayer, Name nplayer)
|
||||||
{
|
{
|
||||||
// we need to update the turn holder if the current turn holder
|
// we need to update the turn holder if the current turn holder was the player that was
|
||||||
// was the player that was replaced and we need to do so in a way
|
// replaced and we need to do so in a way that doesn't make everyone think that the turn
|
||||||
// that doesn't make everyone think that the turn just changed
|
// just changed
|
||||||
if (oplayer != null && oplayer.equals(_turnGame.getTurnHolder())) {
|
if (oplayer != null && oplayer.equals(_turnGame.getTurnHolder())) {
|
||||||
// small hackery: this will indicate to the client that we are
|
// small hackery: this will indicate to the client that we are replacing the turn
|
||||||
// replacing the turn holder rather than changing the turn
|
// holder rather than changing the turn
|
||||||
_turnGame.setTurnHolder(TurnGameObject.TURN_HOLDER_REPLACED);
|
_turnGame.setTurnHolder(TurnGameObject.TURN_HOLDER_REPLACED);
|
||||||
_turnGame.setTurnHolder(nplayer);
|
_turnGame.setTurnHolder(nplayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should be called from {@link GameManager#gameDidStart} to let
|
* This should be called from {@link GameManager#gameDidStart} to let the turn delegate perform
|
||||||
* the turn delegate perform start of game processing.
|
* start of game processing.
|
||||||
*/
|
*/
|
||||||
public void gameDidStart ()
|
public void gameDidStart ()
|
||||||
{
|
{
|
||||||
@@ -189,8 +189,8 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called to determine which player will take the first
|
* This is called to determine which player will take the first turn. The default
|
||||||
* turn. The default implementation chooses a player at random.
|
* implementation chooses a player at random.
|
||||||
*/
|
*/
|
||||||
protected void setFirstTurnHolder ()
|
protected void setFirstTurnHolder ()
|
||||||
{
|
{
|
||||||
@@ -198,10 +198,9 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called to determine which player will next hold the turn.
|
* This is called to determine which player will next hold the turn. The default
|
||||||
* The default implementation simply rotates through the players in
|
* implementation simply rotates through the players in order, but some games may need to mess
|
||||||
* order, but some games may need to mess with the turn from time to
|
* with the turn from time to time. This should update the <code>_turnIdx</code> field, not set
|
||||||
* time. This should update the <code>_turnIdx</code> field, not set
|
|
||||||
* the turn holder field in the game object directly.
|
* the turn holder field in the game object directly.
|
||||||
*/
|
*/
|
||||||
protected void setNextTurnHolder ()
|
protected void setNextTurnHolder ()
|
||||||
@@ -217,10 +216,10 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
do {
|
do {
|
||||||
_turnIdx = (_turnIdx + 1) % size;
|
_turnIdx = (_turnIdx + 1) % size;
|
||||||
if (_turnIdx == oturnIdx) {
|
if (_turnIdx == oturnIdx) {
|
||||||
// if we've wrapped all the way around, stop where we are
|
// if we've wrapped all the way around, stop where we are even if the current
|
||||||
// even if the current player is not active.
|
// player is not active.
|
||||||
Log.warning("1 or less active players. Unable to properly " +
|
Log.warning("1 or less active players. Unable to properly change turn. " +
|
||||||
"change turn. [game=" + where() + "].");
|
"[game=" + where() + "].");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (!_tgmgr.isActivePlayer(_turnIdx));
|
} while (!_tgmgr.isActivePlayer(_turnIdx));
|
||||||
@@ -251,7 +250,6 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
/** A reference to our game object. */
|
/** A reference to our game object. */
|
||||||
protected TurnGameObject _turnGame;
|
protected TurnGameObject _turnGame;
|
||||||
|
|
||||||
/** The player index of the current turn holder or <code>-1</code> if
|
/** The player index of the current turn holder or <code>-1</code> if it's no one's turn. */
|
||||||
* it's no one's turn. */
|
|
||||||
protected int _turnIdx = -1;
|
protected int _turnIdx = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,14 +64,19 @@ public abstract class DropManagerDelegate extends PuzzleManagerDelegate
|
|||||||
implements PuzzleCodes, DropCodes
|
implements PuzzleCodes, DropCodes
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Provides the delegate with a reference to the manager for which it
|
* @deprecated use {@link #DropManagerDelegate(DropLogic)}.
|
||||||
* is delegating as well as the logic object that it uses to determine
|
|
||||||
* how to manage the drop puzzle.
|
|
||||||
*/
|
*/
|
||||||
public DropManagerDelegate (PuzzleManager puzmgr, DropLogic logic)
|
@Deprecated public DropManagerDelegate (PuzzleManager puzmgr, DropLogic logic)
|
||||||
{
|
{
|
||||||
super(puzmgr);
|
this(logic);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a drop manager delegate with a logic that it uses to determine how to manage the
|
||||||
|
* drop puzzle.
|
||||||
|
*/
|
||||||
|
public DropManagerDelegate (DropLogic logic)
|
||||||
|
{
|
||||||
// configure the game-specific settings
|
// configure the game-specific settings
|
||||||
_usedrop = logic.useBlockDropping();
|
_usedrop = logic.useBlockDropping();
|
||||||
_userise = logic.useBoardRising();
|
_userise = logic.useBoardRising();
|
||||||
|
|||||||
@@ -21,21 +21,31 @@
|
|||||||
|
|
||||||
package com.threerings.puzzle.server;
|
package com.threerings.puzzle.server;
|
||||||
|
|
||||||
|
import com.threerings.crowd.server.PlaceManager;
|
||||||
import com.threerings.parlor.game.server.GameManagerDelegate;
|
import com.threerings.parlor.game.server.GameManagerDelegate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends the {@link GameManagerDelegate} mechanism with puzzle manager
|
* Extends the {@link GameManagerDelegate} mechanism with puzzle manager specific methods (of which
|
||||||
* specific methods (of which there are currently none).
|
* there are currently none).
|
||||||
*/
|
*/
|
||||||
public class PuzzleManagerDelegate extends GameManagerDelegate
|
public class PuzzleManagerDelegate extends GameManagerDelegate
|
||||||
{
|
{
|
||||||
/**
|
public PuzzleManagerDelegate ()
|
||||||
* Constructs a puzzle manager delegate.
|
|
||||||
*/
|
|
||||||
public PuzzleManagerDelegate (PuzzleManager puzmgr)
|
|
||||||
{
|
{
|
||||||
super(puzmgr);
|
}
|
||||||
_puzmgr = puzmgr;
|
|
||||||
|
/**
|
||||||
|
* @deprecated use the zero-argument constructor.
|
||||||
|
*/
|
||||||
|
@Deprecated public PuzzleManagerDelegate (PuzzleManager puzmgr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from PlaceManagerDelegate
|
||||||
|
public void setPlaceManager (PlaceManager plmgr)
|
||||||
|
{
|
||||||
|
super.setPlaceManager(plmgr);
|
||||||
|
_puzmgr = (PuzzleManager)plmgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PuzzleManager _puzmgr;
|
protected PuzzleManager _puzmgr;
|
||||||
|
|||||||
Reference in New Issue
Block a user