Reset EZ games to PRE_GAME after they end so that they can be restarted.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@418 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2007-08-24 23:45:47 +00:00
parent 5392df8770
commit 388c616b40
@@ -126,19 +126,19 @@ public class EZGameManager extends GameManager
validateStateModification(caller, false); validateStateModification(caller, false);
// let the game know that it is doing something stupid // let the game know that it is doing something stupid
if (_gameObj.roundId < 0) { if (_ezObj.roundId < 0) {
throw new InvocationException("m.round_already_ended"); throw new InvocationException("m.round_already_ended");
} }
// while we are between rounds, our round id is the negation of the round that just ended // while we are between rounds, our round id is the negation of the round that just ended
_gameObj.setRoundId(-_gameObj.roundId); _ezObj.setRoundId(-_ezObj.roundId);
// queue up the start of the next round if requested // queue up the start of the next round if requested
if (nextRoundDelay > 0) { if (nextRoundDelay > 0) {
new Interval(CrowdServer.omgr) { new Interval(CrowdServer.omgr) {
public void expired () { public void expired () {
if (_gameObj.isInPlay()) { if (_ezObj.isInPlay()) {
_gameObj.setRoundId(-_gameObj.roundId + 1); _ezObj.setRoundId(-_ezObj.roundId + 1);
} }
} }
}.schedule(nextRoundDelay * 1000L); }.schedule(nextRoundDelay * 1000L);
@@ -150,7 +150,7 @@ public class EZGameManager extends GameManager
InvocationService.InvocationListener listener) InvocationService.InvocationListener listener)
throws InvocationException throws InvocationException
{ {
if (!_gameObj.isInPlay()) { if (!_ezObj.isInPlay()) {
throw new InvocationException("e.already_ended"); throw new InvocationException("e.already_ended");
} }
validateStateModification(caller, false); validateStateModification(caller, false);
@@ -164,7 +164,7 @@ public class EZGameManager extends GameManager
InvocationService.InvocationListener listener) InvocationService.InvocationListener listener)
throws InvocationException throws InvocationException
{ {
if (_gameObj.isInPlay()) { if (_ezObj.isInPlay()) {
throw new InvocationException("e.game_in_play"); throw new InvocationException("e.game_in_play");
} }
validateStateModification(caller, false); validateStateModification(caller, false);
@@ -173,7 +173,7 @@ public class EZGameManager extends GameManager
if (seconds > 0) { if (seconds > 0) {
new Interval(CrowdServer.omgr) { new Interval(CrowdServer.omgr) {
public void expired () { public void expired () {
if (_gameObj.isActive() && !_gameObj.isInPlay()) { if (_ezObj.isActive() && !_ezObj.isInPlay()) {
startGame(); startGame();
} }
} }
@@ -189,7 +189,7 @@ public class EZGameManager extends GameManager
validateUser(caller); validateUser(caller);
if (playerId == 0) { if (playerId == 0) {
_gameObj.postMessage(EZGameObject.USER_MESSAGE, msg, data); _ezObj.postMessage(EZGameObject.USER_MESSAGE, msg, data);
} else { } else {
sendPrivateMessage(playerId, msg, data); sendPrivateMessage(playerId, msg, data);
} }
@@ -202,7 +202,7 @@ public class EZGameManager extends GameManager
throws InvocationException throws InvocationException
{ {
validateUser(caller); validateUser(caller);
if (testAndSet && !_gameObj.testProperty(propName, index, testValue)) { if (testAndSet && !_ezObj.testProperty(propName, index, testValue)) {
return; // the test failed: do not set the property return; // the test failed: do not set the property
} }
setProperty(propName, data, index); setProperty(propName, data, index);
@@ -344,7 +344,7 @@ public class EZGameManager extends GameManager
if (_tickers.size() >= MAX_TICKERS) { if (_tickers.size() >= MAX_TICKERS) {
throw new InvocationException(ACCESS_DENIED); throw new InvocationException(ACCESS_DENIED);
} }
t = new Ticker(tickerName, _gameObj); t = new Ticker(tickerName, _ezObj);
_tickers.put(tickerName, t); _tickers.put(tickerName, t);
} }
t.start(msOfDelay); t.start(msOfDelay);
@@ -367,7 +367,7 @@ public class EZGameManager extends GameManager
InvocationService.InvocationListener listener) InvocationService.InvocationListener listener)
throws InvocationException throws InvocationException
{ {
if (_gameObj.userCookies != null && _gameObj.userCookies.containsKey(playerOid)) { if (_ezObj.userCookies != null && _ezObj.userCookies.containsKey(playerOid)) {
// already loaded: we do nothing // already loaded: we do nothing
return; return;
} }
@@ -393,8 +393,8 @@ public class EZGameManager extends GameManager
_cookieLookups.remove(playerOid); _cookieLookups.remove(playerOid);
// result may be null: that's ok, it means we've looked up the user's nonexistent // result may be null: that's ok, it means we've looked up the user's nonexistent
// cookie; also only set the cookie if the player is still in the room // cookie; also only set the cookie if the player is still in the room
if (_gameObj.occupants.contains(playerOid) && _gameObj.isActive()) { if (_ezObj.occupants.contains(playerOid) && _ezObj.isActive()) {
_gameObj.addToUserCookies(new UserCookie(playerOid, result)); _ezObj.addToUserCookies(new UserCookie(playerOid, result));
} }
} }
@@ -418,10 +418,10 @@ public class EZGameManager extends GameManager
// and update the distributed object // and update the distributed object
UserCookie cookie = new UserCookie(caller.getOid(), value); UserCookie cookie = new UserCookie(caller.getOid(), value);
if (_gameObj.userCookies.containsKey(cookie.getKey())) { if (_ezObj.userCookies.containsKey(cookie.getKey())) {
_gameObj.updateUserCookies(cookie); _ezObj.updateUserCookies(cookie);
} else { } else {
_gameObj.addToUserCookies(cookie); _ezObj.addToUserCookies(cookie);
} }
} }
@@ -438,7 +438,7 @@ public class EZGameManager extends GameManager
throw new InvocationException("m.player_not_around"); throw new InvocationException("m.player_not_around");
} }
target.postMessage(EZGameObject.USER_MESSAGE + ":" + _gameObj.getOid(), target.postMessage(EZGameObject.USER_MESSAGE + ":" + _ezObj.getOid(),
new Object[] { msg, data }); new Object[] { msg, data });
} }
@@ -448,9 +448,9 @@ public class EZGameManager extends GameManager
protected void setProperty (String propName, Object value, int index) protected void setProperty (String propName, Object value, int index)
{ {
// apply the property set immediately // apply the property set immediately
Object oldValue = _gameObj.applyPropertySet(propName, value, index); Object oldValue = _ezObj.applyPropertySet(propName, value, index);
_gameObj.postEvent( _ezObj.postEvent(
new PropertySetEvent(_gameObj.getOid(), propName, value, index, oldValue)); new PropertySetEvent(_ezObj.getOid(), propName, value, index, oldValue));
} }
/** /**
@@ -482,7 +482,7 @@ public class EZGameManager extends GameManager
validateUser(caller); validateUser(caller);
if (requireHoldsTurn) { if (requireHoldsTurn) {
Name holder = _gameObj.turnHolder; Name holder = _ezObj.turnHolder;
if (holder != null && !holder.equals(((BodyObject) caller).getVisibleName())) { if (holder != null && !holder.equals(((BodyObject) caller).getVisibleName())) {
throw new InvocationException(InvocationCodes.ACCESS_DENIED); throw new InvocationException(InvocationCodes.ACCESS_DENIED);
} }
@@ -515,7 +515,7 @@ public class EZGameManager extends GameManager
*/ */
protected BodyObject getOccupantByOid (int oid) protected BodyObject getOccupantByOid (int oid)
{ {
if (!_gameObj.occupants.contains(oid)) { if (!_ezObj.occupants.contains(oid)) {
return null; return null;
} }
// return the body // return the body
@@ -533,8 +533,8 @@ public class EZGameManager extends GameManager
{ {
super.didStartup(); super.didStartup();
_gameObj = (EZGameObject) _plobj; _ezObj = (EZGameObject) _plobj;
_gameObj.setEzGameService( _ezObj.setEzGameService(
(EZGameMarshaller) CrowdServer.invmgr.registerDispatcher(new EZGameDispatcher(this))); (EZGameMarshaller) CrowdServer.invmgr.registerDispatcher(new EZGameDispatcher(this)));
// if we don't need the no-show timer, start. // if we don't need the no-show timer, start.
@@ -549,8 +549,8 @@ public class EZGameManager extends GameManager
super.bodyEntered(bodyOid); super.bodyEntered(bodyOid);
// if we have no controller, then our new friend gets control // if we have no controller, then our new friend gets control
if (_gameObj.controllerOid == 0) { if (_ezObj.controllerOid == 0) {
_gameObj.setControllerOid(bodyOid); _ezObj.setControllerOid(bodyOid);
} }
} }
@@ -560,13 +560,13 @@ public class EZGameManager extends GameManager
super.bodyUpdated(info); super.bodyUpdated(info);
// if the controller just disconnected, reassign control // if the controller just disconnected, reassign control
if (info.status == OccupantInfo.DISCONNECTED && info.bodyOid == _gameObj.controllerOid) { if (info.status == OccupantInfo.DISCONNECTED && info.bodyOid == _ezObj.controllerOid) {
_gameObj.setControllerOid(getControllerOid()); _ezObj.setControllerOid(getControllerOid());
// if everyone in the room was disconnected and this client just reconnected, it becomes // if everyone in the room was disconnected and this client just reconnected, it becomes
// the new controller // the new controller
} else if (_gameObj.controllerOid == 0) { } else if (_ezObj.controllerOid == 0) {
_gameObj.setControllerOid(info.bodyOid); _ezObj.setControllerOid(info.bodyOid);
} }
} }
@@ -576,20 +576,20 @@ public class EZGameManager extends GameManager
super.bodyLeft(bodyOid); super.bodyLeft(bodyOid);
// if this player was the controller, reassign control // if this player was the controller, reassign control
if (bodyOid == _gameObj.controllerOid) { if (bodyOid == _ezObj.controllerOid) {
_gameObj.setControllerOid(getControllerOid()); _ezObj.setControllerOid(getControllerOid());
} }
// nix any of this player's cookies // nix any of this player's cookies
if (_gameObj.userCookies != null && _gameObj.userCookies.containsKey(bodyOid)) { if (_ezObj.userCookies != null && _ezObj.userCookies.containsKey(bodyOid)) {
_gameObj.removeFromUserCookies(bodyOid); _ezObj.removeFromUserCookies(bodyOid);
} }
} }
@Override @Override
protected void didShutdown () protected void didShutdown ()
{ {
CrowdServer.invmgr.clearDispatcher(_gameObj.ezGameService); CrowdServer.invmgr.clearDispatcher(_ezObj.ezGameService);
stopTickers(); stopTickers();
super.didShutdown(); super.didShutdown();
@@ -601,6 +601,10 @@ public class EZGameManager extends GameManager
stopTickers(); stopTickers();
super.gameDidEnd(); super.gameDidEnd();
// EZ games immediately resest to PRE_GAME after they end so that they can be restarted if
// desired by having all players call playerReady() again
_ezObj.setState(EZGameObject.PRE_GAME);
} }
@Override @Override
@@ -636,7 +640,7 @@ public class EZGameManager extends GameManager
*/ */
protected int getControllerOid () protected int getControllerOid ()
{ {
for (OccupantInfo info : _gameObj.occupantInfo) { for (OccupantInfo info : _ezObj.occupantInfo) {
if (info.status != OccupantInfo.DISCONNECTED) { if (info.status != OccupantInfo.DISCONNECTED) {
return info.bodyOid; return info.bodyOid;
} }
@@ -651,7 +655,7 @@ public class EZGameManager extends GameManager
{ {
if (_cookMgr == null) { if (_cookMgr == null) {
_cookMgr = createCookieManager(); _cookMgr = createCookieManager();
_gameObj.setUserCookies(new DSet<UserCookie>()); _ezObj.setUserCookies(new DSet<UserCookie>());
} }
return _cookMgr; return _cookMgr;
} }
@@ -712,7 +716,7 @@ public class EZGameManager extends GameManager
} // End: static class Ticker } // End: static class Ticker
/** A nice casted reference to the game object. */ /** A nice casted reference to the game object. */
protected EZGameObject _gameObj; protected EZGameObject _ezObj;
/** Our turn delegate. */ /** Our turn delegate. */
protected EZGameTurnDelegate _turnDelegate; protected EZGameTurnDelegate _turnDelegate;