Added support for handling games with multiple rounds.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@237 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2007-03-11 07:59:23 +00:00
parent b6c6b74d73
commit 5b77f2f95d
11 changed files with 223 additions and 99 deletions
+48 -14
View File
@@ -58,6 +58,13 @@ import flash.display.DisplayObject;
*/ */
[Event(name="GameStarted", type="com.threerings.ezgame.StateChangedEvent")] [Event(name="GameStarted", type="com.threerings.ezgame.StateChangedEvent")]
/**
* Dispatched when a round starts.
*
* @eventType com.threerings.ezgame.StateChangedEvent.ROUND_STARTED
*/
[Event(name="RoundStarted", type="com.threerings.ezgame.StateChangedEvent")]
/** /**
* Dispatched when the turn changes in a turn-based game. * Dispatched when the turn changes in a turn-based game.
* *
@@ -65,6 +72,13 @@ import flash.display.DisplayObject;
*/ */
[Event(name="TurnChanged", type="com.threerings.ezgame.StateChangedEvent")] [Event(name="TurnChanged", type="com.threerings.ezgame.StateChangedEvent")]
/**
* Dispatched when a round ends.
*
* @eventType com.threerings.ezgame.StateChangedEvent.ROUND_ENDED
*/
[Event(name="RoundEnded", type="com.threerings.ezgame.StateChangedEvent")]
/** /**
* Dispatched when the game ends. * Dispatched when the game ends.
* *
@@ -254,7 +268,9 @@ public class EZGameControl extends BaseControl
var scl :StateChangedListener = (obj as StateChangedListener); var scl :StateChangedListener = (obj as StateChangedListener);
addEventListener(StateChangedEvent.CONTROL_CHANGED, scl.stateChanged, false, 0, true); addEventListener(StateChangedEvent.CONTROL_CHANGED, scl.stateChanged, false, 0, true);
addEventListener(StateChangedEvent.GAME_STARTED, scl.stateChanged, false, 0, true); addEventListener(StateChangedEvent.GAME_STARTED, scl.stateChanged, false, 0, true);
addEventListener(StateChangedEvent.ROUND_STARTED, scl.stateChanged, false, 0, true);
addEventListener(StateChangedEvent.TURN_CHANGED, scl.stateChanged, false, 0, true); addEventListener(StateChangedEvent.TURN_CHANGED, scl.stateChanged, false, 0, true);
addEventListener(StateChangedEvent.ROUND_ENDED, scl.stateChanged, false, 0, true);
addEventListener(StateChangedEvent.GAME_ENDED, scl.stateChanged, false, 0, true); addEventListener(StateChangedEvent.GAME_ENDED, scl.stateChanged, false, 0, true);
} }
if (obj is OccupantChangedListener) { if (obj is OccupantChangedListener) {
@@ -282,12 +298,11 @@ public class EZGameControl extends BaseControl
} }
if (obj is StateChangedListener) { if (obj is StateChangedListener) {
var scl :StateChangedListener = (obj as StateChangedListener); var scl :StateChangedListener = (obj as StateChangedListener);
removeEventListener( removeEventListener(StateChangedEvent.GAME_STARTED, scl.stateChanged);
StateChangedEvent.GAME_STARTED, scl.stateChanged); removeEventListener(StateChangedEvent.ROUND_STARTED, scl.stateChanged);
removeEventListener( removeEventListener(StateChangedEvent.TURN_CHANGED, scl.stateChanged);
StateChangedEvent.TURN_CHANGED, scl.stateChanged); removeEventListener(StateChangedEvent.ROUND_ENDED, scl.stateChanged);
removeEventListener( removeEventListener(StateChangedEvent.GAME_ENDED, scl.stateChanged);
StateChangedEvent.GAME_ENDED, scl.stateChanged);
} }
if (obj is OccupantChangedListener) { if (obj is OccupantChangedListener) {
var ocl :OccupantChangedListener = (obj as OccupantChangedListener); var ocl :OccupantChangedListener = (obj as OccupantChangedListener);
@@ -426,6 +441,15 @@ public class EZGameControl extends BaseControl
return int(callEZCode("getTurnHolder_v1")); return int(callEZCode("getTurnHolder_v1"));
} }
/**
* Returns the current round number. Rounds start at 1 and increase if the game calls {@link
* #endRound} with a next round timeout.
*/
public function getRound () :int
{
return int(callEZCode("getRound_v1"));
}
/** /**
* Get the user-specific game data for the specified user. The first time this is requested per * Get the user-specific game data for the specified user. The first time this is requested per
* game instance it will be retrieved from the database. After that, it will be returned from * game instance it will be retrieved from the database. After that, it will be returned from
@@ -476,6 +500,15 @@ public class EZGameControl extends BaseControl
callEZCode("endTurn_v2", nextPlayerId); callEZCode("endTurn_v2", nextPlayerId);
} }
/**
* Ends the current round. If nextRoundDelay is greater than zero, the next round will be
* started in the specified number of seconds.
*/
public function endRound (nextRoundDelay :int = -1) :void
{
callEZCode("endRound_v1", nextRoundDelay);
}
/** /**
* End the game. The specified player ids are winners! * End the game. The specified player ids are winners!
*/ */
@@ -494,8 +527,8 @@ public class EZGameControl extends BaseControl
o["controlDidChange_v1"] = controlDidChange_v1; o["controlDidChange_v1"] = controlDidChange_v1;
o["turnDidChange_v1"] = turnDidChange_v1; o["turnDidChange_v1"] = turnDidChange_v1;
o["messageReceived_v1"] = messageReceived_v1; o["messageReceived_v1"] = messageReceived_v1;
o["gameDidStart_v1"] = gameDidStart_v1; o["gameStateChanged_v1"] = gameStateChanged_v1;
o["gameDidEnd_v1"] = gameDidEnd_v1; o["roundStateChanged_v1"] = roundStateChanged_v1;
o["dispatchEvent_v1"] = dispatch; o["dispatchEvent_v1"] = dispatch;
o["occupantChanged_v1"] = occupantChanged_v1; o["occupantChanged_v1"] = occupantChanged_v1;
} }
@@ -506,8 +539,7 @@ public class EZGameControl extends BaseControl
private function propertyWasSet_v1 ( private function propertyWasSet_v1 (
name :String, newValue :Object, oldValue :Object, index :int) :void name :String, newValue :Object, oldValue :Object, index :int) :void
{ {
dispatch( dispatch(new PropertyChangedEvent(this, name, newValue, oldValue, index));
new PropertyChangedEvent(this, name, newValue, oldValue, index));
} }
/** /**
@@ -537,17 +569,19 @@ public class EZGameControl extends BaseControl
/** /**
* Private method to post a StateChangedEvent. * Private method to post a StateChangedEvent.
*/ */
private function gameDidStart_v1 () :void private function gameStateChanged_v1 (started :Boolean) :void
{ {
dispatch(new StateChangedEvent(StateChangedEvent.GAME_STARTED, this)); dispatch(new StateChangedEvent(started ? StateChangedEvent.GAME_STARTED :
StateChangedEvent.GAME_ENDED, this));
} }
/** /**
* Private method to post a StateChangedEvent. * Private method to post a StateChangedEvent.
*/ */
private function gameDidEnd_v1 () :void private function roundStateChanged_v1 (started :Boolean) :void
{ {
dispatch(new StateChangedEvent(StateChangedEvent.GAME_ENDED, this)); dispatch(new StateChangedEvent(started ? StateChangedEvent.ROUND_STARTED :
StateChangedEvent.ROUND_ENDED, this));
} }
/** /**
@@ -34,6 +34,13 @@ public class StateChangedEvent extends EZEvent
/** Indicates that the game has transitioned to a ended state. */ /** Indicates that the game has transitioned to a ended state. */
public static const GAME_ENDED :String = "GameEnded"; public static const GAME_ENDED :String = "GameEnded";
/** Indicates that a round has started. Games that do not require multiple rounds can ignore
* this event. */
public static const ROUND_STARTED :String = "RoundStarted";
/** Indicates that the current round has ended. */
public static const ROUND_ENDED :String = "RoundEnded";
/** Indicates that a new controller has been assigned. */ /** Indicates that a new controller has been assigned. */
public static const CONTROL_CHANGED :String = "ControlChanged"; public static const CONTROL_CHANGED :String = "ControlChanged";
@@ -34,6 +34,7 @@ import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.util.CrowdContext; import com.threerings.crowd.util.CrowdContext;
import com.threerings.parlor.game.client.GameController; import com.threerings.parlor.game.client.GameController;
import com.threerings.parlor.game.data.GameObject;
import com.threerings.parlor.turn.client.TurnGameController; import com.threerings.parlor.turn.client.TurnGameController;
import com.threerings.parlor.turn.client.TurnGameControllerDelegate; import com.threerings.parlor.turn.client.TurnGameControllerDelegate;
@@ -88,6 +89,12 @@ public class EZGameController extends GameController
var name :String = event.getName(); var name :String = event.getName();
if (EZGameObject.CONTROLLER_OID == name) { if (EZGameObject.CONTROLLER_OID == name) {
_panel.backend.controlDidChange(); _panel.backend.controlDidChange();
} else if (GameObject.ROUND_ID == name) {
if ((event.getValue() as int) > 0) {
_panel.backend.roundStateChanged(true);
} else {
_panel.backend.roundStateChanged(false);
}
} else { } else {
super.attributeChanged(event); super.attributeChanged(event);
} }
@@ -113,14 +120,14 @@ public class EZGameController extends GameController
override protected function gameDidStart () :void override protected function gameDidStart () :void
{ {
super.gameDidStart(); super.gameDidStart();
_panel.backend.gameDidStart(); _panel.backend.gameStateChanged(true);
} }
// from GameController // from GameController
override protected function gameDidEnd () :void override protected function gameDidEnd () :void
{ {
super.gameDidEnd(); super.gameDidEnd();
_panel.backend.gameDidEnd(); _panel.backend.gameStateChanged(false);
} }
// from PlaceController // from PlaceController
@@ -45,6 +45,9 @@ public interface EZGameService extends InvocationService
// from Java interface EZGameService // from Java interface EZGameService
function endGame (arg1 :Client, arg2 :Array, arg3 :InvocationService_InvocationListener) :void; function endGame (arg1 :Client, arg2 :Array, arg3 :InvocationService_InvocationListener) :void;
// from Java interface EZGameService
function endRound (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void;
// from Java interface EZGameService // from Java interface EZGameService
function endTurn (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void; function endTurn (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void;
@@ -192,8 +192,10 @@ public class GameControlBackend
o["getControllerId_v1"] = getControllerId_v1; o["getControllerId_v1"] = getControllerId_v1;
o["getUserCookie_v2"] = getUserCookie_v2; o["getUserCookie_v2"] = getUserCookie_v2;
o["endTurn_v2"] = endTurn_v2; o["endTurn_v2"] = endTurn_v2;
o["endRound_v1"] = endRound_v1;
o["endGame_v2"] = endGame_v2; o["endGame_v2"] = endGame_v2;
o["getTurnHolder_v1"] = getTurnHolder_v1; o["getTurnHolder_v1"] = getTurnHolder_v1;
o["getRound_v1"] = getRound_v1;
o["getOccupantName_v1"] = getOccupantName_v1; o["getOccupantName_v1"] = getOccupantName_v1;
o["getPlayers_v1"] = getPlayers_v1; o["getPlayers_v1"] = getPlayers_v1;
o["getPlayerPosition_v1"] = getPlayerPosition_v1; o["getPlayerPosition_v1"] = getPlayerPosition_v1;
@@ -347,6 +349,11 @@ public class GameControlBackend
return (occInfo == null) ? 0 : occInfo.bodyOid; return (occInfo == null) ? 0 : occInfo.bodyOid;
} }
public function getRound_v1 () :int
{
return _ezObj.roundId;
}
public function getUserCookie_v2 ( public function getUserCookie_v2 (
playerId :int, callback :Function) :void playerId :int, callback :Function) :void
{ {
@@ -401,8 +408,14 @@ public class GameControlBackend
public function endTurn_v2 (nextPlayerId :int) :void public function endTurn_v2 (nextPlayerId :int) :void
{ {
_ezObj.ezGameService.endTurn(_ctx.getClient(), nextPlayerId, _ezObj.ezGameService.endTurn(
createLoggingConfirmListener("endTurn")); _ctx.getClient(), nextPlayerId, createLoggingConfirmListener("endTurn"));
}
public function endRound_v1 (nextRoundDelay :int) :void
{
_ezObj.ezGameService.endRound(
_ctx.getClient(), nextRoundDelay, createLoggingConfirmListener("endRound"));
} }
public function endGame_v2 (... winnerIds) :void public function endGame_v2 (... winnerIds) :void
@@ -411,12 +424,11 @@ public class GameControlBackend
while (winnerIds.length > 0) { while (winnerIds.length > 0) {
winners.push(int(winnerIds.shift())); winners.push(int(winnerIds.shift()));
} }
_ezObj.ezGameService.endGame(_ctx.getClient(), winners, _ezObj.ezGameService.endGame(
createLoggingConfirmListener("endGame")); _ctx.getClient(), winners, createLoggingConfirmListener("endGame"));
} }
public function getDictionaryLetterSet_v1 ( public function getDictionaryLetterSet_v1 (locale :String, count :int, callback :Function) :void
locale :String, count :int, callback :Function) :void
{ {
var listener :InvocationService_ResultListener; var listener :InvocationService_ResultListener;
if (callback != null) { if (callback != null) {
@@ -682,19 +694,25 @@ public class GameControlBackend
} }
/** /**
* Called by the EZGameController when the game starts. * Called by the EZGameController when the game starts or ends.
*/ */
public function gameDidStart () :void public function gameStateChanged (started :Boolean) :void
{ {
callUserCode("gameDidStart_v1"); if (started && _userFuncs["gameDidStart_v1"] != null) {
callUserCode("gameDidStart_v1"); // backwards compatibility
} else if (!started && _userFuncs["gameDidEnd_v1"] != null) {
callUserCode("gameDidEnd_v1"); // backwards compatibility
} else {
callUserCode("gameStateChanged_v1", started); // new hotness
}
} }
/** /**
* Called by the EZGameController when the game ends. * Called by the EZGameController when a round starts or ends.
*/ */
public function gameDidEnd () :void public function roundStateChanged (started :Boolean) :void
{ {
callUserCode("gameDidEnd_v1"); callUserCode("roundStateChanged_v1", started);
} }
// from SetListener // from SetListener
@@ -83,8 +83,21 @@ public class EZGameMarshaller extends InvocationMarshaller
]); ]);
} }
/** The method id used to dispatch {@link #endRound} requests. */
public static const END_ROUND :int = 4;
// from interface EZGameService
public function endRound (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void
{
var listener3 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
listener3.listener = arg3;
sendRequest(arg1, END_ROUND, [
Integer.valueOf(arg2), listener3
]);
}
/** The method id used to dispatch {@link #endTurn} requests. */ /** The method id used to dispatch {@link #endTurn} requests. */
public static const END_TURN :int = 4; public static const END_TURN :int = 5;
// from interface EZGameService // from interface EZGameService
public function endTurn (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void public function endTurn (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void
@@ -97,7 +110,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #getCookie} requests. */ /** The method id used to dispatch {@link #getCookie} requests. */
public static const GET_COOKIE :int = 5; public static const GET_COOKIE :int = 6;
// from interface EZGameService // from interface EZGameService
public function getCookie (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void public function getCookie (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void
@@ -110,7 +123,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #getDictionaryLetterSet} requests. */ /** The method id used to dispatch {@link #getDictionaryLetterSet} requests. */
public static const GET_DICTIONARY_LETTER_SET :int = 6; public static const GET_DICTIONARY_LETTER_SET :int = 7;
// from interface EZGameService // from interface EZGameService
public function getDictionaryLetterSet (arg1 :Client, arg2 :String, arg3 :int, arg4 :InvocationService_ResultListener) :void public function getDictionaryLetterSet (arg1 :Client, arg2 :String, arg3 :int, arg4 :InvocationService_ResultListener) :void
@@ -123,7 +136,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #getFromCollection} requests. */ /** The method id used to dispatch {@link #getFromCollection} requests. */
public static const GET_FROM_COLLECTION :int = 7; public static const GET_FROM_COLLECTION :int = 8;
// from interface EZGameService // from interface EZGameService
public function getFromCollection (arg1 :Client, arg2 :String, arg3 :Boolean, arg4 :int, arg5 :String, arg6 :int, arg7 :InvocationService_ConfirmListener) :void public function getFromCollection (arg1 :Client, arg2 :String, arg3 :Boolean, arg4 :int, arg5 :String, arg6 :int, arg7 :InvocationService_ConfirmListener) :void
@@ -136,7 +149,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #mergeCollection} requests. */ /** The method id used to dispatch {@link #mergeCollection} requests. */
public static const MERGE_COLLECTION :int = 8; public static const MERGE_COLLECTION :int = 9;
// from interface EZGameService // from interface EZGameService
public function mergeCollection (arg1 :Client, arg2 :String, arg3 :String, arg4 :InvocationService_InvocationListener) :void public function mergeCollection (arg1 :Client, arg2 :String, arg3 :String, arg4 :InvocationService_InvocationListener) :void
@@ -149,7 +162,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #sendMessage} requests. */ /** The method id used to dispatch {@link #sendMessage} requests. */
public static const SEND_MESSAGE :int = 9; public static const SEND_MESSAGE :int = 10;
// from interface EZGameService // from interface EZGameService
public function sendMessage (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :InvocationService_InvocationListener) :void public function sendMessage (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :InvocationService_InvocationListener) :void
@@ -162,7 +175,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #setCookie} requests. */ /** The method id used to dispatch {@link #setCookie} requests. */
public static const SET_COOKIE :int = 10; public static const SET_COOKIE :int = 11;
// from interface EZGameService // from interface EZGameService
public function setCookie (arg1 :Client, arg2 :ByteArray, arg3 :InvocationService_InvocationListener) :void public function setCookie (arg1 :Client, arg2 :ByteArray, arg3 :InvocationService_InvocationListener) :void
@@ -175,7 +188,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #setProperty} requests. */ /** The method id used to dispatch {@link #setProperty} requests. */
public static const SET_PROPERTY :int = 11; public static const SET_PROPERTY :int = 12;
// from interface EZGameService // from interface EZGameService
public function setProperty (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :Boolean, arg6 :Object, arg7 :InvocationService_InvocationListener) :void public function setProperty (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :Boolean, arg6 :Object, arg7 :InvocationService_InvocationListener) :void
@@ -188,7 +201,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #setTicker} requests. */ /** The method id used to dispatch {@link #setTicker} requests. */
public static const SET_TICKER :int = 12; public static const SET_TICKER :int = 13;
// from interface EZGameService // from interface EZGameService
public function setTicker (arg1 :Client, arg2 :String, arg3 :int, arg4 :InvocationService_InvocationListener) :void public function setTicker (arg1 :Client, arg2 :String, arg3 :int, arg4 :InvocationService_InvocationListener) :void
@@ -32,48 +32,45 @@ public interface EZGameService extends InvocationService
/** /**
* Request to set the specified property. * Request to set the specified property.
* *
* @param value either a byte[] if setting a non-array property * @param value either a byte[] if setting a non-array property or a property at an array
* or a property at an array index, or a byte[][] if setting * index, or a byte[][] if setting an array property where index is -1.
* an array property where index is -1.
*/ */
public void setProperty ( public void setProperty (Client client, String propName, Object value, int index,
Client client, String propName, Object value, int index, boolean testAndSet, Object testValue, InvocationListener listener);
boolean testAndSet, Object testValue, InvocationListener listener);
/** /**
* Request to end the turn, possibly futzing the next turn holder unless * Request to end the turn, possibly futzing the next turn holder unless -1 is specified for
* -1 is specified for the nextPlayerIndex. * the nextPlayerIndex.
*/ */
public void endTurn ( public void endTurn (Client client, int nextPlayerId, InvocationListener listener);
Client client, int nextPlayerId, InvocationListener listener);
/** /**
* Request to end the game, with the specified player oids assigned * Requests to end the current round. If nextRoundDelay is greater than zero, the next round
* as winners. * will be started in the specified number of seconds.
*/ */
public void endGame ( public void endRound (Client client, int nextRoundDelay, InvocationListener listener);
Client client, int[] winnerOids, InvocationListener listener);
/** /**
* Request to send a private message to one other player in * Request to end the game, with the specified player oids assigned as winners.
* the game. */
public void endGame (Client client, int[] winnerOids, InvocationListener listener);
/**
* Request to send a private message to one other player in the game.
* *
* @param value either a byte[] if setting a non-array property * @param value either a byte[] if setting a non-array property or a property at an array
* or a property at an array index, or a byte[][] if setting * index, or a byte[][] if setting an array property where index is -1.
* an array property where index is -1.
*/ */
public void sendMessage ( public void sendMessage (Client client, String msgName, Object value, int playerId,
Client client, String msgName, Object value, int playerId, InvocationListener listener);
InvocationListener listener);
/** /**
* Ask the dictionary service for a set of random letters * Ask the dictionary service for a set of random letters appropriate for the given
* appropriate for the given language/culture settings. These will be * language/culture settings. These will be returned via a message back to the caller.
* returned via a message back to the caller.
* *
* @param client stores information about the caller * @param client stores information about the caller
* @param locale is an RFC 3066 string specifying language settings, * @param locale is an RFC 3066 string specifying language settings, for example, "en" or
* for example, "en" or "en-us". * "en-us".
* @param count is the number of letters to be returned. * @param count is the number of letters to be returned.
* @param listener is the callback function * @param listener is the callback function
*/ */
@@ -81,13 +78,12 @@ public interface EZGameService extends InvocationService
Client client, String locale, int count, ResultListener listener); Client client, String locale, int count, ResultListener listener);
/** /**
* Ask the dictionary service whether the specified word is valid * Ask the dictionary service whether the specified word is valid with the given
* with the given language/culture settings. The result will be returned * language/culture settings. The result will be returned via a message back to the caller.
* via a message back to the caller.
* *
* @param client stores information about the caller * @param client stores information about the caller
* @param locale is an RFC 3066 string specifying language settings, * @param locale is an RFC 3066 string specifying language settings, for example, "en" or
* for example, "en" or "en-us". * "en-us".
* @param word is the word to be checked against the dictionary. * @param word is the word to be checked against the dictionary.
* @param listener is the callback function * @param listener is the callback function
*/ */
@@ -99,46 +95,39 @@ public interface EZGameService extends InvocationService
* *
* @param clearExisting if true, wipe the old contents. * @param clearExisting if true, wipe the old contents.
*/ */
public void addToCollection ( public void addToCollection (Client client, String collName, byte[][] data,
Client client, String collName, byte[][] data, boolean clearExisting, boolean clearExisting, InvocationListener listener);
InvocationListener listener);
/** /**
* Merge the specified collection into the other. * Merge the specified collection into the other.
*/ */
public void mergeCollection ( public void mergeCollection (
Client client, String srcColl, String intoColl, Client client, String srcColl, String intoColl, InvocationListener listener);
InvocationListener listener);
/** /**
* Pick or deal some number of elements from the specified collection, * Pick or deal some number of elements from the specified collection, and either set a
* and either set a property in the flash object, or delivery the * property in the flash object, or delivery the picks to the specified player index via a game
* picks to the specified player index via a game message. * message.
*/ */
public void getFromCollection ( public void getFromCollection (Client client, String collName, boolean consume, int count,
Client client, String collName, boolean consume, int count, String msgOrPropName, int playerId, ConfirmListener listener);
String msgOrPropName, int playerId, ConfirmListener listener);
/** /**
* Start a ticker that will send out timestamp information at * Start a ticker that will send out timestamp information at the interval specified.
* the interval specified.
* *
* @param msOfDelay must be at least 50, or 0 may be set to halt * @param msOfDelay must be at least 50, or 0 may be set to halt and clear a previously started
* and clear a previously started ticker. * ticker.
*/ */
public void setTicker ( public void setTicker (
Client client, String tickerName, int msOfDelay, Client client, String tickerName, int msOfDelay, InvocationListener listener);
InvocationListener listener);
/** /**
* Request to get the specified user's cookie. * Request to get the specified user's cookie.
*/ */
public void getCookie ( public void getCookie (Client client, int playerId, InvocationListener listener);
Client client, int playerId, InvocationListener listener);
/** /**
* Request to set our cookie. * Request to set our cookie.
*/ */
public void setCookie ( public void setCookie (Client client, byte[] cookie, InvocationListener listener);
Client client, byte[] cookie, InvocationListener listener);
} }
@@ -76,8 +76,21 @@ public class EZGameMarshaller extends InvocationMarshaller
}); });
} }
/** The method id used to dispatch {@link #endRound} requests. */
public static final int END_ROUND = 4;
// from interface EZGameService
public void endRound (Client arg1, int arg2, InvocationService.InvocationListener arg3)
{
ListenerMarshaller listener3 = new ListenerMarshaller();
listener3.listener = arg3;
sendRequest(arg1, END_ROUND, new Object[] {
Integer.valueOf(arg2), listener3
});
}
/** The method id used to dispatch {@link #endTurn} requests. */ /** The method id used to dispatch {@link #endTurn} requests. */
public static final int END_TURN = 4; public static final int END_TURN = 5;
// from interface EZGameService // from interface EZGameService
public void endTurn (Client arg1, int arg2, InvocationService.InvocationListener arg3) public void endTurn (Client arg1, int arg2, InvocationService.InvocationListener arg3)
@@ -90,7 +103,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #getCookie} requests. */ /** The method id used to dispatch {@link #getCookie} requests. */
public static final int GET_COOKIE = 5; public static final int GET_COOKIE = 6;
// from interface EZGameService // from interface EZGameService
public void getCookie (Client arg1, int arg2, InvocationService.InvocationListener arg3) public void getCookie (Client arg1, int arg2, InvocationService.InvocationListener arg3)
@@ -103,7 +116,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #getDictionaryLetterSet} requests. */ /** The method id used to dispatch {@link #getDictionaryLetterSet} requests. */
public static final int GET_DICTIONARY_LETTER_SET = 6; public static final int GET_DICTIONARY_LETTER_SET = 7;
// from interface EZGameService // from interface EZGameService
public void getDictionaryLetterSet (Client arg1, String arg2, int arg3, InvocationService.ResultListener arg4) public void getDictionaryLetterSet (Client arg1, String arg2, int arg3, InvocationService.ResultListener arg4)
@@ -116,7 +129,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #getFromCollection} requests. */ /** The method id used to dispatch {@link #getFromCollection} requests. */
public static final int GET_FROM_COLLECTION = 7; public static final int GET_FROM_COLLECTION = 8;
// from interface EZGameService // from interface EZGameService
public void getFromCollection (Client arg1, String arg2, boolean arg3, int arg4, String arg5, int arg6, InvocationService.ConfirmListener arg7) public void getFromCollection (Client arg1, String arg2, boolean arg3, int arg4, String arg5, int arg6, InvocationService.ConfirmListener arg7)
@@ -129,7 +142,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #mergeCollection} requests. */ /** The method id used to dispatch {@link #mergeCollection} requests. */
public static final int MERGE_COLLECTION = 8; public static final int MERGE_COLLECTION = 9;
// from interface EZGameService // from interface EZGameService
public void mergeCollection (Client arg1, String arg2, String arg3, InvocationService.InvocationListener arg4) public void mergeCollection (Client arg1, String arg2, String arg3, InvocationService.InvocationListener arg4)
@@ -142,7 +155,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #sendMessage} requests. */ /** The method id used to dispatch {@link #sendMessage} requests. */
public static final int SEND_MESSAGE = 9; public static final int SEND_MESSAGE = 10;
// from interface EZGameService // from interface EZGameService
public void sendMessage (Client arg1, String arg2, Object arg3, int arg4, InvocationService.InvocationListener arg5) public void sendMessage (Client arg1, String arg2, Object arg3, int arg4, InvocationService.InvocationListener arg5)
@@ -155,7 +168,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #setCookie} requests. */ /** The method id used to dispatch {@link #setCookie} requests. */
public static final int SET_COOKIE = 10; public static final int SET_COOKIE = 11;
// from interface EZGameService // from interface EZGameService
public void setCookie (Client arg1, byte[] arg2, InvocationService.InvocationListener arg3) public void setCookie (Client arg1, byte[] arg2, InvocationService.InvocationListener arg3)
@@ -168,7 +181,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #setProperty} requests. */ /** The method id used to dispatch {@link #setProperty} requests. */
public static final int SET_PROPERTY = 11; public static final int SET_PROPERTY = 12;
// from interface EZGameService // from interface EZGameService
public void setProperty (Client arg1, String arg2, Object arg3, int arg4, boolean arg5, Object arg6, InvocationService.InvocationListener arg7) public void setProperty (Client arg1, String arg2, Object arg3, int arg4, boolean arg5, Object arg6, InvocationService.InvocationListener arg7)
@@ -181,7 +194,7 @@ public class EZGameMarshaller extends InvocationMarshaller
} }
/** The method id used to dispatch {@link #setTicker} requests. */ /** The method id used to dispatch {@link #setTicker} requests. */
public static final int SET_TICKER = 12; public static final int SET_TICKER = 13;
// from interface EZGameService // from interface EZGameService
public void setTicker (Client arg1, String arg2, int arg3, InvocationService.InvocationListener arg4) public void setTicker (Client arg1, String arg2, int arg3, InvocationService.InvocationListener arg4)
@@ -77,6 +77,13 @@ public class EZGameDispatcher extends InvocationDispatcher
); );
return; return;
case EZGameMarshaller.END_ROUND:
((EZGameProvider)provider).endRound(
source,
((Integer)args[0]).intValue(), (InvocationService.InvocationListener)args[1]
);
return;
case EZGameMarshaller.END_TURN: case EZGameMarshaller.END_TURN:
((EZGameProvider)provider).endTurn( ((EZGameProvider)provider).endTurn(
source, source,
@@ -110,6 +110,33 @@ public class EZGameManager extends GameManager
_turnDelegate.endTurn(nextTurnHolder); _turnDelegate.endTurn(nextTurnHolder);
} }
// from EZGameProvider
public void endRound (ClientObject caller, int nextRoundDelay,
InvocationService.InvocationListener listener)
throws InvocationException
{
validateStateModification(caller, false);
// let the game know that it is doing something stupid
if (_gameObj.roundId < 0) {
throw new InvocationException("m.round_already_ended");
}
// while we are between rounds, our round id is the negation of the round that just ended
_gameObj.setRoundId(-_gameObj.roundId);
// queue up the start of the next round if requested
if (nextRoundDelay > 0) {
new Interval(CrowdServer.omgr) {
public void expired () {
if (_gameObj.isInPlay()) {
_gameObj.setRoundId(-_gameObj.roundId + 1);
}
}
}.schedule(nextRoundDelay * 1000L);
}
}
// from EZGameProvider // from EZGameProvider
public void endGame (ClientObject caller, int[] winnerOids, public void endGame (ClientObject caller, int[] winnerOids,
InvocationService.InvocationListener listener) InvocationService.InvocationListener listener)
@@ -51,6 +51,12 @@ public interface EZGameProvider extends InvocationProvider
public void endGame (ClientObject caller, int[] arg1, InvocationService.InvocationListener arg2) public void endGame (ClientObject caller, int[] arg1, InvocationService.InvocationListener arg2)
throws InvocationException; throws InvocationException;
/**
* Handles a {@link EZGameService#endRound} request.
*/
public void endRound (ClientObject caller, int arg1, InvocationService.InvocationListener arg2)
throws InvocationException;
/** /**
* Handles a {@link EZGameService#endTurn} request. * Handles a {@link EZGameService#endTurn} request.
*/ */