/*
** j###t ########## #### ####
** j###t ########## #### ####
** j###T "###L J###"
** ######P' ########## #########
** ######k, ########## T######T
** ####~###L ####
** #### q###L ########## .#####
** #### \###L ########## #####"
**
** Class History
**
** Date Name Description
** ---------|------------|-----------------------------------------------
** 18Jul97 subtle created this class
**
*/
package key;
import java.net.*;
import java.io.*;
import java.util.*;
import java.lang.*;
/**
* This classes isn't strictly _necessary_. We use it to add
* some very forest specific behaviour to Key. (Our special
* rooms, the concept of realms, which we never did finish,
* and our ranks.) You could modify this fairly easily to do
* this for your own talker. It isn't, of course, necessary
* to spell out your categories of rooms in seperate landscapes
* files here - indeed, most of this class only exists because we
* wanted to seperate the data into different files, as opposed
* to leaving it all in the main one (probably online, but who
* knows.)
*/
public class Forest extends Key
{
private static final long serialVersionUID = 4168035326113564429L;
protected transient Realm realm;
protected transient Realm marshLand;
protected transient Container ranks;
protected transient Rank player;
public Forest()
{
try
{
realm = (Realm) Factory.makeAtom( Realm.class, "realm" );
add( realm );
marshLand = (Realm) Factory.makeAtom( Realm.class, "marshLand" );
add( marshLand );
Landscape ruins = (Landscape) Factory.makeAtom( Landscape.class, "ruins" );
realm.add( ruins );
Landscape city = (Landscape) Factory.makeAtom( Landscape.class, "city" );
realm.add( city );
Landscape outside = (Landscape) Factory.makeAtom( Landscape.class, "outside" );
realm.add( outside );
Landscape caves = (Landscape) Factory.makeAtom( Landscape.class, "caves" );
realm.add( caves );
Log.bootLog( "set up default forest landscape" );
}
catch( NonUniqueKeyException e )
{
Log.debug( this, "couldn't fill forest landscape: " + e.toString() );
}
catch( BadKeyException e )
{
Log.debug( this, "bad forest landscape: " + e.toString() );
}
try
{
ranks = (Container) Factory.makeAtom( Container.class, "ranks" );
ranks.setConstraint( Type.RANK );
add( ranks );
player = (ReverseRank) Factory.makeAtom( ReverseRank.class, "everyone" );
ranks.add( player );
Log.bootLog( "set up default forest ranks" );
}
catch( NonUniqueKeyException e )
{
Log.debug( this, "couldn't fill forest ranks: " + e.toString() );
}
catch( BadKeyException e )
{
Log.debug( this, "bad forest ranks: " + e.toString() );
}
realm.addTopLevel( shortcuts );
marshLand.addTopLevel( shortcuts );
ranks.addTopLevel( shortcuts );
}
protected void initFieldCache()
{
super.initFieldCache();
realm = (Realm) getElement( "realm" );
realm.addReference( this );
marshLand = (Realm) getElement( "marshland" );
marshLand.addReference( this );
ranks = (Container) getElement( "ranks" );
ranks.addReference( this );
player = (Rank) ranks.getElement( "everyone" );
player.addReference( this );
}
public Room getConnectRoom( Player p )
{
// if they had a last public
// location, use it.
{
Room r = p.getLastPublicRoom();
if( r != null )
return( r );
}
// pick a random room for them from the
// entry rooms for realm.
Landscape er = realm.getEntryRooms();
int c = er.count();
if( c == 0 )
return( super.getConnectRoom( p ) );
else
{
Random r = new Random();
int ran = Math.abs( r.nextInt() ) % c;
return( (Room) er.getElementAt( ran ) );
}
}
// the rank a new player gets put in
public Rank getInitialRank()
{
return( null );
}
public Container getRanks()
{
return( ranks );
}
public Realm getDefaultRealm()
{
return( realm );
}
}