EZGameControl updates:
- switched everything to be based on playerId instead of index (which doesn't make sense for a party game.) - started adding new functions - backwards compatible with all old games! git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@186 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -282,17 +282,17 @@ public class EZGameControl extends EventDispatcher
|
|||||||
* @param count the number of elements to pick
|
* @param count the number of elements to pick
|
||||||
* @param msgOrPropName the name of the message or property
|
* @param msgOrPropName the name of the message or property
|
||||||
* that will contain the picked elements.
|
* that will contain the picked elements.
|
||||||
* @param playerIndex if -1 (or unset), the picked elements should be
|
* @param playerId if 0 (or unset), the picked elements should be
|
||||||
* set on the gameObject as a property for all to see.
|
* set on the gameObject as a property for all to see.
|
||||||
* If a playerIndex is specified, only that player will receive
|
* If a playerId is specified, only that player will receive
|
||||||
* the elements as a message.
|
* the elements as a message.
|
||||||
*/
|
*/
|
||||||
// TODO: a way to specify exclusive picks vs. duplicate-OK picks?
|
// TODO: a way to specify exclusive picks vs. duplicate-OK picks?
|
||||||
public function pickFromCollection (
|
public function pickFromCollection (
|
||||||
collName :String, count :int, msgOrPropName :String,
|
collName :String, count :int, msgOrPropName :String,
|
||||||
playerIndex :int = -1) :void
|
playerId :int = 0) :void
|
||||||
{
|
{
|
||||||
getFromCollection(collName, count, msgOrPropName, playerIndex,
|
getFromCollection(collName, count, msgOrPropName, playerId,
|
||||||
false, null);
|
false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,17 +305,17 @@ public class EZGameControl extends EventDispatcher
|
|||||||
* @param count the number of elements to pick
|
* @param count the number of elements to pick
|
||||||
* @param msgOrPropName the name of the message or property
|
* @param msgOrPropName the name of the message or property
|
||||||
* that will contain the picked elements.
|
* that will contain the picked elements.
|
||||||
* @param playerIndex if -1 (or unset), the picked elements should be
|
* @param playerId if 0 (or unset), the picked elements should be
|
||||||
* set on the gameObject as a property for all to see.
|
* set on the gameObject as a property for all to see.
|
||||||
* If a playerIndex is specified, only that player will receive
|
* If a playerId is specified, only that player will receive
|
||||||
* the elements as a message.
|
* the elements as a message.
|
||||||
*/
|
*/
|
||||||
// TODO: figure out the method signature of the callback
|
// TODO: figure out the method signature of the callback
|
||||||
public function dealFromCollection (
|
public function dealFromCollection (
|
||||||
collName :String, count :int, msgOrPropName :String,
|
collName :String, count :int, msgOrPropName :String,
|
||||||
callback :Function = null, playerIndex :int = -1) :void
|
callback :Function = null, playerId :int = 0) :void
|
||||||
{
|
{
|
||||||
getFromCollection(collName, count, msgOrPropName, playerIndex,
|
getFromCollection(collName, count, msgOrPropName, playerId,
|
||||||
true, callback);
|
true, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,13 +336,13 @@ public class EZGameControl extends EventDispatcher
|
|||||||
* value will not be saved- it will merely end up coming out
|
* value will not be saved- it will merely end up coming out
|
||||||
* as a MessageReceivedEvent.
|
* as a MessageReceivedEvent.
|
||||||
*
|
*
|
||||||
* @param playerIndex if -1, sends to all players, otherwise
|
* @param playerId if 0 (or unset), sends to all players, otherwise
|
||||||
* the message will be private to just one player
|
* the message will be private to just one player
|
||||||
*/
|
*/
|
||||||
public function sendMessage (
|
public function sendMessage (
|
||||||
messageName :String, value :Object, playerIndex :int = -1) :void
|
messageName :String, value :Object, playerId :int = 0) :void
|
||||||
{
|
{
|
||||||
callEZCode("sendMessage_v1", messageName, value, playerIndex);
|
callEZCode("sendMessage_v2", messageName, value, playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -382,45 +382,52 @@ public class EZGameControl extends EventDispatcher
|
|||||||
callEZCode("localChat_v1", msg);
|
callEZCode("localChat_v1", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// TODO: NEW
|
||||||
* Get the number of players currently in the game.
|
public function getOccupants () :Array /* of playerId */
|
||||||
*/
|
|
||||||
public function getPlayerCount () :int
|
|
||||||
{
|
{
|
||||||
return int(callEZCode("getPlayerCount_v1"));
|
return (callEZCode("getOccupants_v1") as Array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: NEW
|
||||||
/**
|
/**
|
||||||
* Get the player names, as an array.
|
* Get the display name of the specified occupant.
|
||||||
|
* Two players may have the same name: always use playerId to
|
||||||
|
* purposes of identification and comparison. The name is for display
|
||||||
|
* only.
|
||||||
*/
|
*/
|
||||||
public function getPlayerNames () :Array
|
public function getOccupantName (playerId :int) :String
|
||||||
{
|
{
|
||||||
return (callEZCode("getPlayerNames_v1") as Array);
|
return String(callEZCode("getOccupantName_v1", playerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: NEW: Table control
|
||||||
/**
|
/**
|
||||||
* Get the index into the player names array of the current player,
|
* Get the player's position, or -1 if not a player.
|
||||||
* or -1 if the user is not a player.
|
|
||||||
*/
|
*/
|
||||||
public function getMyIndex () :int
|
public function getPlayerPosition (playerId :int) :int
|
||||||
{
|
{
|
||||||
return int(callEZCode("getMyIndex_v1"));
|
return int(callEZCode("getPlayerPosition_v1", playerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: NEW: Table control
|
||||||
/**
|
/**
|
||||||
* Get the turn holder's index, or -1 if it's nobody's turn.
|
* Get all the players at the table, in their seated position.
|
||||||
|
* Absent players will be represented by a 0.
|
||||||
*/
|
*/
|
||||||
public function getTurnHolderIndex () :int
|
public function getPlayers () :Array /* of playerId (int) */
|
||||||
{
|
{
|
||||||
return int(callEZCode("getTurnHolderIndex_v1"));
|
return (callEZCode("getPlayers_v1") as Array);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// TODO: NEW
|
||||||
* Get the indexes of the winners
|
public function getMyId () :int
|
||||||
*/
|
|
||||||
public function getWinnerIndexes () :Array /* of int */
|
|
||||||
{
|
{
|
||||||
return (callEZCode("getWinnerIndexes_v1") as Array);
|
return int(callEZCode("getMyId_v1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTurnHolder () :int
|
||||||
|
{
|
||||||
|
return int(callEZCode("getTurnHolder_v1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -428,9 +435,9 @@ public class EZGameControl extends EventDispatcher
|
|||||||
* first time this is requested per game instance it will be retrieved
|
* first time this is requested per game instance it will be retrieved
|
||||||
* from the database. After that, it will be returned from memory.
|
* from the database. After that, it will be returned from memory.
|
||||||
*/
|
*/
|
||||||
public function getUserCookie (playerIndex :int, callback :Function) :void
|
public function getUserCookie (playerId :int, callback :Function) :void
|
||||||
{
|
{
|
||||||
callEZCode("getUserCookie_v1", playerIndex, callback);
|
callEZCode("getUserCookie_v1", playerId, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -469,21 +476,21 @@ public class EZGameControl extends EventDispatcher
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End the current turn. If no next player index is specified,
|
* End the current turn. If no next player id is specified,
|
||||||
* then the next player after the current one is used.
|
* then the next player after the current one is used.
|
||||||
*/
|
*/
|
||||||
public function endTurn (nextPlayerIndex :int = -1) :void
|
public function endTurn (nextPlayerId :int = 0) :void
|
||||||
{
|
{
|
||||||
callEZCode("endTurn_v1", nextPlayerIndex);
|
callEZCode("endTurn_v2", nextPlayerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End the game. The specified player indexes are winners!
|
* End the game. The specified player ids are winners!
|
||||||
*/
|
*/
|
||||||
public function endGame (... winnerIndexes) :void
|
public function endGame (... winnerIds) :void
|
||||||
{
|
{
|
||||||
var args :Array = winnerIndexes;
|
var args :Array = winnerIds;
|
||||||
args.unshift("endGame_v1");
|
args.unshift("endGame_v2");
|
||||||
|
|
||||||
// goddamn var-args complications in actionscript
|
// goddamn var-args complications in actionscript
|
||||||
callEZCode.apply(null, args);
|
callEZCode.apply(null, args);
|
||||||
@@ -513,12 +520,12 @@ public class EZGameControl extends EventDispatcher
|
|||||||
/**
|
/**
|
||||||
* Helper method for pickFromCollection and dealFromCollection.
|
* Helper method for pickFromCollection and dealFromCollection.
|
||||||
*/
|
*/
|
||||||
protected function getFromCollection(
|
protected function getFromCollection (
|
||||||
collName :String, count :int, msgOrPropName :String, playerIndex :int,
|
collName :String, count :int, msgOrPropName :String, playerId :int,
|
||||||
consume :Boolean, callback :Function) :void
|
consume :Boolean, callback :Function) :void
|
||||||
{
|
{
|
||||||
callEZCode("getFromCollection_v1", collName, count, msgOrPropName,
|
callEZCode("getFromCollection_v2", collName, count, msgOrPropName,
|
||||||
playerIndex, consume, callback);
|
playerId, consume, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -61,11 +61,13 @@ public class PlayersDisplay extends Sprite
|
|||||||
maxWidth = label.textWidth;
|
maxWidth = label.textWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var players :Array = _gameCtrl.getPlayers();
|
||||||
|
|
||||||
// create a label for each player
|
// create a label for each player
|
||||||
var playerIndex :int = 0;
|
for each (var playerId :int in players) {
|
||||||
for each (var name :String in _gameCtrl.getPlayerNames()) {
|
var name :String = _gameCtrl.getOccupantName(playerId);
|
||||||
label = createPlayerLabel(playerIndex, name);
|
label = createPlayerLabel(playerId, name);
|
||||||
icon = createPlayerIcon(playerIndex, name);
|
icon = createPlayerIcon(playerId, name);
|
||||||
var iconW :int = 0;
|
var iconW :int = 0;
|
||||||
var iconH :int = 0;
|
var iconH :int = 0;
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
@@ -83,7 +85,6 @@ public class PlayersDisplay extends Sprite
|
|||||||
maxWidth = Math.max(maxWidth, iconW + label.textWidth);
|
maxWidth = Math.max(maxWidth, iconW + label.textWidth);
|
||||||
|
|
||||||
_playerLabels.push(label);
|
_playerLabels.push(label);
|
||||||
playerIndex++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make all the player labels the same width
|
// make all the player labels the same width
|
||||||
@@ -123,7 +124,7 @@ public class PlayersDisplay extends Sprite
|
|||||||
/**
|
/**
|
||||||
* Create a TextArea that will be used to display player names.
|
* Create a TextArea that will be used to display player names.
|
||||||
*/
|
*/
|
||||||
protected function createPlayerLabel (idx :int, name :String) :TextField
|
protected function createPlayerLabel (playerId :int, name :String) :TextField
|
||||||
{
|
{
|
||||||
var label :TextField = new TextField();
|
var label :TextField = new TextField();
|
||||||
label.autoSize = TextFieldAutoSize.LEFT;
|
label.autoSize = TextFieldAutoSize.LEFT;
|
||||||
@@ -133,7 +134,7 @@ public class PlayersDisplay extends Sprite
|
|||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createPlayerIcon (idx :int, name :String) :DisplayObject
|
protected function createPlayerIcon (playerId :int, name :String) :DisplayObject
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -159,7 +160,7 @@ public class PlayersDisplay extends Sprite
|
|||||||
*/
|
*/
|
||||||
protected function displayCurrentTurn () :void
|
protected function displayCurrentTurn () :void
|
||||||
{
|
{
|
||||||
var idx :int = _gameCtrl.isInPlay() ? _gameCtrl.getTurnHolderIndex() : -1;
|
var idx :int = _gameCtrl.isInPlay() ? _gameCtrl.getPlayerPosition(_gameCtrl.getTurnHolder()) : -1;
|
||||||
for (var ii :int = 0; ii < _playerLabels.length; ii++) {
|
for (var ii :int = 0; ii < _playerLabels.length; ii++) {
|
||||||
var label :TextField = (_playerLabels[ii] as TextField);
|
var label :TextField = (_playerLabels[ii] as TextField);
|
||||||
label.backgroundColor = getBackground(ii == idx);
|
label.backgroundColor = getBackground(ii == idx);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import flash.utils.getQualifiedSuperclassName;
|
|||||||
|
|
||||||
import com.threerings.io.TypedArray;
|
import com.threerings.io.TypedArray;
|
||||||
|
|
||||||
|
import com.threerings.util.ArrayUtil;
|
||||||
import com.threerings.util.ClassUtil;
|
import com.threerings.util.ClassUtil;
|
||||||
import com.threerings.util.Integer;
|
import com.threerings.util.Integer;
|
||||||
import com.threerings.util.Iterator;
|
import com.threerings.util.Iterator;
|
||||||
@@ -125,27 +126,40 @@ public class GameControlBackend
|
|||||||
// functions
|
// functions
|
||||||
o["setProperty_v1"] = setProperty_v1;
|
o["setProperty_v1"] = setProperty_v1;
|
||||||
o["mergeCollection_v1"] = mergeCollection_v1;
|
o["mergeCollection_v1"] = mergeCollection_v1;
|
||||||
o["sendMessage_v1"] = sendMessage_v1;
|
|
||||||
o["setTicker_v1"] = setTicker_v1;
|
o["setTicker_v1"] = setTicker_v1;
|
||||||
o["sendChat_v1"] = sendChat_v1;
|
o["sendChat_v1"] = sendChat_v1;
|
||||||
o["localChat_v1"] = localChat_v1;
|
o["localChat_v1"] = localChat_v1;
|
||||||
o["getPlayerCount_v1"] = getPlayerCount_v1;
|
o["setUserCookie_v1"] = setUserCookie_v1;
|
||||||
|
o["isMyTurn_v1"] = isMyTurn_v1;
|
||||||
|
o["isInPlay_v1"] = isInPlay_v1;
|
||||||
|
o["getDictionaryLetterSet_v1"] = getDictionaryLetterSet_v1;
|
||||||
|
o["checkDictionaryWord_v1"] = checkDictionaryWord_v1;
|
||||||
|
o["populateCollection_v1"] = populateCollection_v1;
|
||||||
|
o["alterKeyEvents_v1"] = alterKeyEvents_v1;
|
||||||
|
o["focusContainer_v1"] = focusContainer_v1;
|
||||||
|
|
||||||
|
// newest
|
||||||
|
o["getFromCollection_v2"] = getFromCollection_v2;
|
||||||
|
o["sendMessage_v2"] = sendMessage_v2;
|
||||||
|
o["getOccupants_v1"] = getOccupants_v1;
|
||||||
|
o["getMyId_v1"] = getMyId_v1;
|
||||||
|
o["getUserCookie_v2"] = getUserCookie_v2;
|
||||||
|
o["endTurn_v2"] = endTurn_v2;
|
||||||
|
o["endGame_v2"] = endGame_v2;
|
||||||
|
o["getTurnHolder_v1"] = getTurnHolder_v1;
|
||||||
|
o["getPlayers_v1"] = getPlayers_v1;
|
||||||
|
|
||||||
|
// deprecated, will be removed soon
|
||||||
|
o["getFromCollection_v1"] = getFromCollection_v1;
|
||||||
|
o["sendMessage_v1"] = sendMessage_v1;
|
||||||
|
o["getPlayerCount_v1"] = getPlayerCount_v1; // no replacement
|
||||||
o["getPlayerNames_v1"] = getPlayerNames_v1;
|
o["getPlayerNames_v1"] = getPlayerNames_v1;
|
||||||
o["getMyIndex_v1"] = getMyIndex_v1;
|
o["getMyIndex_v1"] = getMyIndex_v1;
|
||||||
o["getTurnHolderIndex_v1"] = getTurnHolderIndex_v1;
|
o["getTurnHolderIndex_v1"] = getTurnHolderIndex_v1;
|
||||||
o["getWinnerIndexes_v1"] = getWinnerIndexes_v1;
|
o["getWinnerIndexes_v1"] = getWinnerIndexes_v1;
|
||||||
o["getUserCookie_v1"] = getUserCookie_v1;
|
o["getUserCookie_v1"] = getUserCookie_v1;
|
||||||
o["setUserCookie_v1"] = setUserCookie_v1;
|
|
||||||
o["isMyTurn_v1"] = isMyTurn_v1;
|
|
||||||
o["isInPlay_v1"] = isInPlay_v1;
|
|
||||||
o["endTurn_v1"] = endTurn_v1;
|
o["endTurn_v1"] = endTurn_v1;
|
||||||
o["endGame_v1"] = endGame_v1;
|
o["endGame_v1"] = endGame_v1;
|
||||||
o["getDictionaryLetterSet_v1"] = getDictionaryLetterSet_v1;
|
|
||||||
o["checkDictionaryWord_v1"] = checkDictionaryWord_v1;
|
|
||||||
o["populateCollection_v1"] = populateCollection_v1;
|
|
||||||
o["getFromCollection_v1"] = getFromCollection_v1;
|
|
||||||
o["alterKeyEvents_v1"] = alterKeyEvents_v1;
|
|
||||||
o["focusContainer_v1"] = focusContainer_v1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setProperty_v1 (
|
public function setProperty_v1 (
|
||||||
@@ -171,15 +185,15 @@ public class GameControlBackend
|
|||||||
srcColl, intoColl, createLoggingConfirmListener("mergeCollection"));
|
srcColl, intoColl, createLoggingConfirmListener("mergeCollection"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendMessage_v1 (
|
public function sendMessage_v2 (
|
||||||
messageName :String, value :Object, playerIndex :int) :void
|
messageName :String, value :Object, playerId :int) :void
|
||||||
{
|
{
|
||||||
validateName(messageName);
|
validateName(messageName);
|
||||||
validateValue(value);
|
validateValue(value);
|
||||||
|
|
||||||
var encoded :Object = EZObjectMarshaller.encode(value, false);
|
var encoded :Object = EZObjectMarshaller.encode(value, false);
|
||||||
_ezObj.ezGameService.sendMessage(_ctx.getClient(),
|
_ezObj.ezGameService.sendMessage(_ctx.getClient(),
|
||||||
messageName, encoded, playerIndex,
|
messageName, encoded, playerId,
|
||||||
createLoggingConfirmListener("sendMessage"));
|
createLoggingConfirmListener("sendMessage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,74 +221,63 @@ public class GameControlBackend
|
|||||||
_ctx.getChatDirector().displayInfo(null, MessageBundle.taint(msg));
|
_ctx.getChatDirector().displayInfo(null, MessageBundle.taint(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPlayerCount_v1 () :int
|
public function getOccupants_v1 () :Array
|
||||||
{
|
{
|
||||||
if (_ezObj.players.length == 0) {
|
var occs :Array = [];
|
||||||
// party game
|
for (var ii :int = _ezObj.occupants.size() - 1; ii >= 0; ii--) {
|
||||||
return _ezObj.occupants.size();
|
occs.push(_ezObj.occupants.get(ii));
|
||||||
|
|
||||||
} else {
|
|
||||||
return _ezObj.getPlayerCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return occs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPlayerNames_v1 () :Array
|
public function getPlayers_v1 () :Array
|
||||||
{
|
{
|
||||||
var names :Array = new Array();
|
var playerIds :Array = [];
|
||||||
if (_ezObj.players.length == 0) {
|
for (var ii :int = 0; ii < _ezObj.players.length; ii++) {
|
||||||
// party game, count all occupants
|
var occInfo :OccupantInfo = _ezObj.getOccupantInfo(_ezObj.players[ii] as Name);
|
||||||
var itr :Iterator = _ezObj.occupantInfo.iterator();
|
playerIds.push((occInfo == null) ? 0 : occInfo.bodyOid);
|
||||||
while (itr.hasNext()) {
|
|
||||||
var occInfo :OccupantInfo = (itr.next() as OccupantInfo);
|
|
||||||
names.push(occInfo.username.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
for each (var name :Name in _ezObj.players) {
|
|
||||||
names.push((name == null) ? null : name.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return names;
|
return playerIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMyIndex_v1 () :int
|
public function getOccupantName_v1 (playerId :int) :String
|
||||||
{
|
{
|
||||||
if (_ezObj.players.length == 0) {
|
var occInfo :OccupantInfo =
|
||||||
// party game
|
(_ezObj.occupantInfo.get(playerId) as OccupantInfo);
|
||||||
// TODO: this shouldn't be based off of the String form of the name.
|
return (occInfo == null) ? null : occInfo.username.toString();
|
||||||
var array :Array = getPlayerNames_v1();
|
}
|
||||||
return array.indexOf(getUsername().toString());
|
|
||||||
|
|
||||||
} else {
|
public function getMyId_v1 () :int
|
||||||
return _ezObj.getPlayerIndex(getUsername());
|
{
|
||||||
|
return _ctx.getClient().getClientObject().getOid();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: table games only
|
||||||
|
public function getPlayerPosition_v1 (playerId :int) :int
|
||||||
|
{
|
||||||
|
var occInfo :OccupantInfo =
|
||||||
|
(_ezObj.occupantInfo.get(playerId) as OccupantInfo);
|
||||||
|
if (occInfo == null) {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
return ArrayUtil.indexOf(_ezObj.players, occInfo.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTurnHolderIndex_v1 () :int
|
// TODO: table only
|
||||||
|
public function getTurnHolder_v1 () :int
|
||||||
{
|
{
|
||||||
return _ezObj.getPlayerIndex(_ezObj.turnHolder);
|
var occInfo :OccupantInfo = _ezObj.getOccupantInfo(_ezObj.turnHolder);
|
||||||
|
return (occInfo == null) ? 0 : occInfo.bodyOid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWinnerIndexes_v1 () :Array /* of int */
|
public function getUserCookie_v2 (
|
||||||
{
|
playerId :int, callback :Function) :void
|
||||||
var arr :Array = new Array();
|
|
||||||
if (_ezObj.winners != null) {
|
|
||||||
for (var ii :int = 0; ii < _ezObj.winners.length; ii++) {
|
|
||||||
if (_ezObj.winners[ii]) {
|
|
||||||
arr.push(ii);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUserCookie_v1 (
|
|
||||||
playerIndex :int, callback :Function) :void
|
|
||||||
{
|
{
|
||||||
// see if that cookie is already published
|
// see if that cookie is already published
|
||||||
if (_ezObj.userCookies != null) {
|
if (_ezObj.userCookies != null) {
|
||||||
var uc :UserCookie =
|
var uc :UserCookie =
|
||||||
(_ezObj.userCookies.get(playerIndex) as UserCookie);
|
(_ezObj.userCookies.get(playerId) as UserCookie);
|
||||||
if (uc != null) {
|
if (uc != null) {
|
||||||
callback(uc.cookie);
|
callback(uc.cookie);
|
||||||
return;
|
return;
|
||||||
@@ -284,15 +287,15 @@ public class GameControlBackend
|
|||||||
if (_cookieCallbacks == null) {
|
if (_cookieCallbacks == null) {
|
||||||
_cookieCallbacks = new Dictionary();
|
_cookieCallbacks = new Dictionary();
|
||||||
}
|
}
|
||||||
var arr :Array = (_cookieCallbacks[playerIndex] as Array);
|
var arr :Array = (_cookieCallbacks[playerId] as Array);
|
||||||
if (arr == null) {
|
if (arr == null) {
|
||||||
arr = [];
|
arr = [];
|
||||||
_cookieCallbacks[playerIndex] = arr;
|
_cookieCallbacks[playerId] = arr;
|
||||||
}
|
}
|
||||||
arr.push(callback);
|
arr.push(callback);
|
||||||
|
|
||||||
// request it to be made so by the server
|
// request it to be made so by the server
|
||||||
_ezObj.ezGameService.getCookie(_ctx.getClient(), playerIndex,
|
_ezObj.ezGameService.getCookie(_ctx.getClient(), playerId,
|
||||||
createLoggingConfirmListener("getUserCookie"));
|
createLoggingConfirmListener("getUserCookie"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,17 +323,17 @@ public class GameControlBackend
|
|||||||
return _ezObj.isInPlay();
|
return _ezObj.isInPlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function endTurn_v1 (nextPlayerIndex :int = -1) :void
|
public function endTurn_v2 (nextPlayerId :int) :void
|
||||||
{
|
{
|
||||||
_ezObj.ezGameService.endTurn(_ctx.getClient(), nextPlayerIndex,
|
_ezObj.ezGameService.endTurn(_ctx.getClient(), nextPlayerId,
|
||||||
createLoggingConfirmListener("endTurn"));
|
createLoggingConfirmListener("endTurn"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function endGame_v1 (... winnerDexes) :void
|
public function endGame_v2 (... winnerIds) :void
|
||||||
{
|
{
|
||||||
var winners :TypedArray = TypedArray.create(int);
|
var winners :TypedArray = TypedArray.create(int);
|
||||||
while (winnerDexes.length > 0) {
|
while (winnerIds.length > 0) {
|
||||||
winners.push(int(winnerDexes.shift()));
|
winners.push(int(winnerIds.shift()));
|
||||||
}
|
}
|
||||||
_ezObj.ezGameService.endGame(_ctx.getClient(), winners,
|
_ezObj.ezGameService.endGame(_ctx.getClient(), winners,
|
||||||
createLoggingConfirmListener("endGame"));
|
createLoggingConfirmListener("endGame"));
|
||||||
@@ -406,8 +409,8 @@ public class GameControlBackend
|
|||||||
/**
|
/**
|
||||||
* Helper method for pickFromCollection and dealFromCollection.
|
* Helper method for pickFromCollection and dealFromCollection.
|
||||||
*/
|
*/
|
||||||
public function getFromCollection_v1 (
|
public function getFromCollection_v2 (
|
||||||
collName :String, count :int, msgOrPropName :String, playerIndex :int,
|
collName :String, count :int, msgOrPropName :String, playerId :int,
|
||||||
consume :Boolean, callback :Function) :void
|
consume :Boolean, callback :Function) :void
|
||||||
{
|
{
|
||||||
validateName(collName);
|
validateName(collName);
|
||||||
@@ -435,7 +438,7 @@ public class GameControlBackend
|
|||||||
|
|
||||||
_ezObj.ezGameService.getFromCollection(
|
_ezObj.ezGameService.getFromCollection(
|
||||||
_ctx.getClient(), collName, consume, count, msgOrPropName,
|
_ctx.getClient(), collName, consume, count, msgOrPropName,
|
||||||
playerIndex, listener);
|
playerId, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function alterKeyEvents_v1 (
|
public function alterKeyEvents_v1 (
|
||||||
@@ -675,16 +678,15 @@ public class GameControlBackend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the arrival of a new UserCookie.
|
* Handle the arrival of a new UserCookie.
|
||||||
*/
|
*/
|
||||||
protected function receivedUserCookie (cookie :UserCookie) :void
|
protected function receivedUserCookie (cookie :UserCookie) :void
|
||||||
{
|
{
|
||||||
if (_cookieCallbacks != null) {
|
if (_cookieCallbacks != null) {
|
||||||
var arr :Array = (_cookieCallbacks[cookie.playerIndex] as Array);
|
var arr :Array = (_cookieCallbacks[cookie.playerId] as Array);
|
||||||
if (arr != null) {
|
if (arr != null) {
|
||||||
delete _cookieCallbacks[cookie.playerIndex];
|
delete _cookieCallbacks[cookie.playerId];
|
||||||
for each (var fn :Function in arr) {
|
for each (var fn :Function in arr) {
|
||||||
try {
|
try {
|
||||||
fn(cookie.cookie);
|
fn(cookie.cookie);
|
||||||
@@ -696,6 +698,131 @@ public class GameControlBackend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some methods included for backwards compatability.
|
||||||
|
// Most of these were only ever used internally, so we should be able to
|
||||||
|
// get rid of them sooner rather than later.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BackCompat: turn a player index into an oid.
|
||||||
|
*/
|
||||||
|
protected function indexToId (index :int) :int
|
||||||
|
{
|
||||||
|
var name :Name = _ezObj.players[index];
|
||||||
|
if (name != null) {
|
||||||
|
var occInfo :OccupantInfo = _ezObj.getOccupantInfo(name);
|
||||||
|
if (occInfo != null) {
|
||||||
|
return occInfo.bodyOid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
protected function getFromCollection_v1 (
|
||||||
|
collName :String, count :int, msgOrPropName :String,
|
||||||
|
playerIndex :int, consume :Boolean, callback :Function) :void
|
||||||
|
{
|
||||||
|
getFromCollection_v2(collName, count, msgOrPropName,
|
||||||
|
indexToId(playerIndex), consume, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
public function sendMessage_v1 (
|
||||||
|
messageName :String, value :Object, playerIndex :int) :void
|
||||||
|
{
|
||||||
|
sendMessage_v2(messageName, value, indexToId(playerIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
public function getPlayerCount_v1 () :int
|
||||||
|
{
|
||||||
|
if (_ezObj.players.length == 0) {
|
||||||
|
// party game
|
||||||
|
return _ezObj.occupants.size();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return _ezObj.getPlayerCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
public function getPlayerNames_v1 () :Array
|
||||||
|
{
|
||||||
|
var names :Array = new Array();
|
||||||
|
if (_ezObj.players.length == 0) {
|
||||||
|
// party game, count all occupants
|
||||||
|
var itr :Iterator = _ezObj.occupantInfo.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
var occInfo :OccupantInfo = (itr.next() as OccupantInfo);
|
||||||
|
names.push(occInfo.username.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
for each (var name :Name in _ezObj.players) {
|
||||||
|
names.push((name == null) ? null : name.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
public function getMyIndex_v1 () :int
|
||||||
|
{
|
||||||
|
if (_ezObj.players.length == 0) {
|
||||||
|
// party game
|
||||||
|
// TODO: this shouldn't be based off of the String form of the name.
|
||||||
|
var array :Array = getPlayerNames_v1();
|
||||||
|
return array.indexOf(getUsername().toString());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return _ezObj.getPlayerIndex(getUsername());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
public function getTurnHolderIndex_v1 () :int
|
||||||
|
{
|
||||||
|
return _ezObj.getPlayerIndex(_ezObj.turnHolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
public function getWinnerIndexes_v1 () :Array /* of int */
|
||||||
|
{
|
||||||
|
var arr :Array = new Array();
|
||||||
|
if (_ezObj.winners != null) {
|
||||||
|
for (var ii :int = 0; ii < _ezObj.winners.length; ii++) {
|
||||||
|
if (_ezObj.winners[ii]) {
|
||||||
|
arr.push(ii);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
public function getUserCookie_v1 (
|
||||||
|
playerIndex :int, callback :Function) :void
|
||||||
|
{
|
||||||
|
getUserCookie_v2(indexToId(playerIndex), callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
public function endTurn_v1 (nextPlayerIndex :int) :void
|
||||||
|
{
|
||||||
|
endTurn_v2(indexToId(nextPlayerIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
public function endGame_v1 (... winnerDexes) :void
|
||||||
|
{
|
||||||
|
var winnerIds :Array = [];
|
||||||
|
for each (var dex :int in winnerDexes) {
|
||||||
|
winnerIds.push(indexToId(dex));
|
||||||
|
}
|
||||||
|
endGame_v2.apply(this, winnerIds);
|
||||||
|
}
|
||||||
|
|
||||||
protected var _ctx :CrowdContext;
|
protected var _ctx :CrowdContext;
|
||||||
|
|
||||||
protected var _userListener :MessageAdapter =
|
protected var _userListener :MessageAdapter =
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import com.threerings.ezgame.util.EZObjectMarshaller;
|
|||||||
public class UserCookie
|
public class UserCookie
|
||||||
implements DSet_Entry
|
implements DSet_Entry
|
||||||
{
|
{
|
||||||
/** The index of the player that has this cookie. */
|
/** The id of the player that has this cookie. */
|
||||||
public var playerIndex :int;
|
public var playerId :int;
|
||||||
|
|
||||||
/** The decoded cookie value. */
|
/** The decoded cookie value. */
|
||||||
public var cookie :Object;
|
public var cookie :Object;
|
||||||
@@ -24,13 +24,13 @@ public class UserCookie
|
|||||||
// from DSet_Entry
|
// from DSet_Entry
|
||||||
public function getKey () :Object
|
public function getKey () :Object
|
||||||
{
|
{
|
||||||
return playerIndex;
|
return playerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from superinterface Streamable
|
// from superinterface Streamable
|
||||||
public function readObject (ins :ObjectInputStream) :void
|
public function readObject (ins :ObjectInputStream) :void
|
||||||
{
|
{
|
||||||
playerIndex = ins.readInt();
|
playerId = ins.readInt();
|
||||||
var ba :ByteArray = (ins.readField(ByteArray) as ByteArray);
|
var ba :ByteArray = (ins.readField(ByteArray) as ByteArray);
|
||||||
cookie = EZObjectMarshaller.decode(ba);
|
cookie = EZObjectMarshaller.decode(ba);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
The code in here is out of date and out of sync, but will not be updated
|
||||||
|
until needed, as we're focusing on flash development.
|
||||||
@@ -27,14 +27,14 @@ public interface EZGameService extends InvocationService
|
|||||||
* -1 is specified for the nextPlayerIndex.
|
* -1 is specified for the nextPlayerIndex.
|
||||||
*/
|
*/
|
||||||
public void endTurn (
|
public void endTurn (
|
||||||
Client client, int nextPlayerIndex, InvocationListener listener);
|
Client client, int nextPlayerId, InvocationListener listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request to end the game, with the specified player indices assigned
|
* Request to end the game, with the specified player oids assigned
|
||||||
* as winners.
|
* as winners.
|
||||||
*/
|
*/
|
||||||
public void endGame (
|
public void endGame (
|
||||||
Client client, int[] winners, InvocationListener listener);
|
Client client, int[] winnerOids, InvocationListener listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request to send a private message to one other player in
|
* Request to send a private message to one other player in
|
||||||
@@ -45,7 +45,7 @@ public interface EZGameService extends InvocationService
|
|||||||
* 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 playerIdx,
|
Client client, String msgName, Object value, int playerId,
|
||||||
InvocationListener listener);
|
InvocationListener listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +99,7 @@ public interface EZGameService extends InvocationService
|
|||||||
*/
|
*/
|
||||||
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 playerIndex, 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
|
||||||
@@ -116,7 +116,7 @@ public interface EZGameService extends InvocationService
|
|||||||
* 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 playerIndex, InvocationListener listener);
|
Client client, int playerId, InvocationListener listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request to set our cookie.
|
* Request to set our cookie.
|
||||||
|
|||||||
@@ -29,23 +29,23 @@ import com.threerings.presents.dobj.DSet;
|
|||||||
public class UserCookie
|
public class UserCookie
|
||||||
implements DSet.Entry
|
implements DSet.Entry
|
||||||
{
|
{
|
||||||
/** The index of the player that has this cookie. */
|
/** The id of the player that has this cookie. */
|
||||||
public int playerIndex;
|
public int playerId;
|
||||||
|
|
||||||
/** The cookie value. */
|
/** The cookie value. */
|
||||||
public byte[] cookie;
|
public byte[] cookie;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public UserCookie (int playerIndex, byte[] cookie)
|
public UserCookie (int playerId, byte[] cookie)
|
||||||
{
|
{
|
||||||
this.playerIndex = playerIndex;
|
this.playerId = playerId;
|
||||||
this.cookie = cookie;
|
this.cookie = cookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from DSet.Entry
|
// from DSet.Entry
|
||||||
public Comparable getKey ()
|
public Comparable getKey ()
|
||||||
{
|
{
|
||||||
return playerIndex;
|
return playerId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.samskivert.util.ArrayUtil;
|
|||||||
import com.samskivert.util.CollectionUtil;
|
import com.samskivert.util.CollectionUtil;
|
||||||
import com.samskivert.util.HashIntMap;
|
import com.samskivert.util.HashIntMap;
|
||||||
import com.samskivert.util.Interval;
|
import com.samskivert.util.Interval;
|
||||||
|
import com.samskivert.util.IntListUtil;
|
||||||
import com.samskivert.util.RandomUtil;
|
import com.samskivert.util.RandomUtil;
|
||||||
import com.samskivert.util.ResultListener;
|
import com.samskivert.util.ResultListener;
|
||||||
|
|
||||||
@@ -74,17 +75,26 @@ public class EZGameManager extends GameManager
|
|||||||
|
|
||||||
// from EZGameProvider
|
// from EZGameProvider
|
||||||
public void endTurn (
|
public void endTurn (
|
||||||
ClientObject caller, int nextPlayerIndex,
|
ClientObject caller, int nextPlayerId,
|
||||||
InvocationService.InvocationListener listener)
|
InvocationService.InvocationListener listener)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
validateStateModification(caller);
|
validateStateModification(caller);
|
||||||
_turnDelegate.endTurn(nextPlayerIndex);
|
|
||||||
|
Name nextTurnHolder = null;
|
||||||
|
if (nextPlayerId != 0) {
|
||||||
|
BodyObject target = getPlayerByOid(nextPlayerId);
|
||||||
|
if (target != null) {
|
||||||
|
nextTurnHolder = target.getVisibleName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_turnDelegate.endTurn(nextTurnHolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// from EZGameProvider
|
// from EZGameProvider
|
||||||
public void endGame (
|
public void endGame (
|
||||||
ClientObject caller, int[] winners,
|
ClientObject caller, int[] winnerOids,
|
||||||
InvocationService.InvocationListener listener)
|
InvocationService.InvocationListener listener)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
@@ -93,24 +103,24 @@ public class EZGameManager extends GameManager
|
|||||||
}
|
}
|
||||||
validateStateModification(caller);
|
validateStateModification(caller);
|
||||||
|
|
||||||
_winnerIndexes = winners;
|
_winnerIds = winnerOids;
|
||||||
endGame();
|
endGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
// from EZGameProvider
|
// from EZGameProvider
|
||||||
public void sendMessage (
|
public void sendMessage (
|
||||||
ClientObject caller, String msg, Object data, int playerIdx,
|
ClientObject caller, String msg, Object data, int playerId,
|
||||||
InvocationService.InvocationListener listener)
|
InvocationService.InvocationListener listener)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
validateUser(caller);
|
validateUser(caller);
|
||||||
|
|
||||||
if (playerIdx < 0 || playerIdx >= _gameObj.players.length) {
|
if (playerId == 0) {
|
||||||
_gameObj.postMessage(EZGameObject.USER_MESSAGE,
|
_gameObj.postMessage(EZGameObject.USER_MESSAGE,
|
||||||
new Object[] { msg, data });
|
new Object[] { msg, data });
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sendPrivateMessage(playerIdx, msg, data);
|
sendPrivateMessage(playerId, msg, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +196,7 @@ public class EZGameManager extends GameManager
|
|||||||
// from EZGameProvider
|
// from EZGameProvider
|
||||||
public void getFromCollection (
|
public void getFromCollection (
|
||||||
ClientObject caller, String collName, boolean consume, int count,
|
ClientObject caller, String collName, boolean consume, int count,
|
||||||
String msgOrPropName, int playerIndex,
|
String msgOrPropName, int playerId,
|
||||||
InvocationService.ConfirmListener listener)
|
InvocationService.ConfirmListener listener)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
@@ -209,11 +219,11 @@ public class EZGameManager extends GameManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerIndex >= 0 && playerIndex < _gameObj.players.length) {
|
if (playerId == 0) {
|
||||||
sendPrivateMessage(playerIndex, msgOrPropName, result);
|
setProperty(msgOrPropName, result, -1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
setProperty(msgOrPropName, result, -1);
|
sendPrivateMessage(playerId, msgOrPropName, result);
|
||||||
}
|
}
|
||||||
// SUCCESS!
|
// SUCCESS!
|
||||||
listener.requestProcessed();
|
listener.requestProcessed();
|
||||||
@@ -289,12 +299,12 @@ public class EZGameManager extends GameManager
|
|||||||
|
|
||||||
// from EZGameProvider
|
// from EZGameProvider
|
||||||
public void getCookie (
|
public void getCookie (
|
||||||
ClientObject caller, final int playerIndex,
|
ClientObject caller, final int playerId,
|
||||||
InvocationService.InvocationListener listener)
|
InvocationService.InvocationListener listener)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
GameCookieManager gcm = getCookieManager();
|
GameCookieManager gcm = getCookieManager();
|
||||||
if (_gameObj.userCookies.containsKey(playerIndex)) {
|
if (_gameObj.userCookies.containsKey(playerId)) {
|
||||||
// already loaded: we do nothing
|
// already loaded: we do nothing
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -303,18 +313,18 @@ public class EZGameManager extends GameManager
|
|||||||
_cookieLookups = new ArrayIntSet();
|
_cookieLookups = new ArrayIntSet();
|
||||||
}
|
}
|
||||||
// we only start looking up the cookie if nobody else already is
|
// we only start looking up the cookie if nobody else already is
|
||||||
if (!_cookieLookups.contains(playerIndex)) {
|
if (!_cookieLookups.contains(playerId)) {
|
||||||
gcm.getCookie(getPersistentGameId(), getPlayer(playerIndex),
|
gcm.getCookie(getPersistentGameId(), getPlayerByOid(playerId),
|
||||||
new ResultListener<byte[]>() {
|
new ResultListener<byte[]>() {
|
||||||
public void requestCompleted (byte[] result) {
|
public void requestCompleted (byte[] result) {
|
||||||
// Result may be null: that's ok, it means
|
// Result may be null: that's ok, it means
|
||||||
// we've looked up the user's nonexistant cookie.
|
// we've looked up the user's nonexistant cookie.
|
||||||
// Only set the cookie if the playerIndex is
|
// Only set the cookie if the playerIndex is
|
||||||
// still in the lookup set, otherwise they left!
|
// still in the lookup set, otherwise they left!
|
||||||
if (_cookieLookups.remove(playerIndex) &&
|
if (_cookieLookups.remove(playerId) &&
|
||||||
_gameObj.isActive()) {
|
_gameObj.isActive()) {
|
||||||
_gameObj.addToUserCookies(
|
_gameObj.addToUserCookies(
|
||||||
new UserCookie(playerIndex, result));
|
new UserCookie(playerId, result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +336,7 @@ public class EZGameManager extends GameManager
|
|||||||
});
|
});
|
||||||
|
|
||||||
// indicate that we're looking up a cookie
|
// indicate that we're looking up a cookie
|
||||||
_cookieLookups.add(playerIndex);
|
_cookieLookups.add(playerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,14 +346,11 @@ public class EZGameManager extends GameManager
|
|||||||
InvocationService.InvocationListener listener)
|
InvocationService.InvocationListener listener)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
int playerIndex = getPresentPlayerIndex(caller.getOid());
|
validateUser(caller);
|
||||||
if (playerIndex == -1) {
|
|
||||||
throw new InvocationException(ACCESS_DENIED);
|
|
||||||
}
|
|
||||||
|
|
||||||
GameCookieManager gcm = getCookieManager();
|
GameCookieManager gcm = getCookieManager();
|
||||||
UserCookie cookie = new UserCookie(playerIndex, value);
|
UserCookie cookie = new UserCookie(caller.getOid(), value);
|
||||||
if (_gameObj.userCookies.containsKey(playerIndex)) {
|
if (_gameObj.userCookies.containsKey(cookie.getKey())) {
|
||||||
_gameObj.updateUserCookies(cookie);
|
_gameObj.updateUserCookies(cookie);
|
||||||
} else {
|
} else {
|
||||||
_gameObj.addToUserCookies(cookie);
|
_gameObj.addToUserCookies(cookie);
|
||||||
@@ -372,14 +379,14 @@ public class EZGameManager extends GameManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to send a private message to the specified player
|
* Helper method to send a private message to the specified player oid
|
||||||
* index (must already be verified).
|
* (must already be verified).
|
||||||
*/
|
*/
|
||||||
protected void sendPrivateMessage (
|
protected void sendPrivateMessage (
|
||||||
int playerIdx, String msg, Object data)
|
int playerId, String msg, Object data)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
BodyObject target = getPlayer(playerIdx);
|
BodyObject target = getPlayerByOid(playerId);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
// TODO: this code has no corresponding translation
|
// TODO: this code has no corresponding translation
|
||||||
throw new InvocationException("m.player_not_around");
|
throw new InvocationException("m.player_not_around");
|
||||||
@@ -446,6 +453,33 @@ public class EZGameManager extends GameManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the specified player body by Oid.
|
||||||
|
*/
|
||||||
|
protected BodyObject getPlayerByOid (int oid)
|
||||||
|
{
|
||||||
|
// verify that they're in the room
|
||||||
|
if (!_gameObj.occupants.contains(oid)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// verify that they're a player
|
||||||
|
switch (getGameType()) {
|
||||||
|
case GameConfig.PARTY:
|
||||||
|
// all occupants are players in a party game
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (!IntListUtil.contains(_playerOids, oid)) {
|
||||||
|
return null; // not a player!
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the body
|
||||||
|
return (BodyObject) CrowdServer.omgr.getObject(oid);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PlaceObject createPlaceObject ()
|
protected PlaceObject createPlaceObject ()
|
||||||
{
|
{
|
||||||
@@ -503,13 +537,14 @@ public class EZGameManager extends GameManager
|
|||||||
@Override
|
@Override
|
||||||
protected void assignWinners (boolean[] winners)
|
protected void assignWinners (boolean[] winners)
|
||||||
{
|
{
|
||||||
if (_winnerIndexes != null) {
|
if (_winnerIds != null) {
|
||||||
for (int index : _winnerIndexes) {
|
for (int oid : _winnerIds) {
|
||||||
|
int index = IntListUtil.indexOf(_playerOids, oid);
|
||||||
if (index >= 0 && index < winners.length) {
|
if (index >= 0 && index < winners.length) {
|
||||||
winners[index] = true;
|
winners[index] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_winnerIndexes = null;
|
_winnerIds = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,8 +630,8 @@ public class EZGameManager extends GameManager
|
|||||||
// /** User tokens, lazy-initialized. */
|
// /** User tokens, lazy-initialized. */
|
||||||
// protected HashIntMap<HashSet<String>> _tokens;
|
// protected HashIntMap<HashSet<String>> _tokens;
|
||||||
|
|
||||||
/** The array of winners, after the user has filled it in. */
|
/** The array of winner oids, after the user has filled it in. */
|
||||||
protected int[] _winnerIndexes;
|
protected int[] _winnerIds;
|
||||||
|
|
||||||
/** The minimum delay a ticker can have. */
|
/** The minimum delay a ticker can have. */
|
||||||
protected static final int MIN_TICKER_DELAY = 50;
|
protected static final int MIN_TICKER_DELAY = 50;
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
package com.threerings.ezgame.server;
|
package com.threerings.ezgame.server;
|
||||||
|
|
||||||
|
import com.samskivert.util.ListUtil;
|
||||||
|
|
||||||
|
import com.threerings.util.Name;
|
||||||
|
|
||||||
import com.threerings.parlor.turn.server.TurnGameManagerDelegate;
|
import com.threerings.parlor.turn.server.TurnGameManagerDelegate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,11 +20,11 @@ public class EZGameTurnDelegate extends TurnGameManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A form of endTurn where you can specify the next turn holder index.
|
* A form of endTurn where you can specify the next turn holder oid.
|
||||||
*/
|
*/
|
||||||
public void endTurn (int playerIndex)
|
public void endTurn (Name nextPlayer)
|
||||||
{
|
{
|
||||||
_nextPlayerIndex = playerIndex;
|
_nextPlayer = nextPlayer;
|
||||||
endTurn();
|
endTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,19 +32,22 @@ public class EZGameTurnDelegate extends TurnGameManagerDelegate
|
|||||||
protected void setNextTurnHolder ()
|
protected void setNextTurnHolder ()
|
||||||
{
|
{
|
||||||
// if the user-supplied value seems to make sense, use it!
|
// if the user-supplied value seems to make sense, use it!
|
||||||
if ((_nextPlayerIndex >= 0) &&
|
if (_nextPlayer != null) {
|
||||||
(_nextPlayerIndex < _turnGame.getPlayers().length)) {
|
// copy the value, clear out _nextPlayer.
|
||||||
_turnIdx = _nextPlayerIndex;
|
Name nextPlayer = _nextPlayer;
|
||||||
|
_nextPlayer = null;
|
||||||
|
|
||||||
} else {
|
int index = ListUtil.indexOf(_turnGame.getPlayers(), _nextPlayer);
|
||||||
// otherwise, do the default behavior
|
if (index != -1) {
|
||||||
super.setNextTurnHolder();
|
_turnIdx = index;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// always clear out the override
|
// otherwise, do the default behavior
|
||||||
_nextPlayerIndex = -1;
|
super.setNextTurnHolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An override next turn holder, or -1. */
|
/** An override next turn holder, or null. */
|
||||||
protected int _nextPlayerIndex = -1;
|
protected Name _nextPlayer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user