Now that games clear out their player oids when they finish, card games

need to keep around a copy to confirm that somebody is allowed to request
a rematch, and then pull everyone into it.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@368 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Dave Hoover
2007-07-18 16:39:50 +00:00
parent 6958d99563
commit 8c88195b8b
@@ -32,6 +32,7 @@ import com.threerings.parlor.card.data.CardCodes;
import com.threerings.parlor.card.data.CardGameObject; import com.threerings.parlor.card.data.CardGameObject;
import com.threerings.parlor.card.data.Deck; import com.threerings.parlor.card.data.Deck;
import com.threerings.parlor.card.data.Hand; import com.threerings.parlor.card.data.Hand;
import com.threerings.parlor.game.data.GameObject;
import com.threerings.parlor.game.server.GameManager; import com.threerings.parlor.game.server.GameManager;
import com.threerings.parlor.turn.server.TurnGameManager; import com.threerings.parlor.turn.server.TurnGameManager;
@@ -67,6 +68,16 @@ public class CardGameManager extends GameManager
public void turnDidEnd () public void turnDidEnd ()
{} {}
@Override // documentation inherited
protected void gameDidEnd ()
{
// Copy off our player oids so we have them handy to see if somebody was a player for
// rematch purposes.
_oldPlayerOids = _playerOids.clone();
super.gameDidEnd();
}
/** /**
* This should be called to start a rematched game. It just starts the * This should be called to start a rematched game. It just starts the
* current game anew, but provides a mechanism for derived classes to * current game anew, but provides a mechanism for derived classes to
@@ -75,6 +86,8 @@ public class CardGameManager extends GameManager
public void rematchGame () public void rematchGame ()
{ {
if (gameWillRematch()) { if (gameWillRematch()) {
// Stuff our old oids back in since they're ready.
_playerOids = _oldPlayerOids.clone();
startGame(); startGame();
} }
} }
@@ -146,14 +159,18 @@ public class CardGameManager extends GameManager
/** /**
* Gets the player index of the specified client object, or -1 * Gets the player index of the specified client object, or -1
* if the client object does not represent a player. * if the client object does not represent a player. If the game has ended,
* looks through the players of the now-ended game.
*
*/ */
public int getPlayerIndex (ClientObject client) public int getPlayerIndex (ClientObject client)
{ {
int[] oids = (_gameobj.state == GameObject.GAME_OVER) ? _oldPlayerOids : _playerOids;
int oid = client.getOid(); int oid = client.getOid();
for (int i=0;i<_playerOids.length;i++) {
if (_playerOids[i] == oid) { for (int ii=0; ii < oids.length; ii++) {
return i; if (oids[ii] == oid) {
return ii;
} }
} }
return -1; return -1;
@@ -265,4 +282,7 @@ public class CardGameManager extends GameManager
/** The card game object. */ /** The card game object. */
protected CardGameObject _cardgameobj; protected CardGameObject _cardgameobj;
/** The oids of the players from our now-ended game. */
protected int[] _oldPlayerOids;
} }