Some cleaning up of the difficulty handling so that we can use it as the

basis for our star system.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3038 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2004-06-22 14:08:58 +00:00
parent 031331a5c3
commit 2f0b9939d7
10 changed files with 32 additions and 119 deletions
@@ -1,5 +1,5 @@
//
// $Id: PuzzleDispatcher.java,v 1.1 2003/11/26 01:42:34 mdb Exp $
// $Id: PuzzleDispatcher.java,v 1.2 2004/06/22 14:08:58 mdb Exp $
package com.threerings.puzzle.server;
@@ -62,13 +62,6 @@ public class PuzzleDispatcher extends InvocationDispatcher
);
return;
case PuzzleMarshaller.CHANGE_DIFFICULTY:
((PuzzleProvider)provider).changeDifficulty(
source,
((Integer)args[0]).intValue()
);
return;
default:
super.dispatchRequest(source, methodId, args);
}
@@ -1,5 +1,5 @@
//
// $Id: PuzzleManager.java,v 1.8 2004/03/06 11:29:19 mdb Exp $
// $Id: PuzzleManager.java,v 1.9 2004/06/22 14:08:58 mdb Exp $
package com.threerings.puzzle.server;
@@ -248,6 +248,11 @@ public abstract class PuzzleManager extends GameManager
// initialize the player status
_puzobj.setPlayerStatus(new int[size]);
// compute the starting difficulty
_puzobj.setDifficulty(computeDifficulty());
Log.info("Computed difficulty [game=" + _puzobj.which() +
", difficulty=" + _puzobj.difficulty + "].");
// initialize the player boards
initBoards();
@@ -284,6 +289,20 @@ public abstract class PuzzleManager extends GameManager
return 0L;
}
/**
* When a puzzle game starts, the manager is given the opportunity to
* configure the puzzle difficulty based on information known about
* the player. Additionally, when the game resets due to the player
* clearing the board, etc. this will be called again, so the
* difficulty can be ramped up as the player progresses. In situations
* where ratings and experience are tracked, the difficulty can be
* seeded based on the players prior performance.
*/
protected int computeDifficulty ()
{
return DEFAULT_DIFFICULTY;
}
// documentation inherited
protected void gameDidStart ()
{
@@ -658,29 +677,6 @@ public abstract class PuzzleManager extends GameManager
*/
protected abstract BoardSummary newBoardSummary (Board board);
// documentation inherited
public void attributeChanged (AttributeChangedEvent event)
{
super.attributeChanged(event);
if (event.getName().equals(PuzzleObject.DIFFICULTY)) {
difficultyChanged(_puzobj.difficulty);
}
}
/**
* Called when the puzzle difficulty level is changed.
*/
public void difficultyChanged (final int level)
{
// let our delegates do their business
applyToDelegates(new DelegateOp() {
public void apply (PlaceManagerDelegate delegate) {
((PuzzleManagerDelegate)delegate).difficultyChanged(level);
}
});
}
// documentation inherited from interface PuzzleGameProvider
public void updateProgress (ClientObject caller, int roundId, int[] events)
{
@@ -1,5 +1,5 @@
//
// $Id: PuzzleManagerDelegate.java,v 1.2 2003/11/26 03:17:16 mdb Exp $
// $Id: PuzzleManagerDelegate.java,v 1.3 2004/06/22 14:08:58 mdb Exp $
package com.threerings.puzzle.server;
@@ -20,12 +20,5 @@ public class PuzzleManagerDelegate extends GameManagerDelegate
_puzmgr = puzmgr;
}
/**
* Called when the puzzle difficulty level is changed.
*/
public void difficultyChanged (int level)
{
}
protected PuzzleManager _puzmgr;
}
@@ -1,5 +1,5 @@
//
// $Id: PuzzleProvider.java,v 1.3 2004/03/06 11:29:19 mdb Exp $
// $Id: PuzzleProvider.java,v 1.4 2004/06/22 14:08:58 mdb Exp $
package com.threerings.puzzle.server;
@@ -115,35 +115,6 @@ public class PuzzleProvider
((PuzzlerObject)user).setPuzzleLoc(-1);
}
/**
* Processes a request from a client to change the difficulty level of
* their current puzzle.
*/
public void changeDifficulty (ClientObject caller, int level)
{
BodyObject user = (BodyObject)caller;
int puzzleOid = ((PuzzlerObject)user).getPuzzleLoc();
// make sure they're currently in a puzzle
if (puzzleOid == -1) {
Log.warning("Received change difficulty 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 change difficulty of a non-existent " +
"puzzle [user=" + user.who() + "].");
return;
}
// change the puzzle difficulty level
PuzzleObject puzobj = (PuzzleObject)pmgr.getPlaceObject();
puzobj.setDifficulty(level);
}
/**
* Moves the specified body from whatever puzzle they currently occupy
* to the puzzle identified by the supplied oid.