Removed special handling that is now confined to Yohoho and its particular
requirements. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3155 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PuzzleService.java,v 1.4 2004/08/27 02:20:27 mdb Exp $
|
||||
// $Id: PuzzleService.java,v 1.5 2004/10/21 02:54:43 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -24,7 +24,6 @@ package com.threerings.puzzle.client;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.puzzle.data.SolitairePuzzleConfig;
|
||||
|
||||
/**
|
||||
@@ -34,31 +33,10 @@ import com.threerings.puzzle.data.SolitairePuzzleConfig;
|
||||
*/
|
||||
public interface PuzzleService extends InvocationService
|
||||
{
|
||||
/** Used to communicate responses to {@link #enterPuzzle} requests. */
|
||||
public static interface EnterPuzzleListener extends InvocationListener
|
||||
{
|
||||
/**
|
||||
* Indicates that a {@link #enterPuzzle} request was successful
|
||||
* and provides the place config for the puzzle room.
|
||||
*/
|
||||
public void puzzleEntered (PlaceConfig config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that this client start up the specified single-player
|
||||
* puzzle.
|
||||
*/
|
||||
public void startPuzzle (Client client, SolitairePuzzleConfig config,
|
||||
ConfirmListener listener);
|
||||
|
||||
/**
|
||||
* Requests that this client enter the specified puzzle.
|
||||
*/
|
||||
public void enterPuzzle (
|
||||
Client client, int puzzleOid, EnterPuzzleListener listener);
|
||||
|
||||
/**
|
||||
* Requests that this client depart whatever puzzle they occupy.
|
||||
*/
|
||||
public void leavePuzzle (Client client);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PuzzleCodes.java,v 1.3 2004/08/27 02:20:28 mdb Exp $
|
||||
// $Id: PuzzleCodes.java,v 1.4 2004/10/21 02:54:44 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -48,23 +48,7 @@ public interface PuzzleCodes extends InvocationCodes
|
||||
|
||||
/** Enable this flag to have the client send a copy of its board state
|
||||
* with every event to the server for checking. */
|
||||
public static final boolean SYNC_BOARD_STATE = false;
|
||||
|
||||
/** An error code indicating that a place identified by a particular
|
||||
* place id does not exist. Usually generated by a failed enterPuzzle
|
||||
* request. */
|
||||
public static final String NO_SUCH_PUZZLE = MessageBundle.qualify(
|
||||
PUZZLE_MESSAGE_BUNDLE, "m.no_such_puzzle");
|
||||
|
||||
/** An error code sent when a user requests to enter a new puzzle but
|
||||
* they are in the middle of moving somewhere already. */
|
||||
public static final String ENTER_IN_PROGRESS = MessageBundle.qualify(
|
||||
PUZZLE_MESSAGE_BUNDLE, "m.enter_in_progress");
|
||||
|
||||
/** An error code sent when a user requests to enter a puzzle, but
|
||||
* they are already in it. */
|
||||
public static final String ALREADY_IN_PUZZLE = MessageBundle.qualify(
|
||||
PUZZLE_MESSAGE_BUNDLE, "m.already_in_puzzle");
|
||||
public static final boolean SYNC_BOARD_STATE = true;
|
||||
|
||||
/** Whether to enable debug logging and assertions for puzzles. Note
|
||||
* that enabling this may result in the server or client exiting
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
//
|
||||
// $Id: PuzzleGameMarshaller.java,v 1.2 2004/08/27 02:20:28 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
// $Id: PuzzleGameMarshaller.java,v 1.3 2004/10/21 02:54:44 mdb Exp $
|
||||
|
||||
package com.threerings.puzzle.data;
|
||||
|
||||
|
||||
@@ -1,33 +1,13 @@
|
||||
//
|
||||
// $Id: PuzzleMarshaller.java,v 1.4 2004/08/27 02:20:28 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
// $Id: PuzzleMarshaller.java,v 1.5 2004/10/21 02:54:44 mdb Exp $
|
||||
|
||||
package com.threerings.puzzle.data;
|
||||
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService.ConfirmListener;
|
||||
import com.threerings.presents.data.InvocationMarshaller;
|
||||
import com.threerings.presents.dobj.InvocationResponseEvent;
|
||||
import com.threerings.puzzle.client.PuzzleService;
|
||||
import com.threerings.puzzle.client.PuzzleService.EnterPuzzleListener;
|
||||
import com.threerings.puzzle.data.SolitairePuzzleConfig;
|
||||
|
||||
/**
|
||||
@@ -40,37 +20,6 @@ import com.threerings.puzzle.data.SolitairePuzzleConfig;
|
||||
public class PuzzleMarshaller extends InvocationMarshaller
|
||||
implements PuzzleService
|
||||
{
|
||||
// documentation inherited
|
||||
public static class EnterPuzzleMarshaller extends ListenerMarshaller
|
||||
implements EnterPuzzleListener
|
||||
{
|
||||
/** The method id used to dispatch {@link #puzzleEntered}
|
||||
* responses. */
|
||||
public static final int PUZZLE_ENTERED = 1;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void puzzleEntered (PlaceConfig arg1)
|
||||
{
|
||||
omgr.postEvent(new InvocationResponseEvent(
|
||||
callerOid, requestId, PUZZLE_ENTERED,
|
||||
new Object[] { arg1 }));
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void dispatchResponse (int methodId, Object[] args)
|
||||
{
|
||||
switch (methodId) {
|
||||
case PUZZLE_ENTERED:
|
||||
((EnterPuzzleListener)listener).puzzleEntered(
|
||||
(PlaceConfig)args[0]);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchResponse(methodId, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #startPuzzle} requests. */
|
||||
public static final int START_PUZZLE = 1;
|
||||
|
||||
@@ -84,28 +33,4 @@ public class PuzzleMarshaller extends InvocationMarshaller
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #enterPuzzle} requests. */
|
||||
public static final int ENTER_PUZZLE = 2;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void enterPuzzle (Client arg1, int arg2, EnterPuzzleListener arg3)
|
||||
{
|
||||
EnterPuzzleMarshaller listener3 = new EnterPuzzleMarshaller();
|
||||
listener3.listener = arg3;
|
||||
sendRequest(arg1, ENTER_PUZZLE, new Object[] {
|
||||
new Integer(arg2), listener3
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #leavePuzzle} requests. */
|
||||
public static final int LEAVE_PUZZLE = 3;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void leavePuzzle (Client arg1)
|
||||
{
|
||||
sendRequest(arg1, LEAVE_PUZZLE, new Object[] {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
//
|
||||
// $Id: PuzzlerObject.java,v 1.3 2004/08/27 02:20:28 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.puzzle.data;
|
||||
|
||||
/**
|
||||
* An interface that must be implemented by {@link BodyObject} derivations
|
||||
* that wish to be usable with the puzzle services.
|
||||
*/
|
||||
public interface PuzzlerObject
|
||||
{
|
||||
/**
|
||||
* Returns this puzzler's "puzzle location which is the oid of the
|
||||
* puzzle game object. Should return -1 until some value is set via
|
||||
* {@link #setPuzzleLoc}.
|
||||
*/
|
||||
public int getPuzzleLoc ();
|
||||
|
||||
/**
|
||||
* Sets this puzzler's "puzzle location".
|
||||
*/
|
||||
public void setPuzzleLoc (int puzzleLoc);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DropSprite.java,v 1.3 2004/08/27 02:20:29 mdb Exp $
|
||||
// $Id: DropSprite.java,v 1.4 2004/10/21 02:54:44 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -32,6 +32,8 @@ import com.threerings.util.DirectionUtil;
|
||||
import com.threerings.media.image.Mirage;
|
||||
import com.threerings.media.sprite.Sprite;
|
||||
|
||||
import com.threerings.puzzle.Log;
|
||||
|
||||
/**
|
||||
* The drop sprite is a sprite that displays one or more pieces falling
|
||||
* toward the bottom of the board.
|
||||
@@ -406,9 +408,6 @@ public class DropSprite extends Sprite
|
||||
pmop = new PieceMovedOp(this, timestamp, _col, _row);
|
||||
}
|
||||
|
||||
// Log.info("Drop sprite tick [dist=" + _dist + ", pctdone=" + pctdone +
|
||||
// ", row=" + _row + ", col=" + _col + "].");
|
||||
|
||||
// constrain the sprite's position to the destination row
|
||||
pctdone = Math.min(pctdone, 1.0f);
|
||||
|
||||
@@ -416,6 +415,10 @@ public class DropSprite extends Sprite
|
||||
int nx = _srcPos.x + (int)((_destPos.x - _srcPos.x) * pctdone);
|
||||
int ny = _srcPos.y + (int)((_destPos.y - _srcPos.y) * pctdone);
|
||||
|
||||
// Log.info("Drop sprite tick [dist=" + _dist + ", pctdone=" + pctdone +
|
||||
// ", row=" + _row + ", col=" + _col +
|
||||
// ", nx=" + nx + ", ny=" + ny + "].");
|
||||
|
||||
// only update the sprite's location if it actually moved
|
||||
if (_ox != nx || _oy != ny) {
|
||||
setLocation(nx, ny);
|
||||
|
||||
@@ -1,27 +1,8 @@
|
||||
//
|
||||
// $Id: PuzzleDispatcher.java,v 1.4 2004/08/27 02:20:32 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
// $Id: PuzzleDispatcher.java,v 1.5 2004/10/21 02:54:44 mdb Exp $
|
||||
|
||||
package com.threerings.puzzle.server;
|
||||
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService.ConfirmListener;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
@@ -29,7 +10,6 @@ import com.threerings.presents.data.InvocationMarshaller;
|
||||
import com.threerings.presents.server.InvocationDispatcher;
|
||||
import com.threerings.presents.server.InvocationException;
|
||||
import com.threerings.puzzle.client.PuzzleService;
|
||||
import com.threerings.puzzle.client.PuzzleService.EnterPuzzleListener;
|
||||
import com.threerings.puzzle.data.PuzzleMarshaller;
|
||||
import com.threerings.puzzle.data.SolitairePuzzleConfig;
|
||||
|
||||
@@ -66,20 +46,6 @@ public class PuzzleDispatcher extends InvocationDispatcher
|
||||
);
|
||||
return;
|
||||
|
||||
case PuzzleMarshaller.ENTER_PUZZLE:
|
||||
((PuzzleProvider)provider).enterPuzzle(
|
||||
source,
|
||||
((Integer)args[0]).intValue(), (EnterPuzzleListener)args[1]
|
||||
);
|
||||
return;
|
||||
|
||||
case PuzzleMarshaller.LEAVE_PUZZLE:
|
||||
((PuzzleProvider)provider).leavePuzzle(
|
||||
source
|
||||
|
||||
);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchRequest(source, methodId, args);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
//
|
||||
// $Id: PuzzleGameDispatcher.java,v 1.2 2004/08/27 02:20:32 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
// $Id: PuzzleGameDispatcher.java,v 1.3 2004/10/21 02:54:44 mdb Exp $
|
||||
|
||||
package com.threerings.puzzle.server;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PuzzleManager.java,v 1.15 2004/09/01 21:03:11 ray Exp $
|
||||
// $Id: PuzzleManager.java,v 1.16 2004/10/21 02:54:44 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -28,14 +28,12 @@ import com.samskivert.util.IntervalManager;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
import com.threerings.presents.dobj.OidList;
|
||||
import com.threerings.presents.server.util.SafeInterval;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.server.CrowdServer;
|
||||
import com.threerings.crowd.server.PlaceManagerDelegate;
|
||||
|
||||
import com.threerings.parlor.game.GameManager;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PuzzleProvider.java,v 1.6 2004/08/27 02:20:32 mdb Exp $
|
||||
// $Id: PuzzleProvider.java,v 1.7 2004/10/21 02:54:44 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -32,16 +32,13 @@ import com.threerings.presents.server.InvocationProvider;
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.server.PlaceManager;
|
||||
import com.threerings.crowd.server.PlaceRegistry;
|
||||
|
||||
import com.threerings.parlor.game.GameManager;
|
||||
|
||||
import com.threerings.puzzle.Log;
|
||||
import com.threerings.puzzle.client.PuzzleService.EnterPuzzleListener;
|
||||
import com.threerings.puzzle.data.PuzzleCodes;
|
||||
import com.threerings.puzzle.data.PuzzleObject;
|
||||
import com.threerings.puzzle.data.PuzzlerObject;
|
||||
import com.threerings.puzzle.data.SolitairePuzzleConfig;
|
||||
|
||||
/**
|
||||
@@ -93,152 +90,6 @@ public class PuzzleProvider
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a request from a client to enter a puzzle.
|
||||
*/
|
||||
public void enterPuzzle (
|
||||
ClientObject caller, int puzzleOid, EnterPuzzleListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
// do the entry and send the response
|
||||
listener.puzzleEntered(enterPuzzle((BodyObject)caller, puzzleOid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a request from a client to leave their current puzzle.
|
||||
*/
|
||||
public void leavePuzzle (ClientObject caller)
|
||||
{
|
||||
BodyObject user = (BodyObject)caller;
|
||||
int puzzleOid = ((PuzzlerObject)user).getPuzzleLoc();
|
||||
|
||||
// make sure they're currently in a puzzle
|
||||
if (puzzleOid == -1) {
|
||||
Log.warning("Received leave puzzle request from user that " +
|
||||
"isn't in a puzzle [user=" + user.who() + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the puzzle in question actually exists
|
||||
PlaceManager pmgr = _plreg.getPlaceManager(puzzleOid);
|
||||
if (pmgr == null) {
|
||||
Log.info("Requested to leave a non-existent puzzle " +
|
||||
"[user=" + user.who() + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// depart their old puzzle
|
||||
departPuzzle(user);
|
||||
|
||||
// set their puzzle location to -1 to indicate that they're no
|
||||
// longer in a puzzle
|
||||
((PuzzlerObject)user).setPuzzleLoc(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the specified body from whatever puzzle they currently occupy
|
||||
* to the puzzle identified by the supplied oid.
|
||||
*
|
||||
* @return the config object for the new location.
|
||||
*
|
||||
* @exception InvocationException thrown if the entry was not
|
||||
* successful for some reason (which will be communicated as an error
|
||||
* code in the exception's message data).
|
||||
*/
|
||||
public PlaceConfig enterPuzzle (BodyObject user, int puzzleOid)
|
||||
throws InvocationException
|
||||
{
|
||||
int bodoid = user.getOid();
|
||||
int puzzleLoc = ((PuzzlerObject)user).getPuzzleLoc();
|
||||
|
||||
// make sure the place in question actually exists
|
||||
PlaceManager pmgr = _plreg.getPlaceManager(puzzleOid);
|
||||
if (pmgr == null) {
|
||||
Log.info("Requested to move to non-existent place " +
|
||||
"[user=" + user.who() + ", puzzle=" + puzzleOid + "].");
|
||||
throw new InvocationException(NO_SUCH_PUZZLE);
|
||||
}
|
||||
|
||||
// acquire a lock on the body object to ensure that rapid fire
|
||||
// enterPuzzle requests don't break things
|
||||
if (!user.acquireLock("enterPuzzleLock")) {
|
||||
// if we're still locked, a previous enterPuzzle request
|
||||
// hasn't been fully processed
|
||||
throw new InvocationException(ENTER_IN_PROGRESS);
|
||||
}
|
||||
|
||||
// make sure they're not already in the puzzle they're entering
|
||||
if (puzzleLoc == puzzleOid) {
|
||||
throw new InvocationException(ALREADY_IN_PUZZLE);
|
||||
}
|
||||
|
||||
// depart any previously occupied puzzle
|
||||
departPuzzle(user);
|
||||
|
||||
// set the body's new puzzle location
|
||||
PlaceObject place = pmgr.getPlaceObject();
|
||||
((PuzzlerObject)user).setPuzzleLoc(place.getOid());
|
||||
|
||||
// prepare to update their new puzzle location
|
||||
place.startTransaction();
|
||||
try {
|
||||
// generate a new occupant info record (which will add it to
|
||||
// the target location)
|
||||
pmgr.buildOccupantInfo(user);
|
||||
|
||||
// add the body object id to the place object's occupant list
|
||||
place.addToOccupants(bodoid);
|
||||
} finally {
|
||||
place.commitTransaction();
|
||||
}
|
||||
|
||||
// and finally queue up a lock release event to release the lock
|
||||
// once all these events are processed
|
||||
user.releaseLock("enterPuzzleLock");
|
||||
|
||||
return pmgr.getConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the user's occupant information from the puzzle object that
|
||||
* they are now departing.
|
||||
*/
|
||||
protected void departPuzzle (BodyObject user)
|
||||
{
|
||||
int puzzleOid = ((PuzzlerObject)user).getPuzzleLoc();
|
||||
if (puzzleOid == -1) {
|
||||
return;
|
||||
}
|
||||
int bodoid = user.getOid();
|
||||
|
||||
// remove them from the occupant list of the previous puzzle
|
||||
try {
|
||||
PlaceObject pold = (PlaceObject)_omgr.getObject(puzzleOid);
|
||||
if (pold != null) {
|
||||
Integer key = new Integer(bodoid);
|
||||
// remove their occupant info (which is keyed on oid) and
|
||||
// remove them from the occupant list
|
||||
pold.startTransaction();
|
||||
try {
|
||||
pold.removeFromOccupantInfo(key);
|
||||
pold.removeFromOccupants(bodoid);
|
||||
} finally {
|
||||
pold.commitTransaction();
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.info("Body's prior puzzle no longer around? " +
|
||||
"[boid=" + bodoid +
|
||||
", puzoid=" + puzzleOid + "].");
|
||||
}
|
||||
|
||||
} catch (ClassCastException cce) {
|
||||
Log.warning("Body claims to be in puzzle which references " +
|
||||
"non-PlaceObject!? [boid=" + bodoid +
|
||||
", puzoid=" + puzzleOid + "].");
|
||||
}
|
||||
}
|
||||
|
||||
/** The distributed object manager with which we interoperate. */
|
||||
protected RootDObjectManager _omgr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user