📄 worldmanager.java
字号:
return null;
return bMap.getInteriorMapFromID( location.getInteriorMapID() );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To Get a Room from a WotlasLocation. IMPORTANT: we assume the
* WotlasLocation object points out a room...
*
* @param location wotlas location
* @return corresponding Room, null if the map does not exist.
*/
public Room getRoom( WotlasLocation location ) {
InteriorMap iMap = getInteriorMap( location );
if(iMap==null)
return null;
return iMap.getRoomFromID( location.getRoomID() );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Add a new WorldMap object to the array {@link #worldMaps worldMaps}
*
* IMPORTANT: WorldManager methods are not synchronized. Handle this method
* with care ( Server locked and no connected clients ).
*
* @return a new WorldMap object
*/
public WorldMap addWorldMap() {
WorldMap myWorldMap = new WorldMap();
if (worldMaps == null) {
worldMaps = new WorldMap[1];
myWorldMap.setWorldMapID(0);
worldMaps[0] = myWorldMap;
} else {
WorldMap[] myWorldMaps = new WorldMap[worldMaps.length+1];
myWorldMap.setWorldMapID(worldMaps.length);
System.arraycopy(worldMaps, 0, myWorldMaps, 0, worldMaps.length);
myWorldMaps[worldMaps.length] = myWorldMap;
worldMaps = myWorldMaps;
}
return myWorldMap;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Add a player to this universe.
* @param player player to add to this world.
*/
public void addPlayerToUniverse( Player player ) {
editPlayer( player, true ); // no control on server location, we assume locality
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Remove a player from the universe.
* @param player the player to remove.
*/
public void removePlayerFromUniverse( Player player ) {
editPlayer( player, false );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Add a player to this universe (addButNotRemove=true) or removes a player from
* this universe (addButNotRemove=false). The player must have been previously initialized.
* IMPORTANT: if the location points out a room we assume that the room is LOCAL, i.e.
* local to this server.
*
* @param player player to add/remove
* @param addButNotRemove set to true if tou want to add this player, set to false
* if you want to remove the player.
*/
protected void editPlayer( Player player, boolean addButNotRemove ) {
// Get Location & location type
WotlasLocation location = player.getLocation();
if( location==null ) {
Debug.signal( Debug.ERROR, this, "Player "+player.toString()+" has no WotlasLocation.");
return;
}
// does this world exists ?
WorldMap world = getWorldMapFromID( location.getWorldMapID() );
if( world==null ) {
Debug.signal( Debug.ERROR, this, "Player "+player.toString()+" has bad location.");
return;
}
// add/remove player
if( location.isWorld() ) {
if(addButNotRemove)
world.getMessageRouter().addPlayer( player );
else
world.getMessageRouter().removePlayer( player );
}
else{
// does this town exists ?
TownMap town = world.getTownMapFromID( location.getTownMapID() );
if(town==null) {
Debug.signal( Debug.ERROR, this, "Player "+player.toString()+" has bad location." );
return;
}
if( location.isTown() ) {
if(addButNotRemove)
town.getMessageRouter().addPlayer( player );
else
town.getMessageRouter().removePlayer( player );
}
else if( location.isRoom() )
{
// does this building exists ?
Building building = town.getBuildingFromID( location.getBuildingID() );
if(building==null) {
Debug.signal( Debug.ERROR, this, "Player "+player.toString()+" has bad location." );
return;
}
// does this interiorMap exists ?
InteriorMap map = building.getInteriorMapFromID( location.getInteriorMapID() );
if(map==null) {
Debug.signal( Debug.ERROR, this, "Player "+player.toString()+" has bad location." );
return;
}
// does this room exists ?
Room room = map.getRoomFromID( location.getRoomID() );
if(room==null) {
Debug.signal( Debug.ERROR, this, "Player "+player.toString()+" has bad location." );
return;
}
// pheewww... ok, we add/remove this player...
if(addButNotRemove)
room.getMessageRouter().addPlayer( player );
else
room.getMessageRouter().removePlayer( player );
}
else
Debug.signal( Debug.ERROR, this, "Player "+player.toString()+" has strange location." );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To Get a valid WorldID ( for player inits ).
*
* @return a valid worldMap ID, -1 if there are none
*/
public int getAValidWorldID() {
if(worldMaps==null)
return -1;
for( int i=0; i<worldMaps.length; i++ )
if( worldMaps[i]!=null )
return i;
return -1;
}
/*------------------------------------------------------------------------------------*/
/** To load the local game universe.
*
* @param loadDefault do we have to load default data ?
*/
public void loadUniverse( boolean loadDefault ) {
loadUniverse( loadDefault, false );
}
/** To load the local game universe.
*
* @param loadDefault do we have to load default data ?
*/
public void loadUniverse( boolean loadDefault, boolean pleaseLoadTreeForEditor ) {
int worldCount=0, townCount=0, buildingCount=0, mapCount=0, tileMapCount=0;
String universeHome = rManager.getUniverseDataDir()+DEFAULT_UNIVERSE+"/";
/*** STEP 1 - WE LOAD LOCATIONS (default data) ***/
String worldList[] = rManager.listUniverseDirectories( universeHome );
Debug.signal( Debug.NOTICE, null, "Loading Universe Data from : "
+universeHome+" preloader status ["+PRELOADER_STATUS+"]" );
worldMaps = null;
// ok, here we go ! we load all the worlds we can find...
for( int w=0; w<worldList.length; w++ ) {
// we load the world object
if(worldList[w].endsWith("/CVS/") || worldList[w].endsWith("\\CVS\\"))
continue; // this is a CVS directory
WorldMap world = (WorldMap) rManager.loadObject( worldList[w] + WORLD_FILE );
if( world==null ) {
Debug.signal(Debug.WARNING, this, "Failed to load World : "+worldList[w]);
continue;
}
if(worldMaps == null) {
worldMaps = new WorldMap[world.getWorldMapID()+1];
}
else if( worldMaps.length <= world.getWorldMapID() ) {
WorldMap[] myWorldMaps = new WorldMap[world.getWorldMapID()+1];
System.arraycopy( worldMaps, 0, myWorldMaps, 0, worldMaps.length );
worldMaps = myWorldMaps;
}
worldMaps[world.getWorldMapID()] = world;
worldCount++;
// we load all the towns of this world
String townList[] = rManager.listUniverseDirectories( worldList[w], TOWN_DIR_EXT );
for( int t=0; t<townList.length; t++ ) {
// we load the town objects
TownMap town = (TownMap) rManager.loadObject( townList[t] + TOWN_FILE );
if( town==null ) {
Debug.signal(Debug.WARNING, this, "Failed to load Town : "+townList[t]);
continue;
}
world.addTownMap( town );
townCount++;
// we load all this town's buildings
String buildingList[] = rManager.listUniverseDirectories( townList[t] );
for( int b=0; b<buildingList.length; b++ ) {
// we load the building objects
Building building = (Building) rManager.loadObject( buildingList[b] + BUILDING_FILE );
if( building==null ) {
Debug.signal(Debug.WARNING, this, "Failed to load building : "+buildingList[b]);
continue;
}
town.addBuilding( building );
buildingCount++;
// we load all this building's maps
String mapList[] = rManager.listUniverseFiles( buildingList[b], MAP_SUFFIX );
for( int m=0; m<mapList.length; m++ ) {
if( mapList[m].equals( buildingList[b]+BUILDING_FILE ) )
continue;
// we load the map objects
InteriorMap map = (InteriorMap) rManager.loadObject( mapList[m] );
if( map==null ) {
Debug.signal(Debug.WARNING, this, "Failed to load map : "+mapList[m]);
continue;
}
building.addInteriorMap( map );
mapCount++;
}
}
}
if( pleaseLoadTreeForEditor )
EditorPlugIn.treeOfTileMapNode = new DefaultMutableTreeNode("World : Tile Maps");
DefaultMutableTreeNode area = null;
DefaultMutableTreeNode map = null;
// managing tile maps : PART I
// we load all the tilemap of this world that are cities on the map
TileMap.SetClassPreloader( PRELOADER_STATUS );
String tileMapList[] = rManager.listUniverseDirectories( worldList[w], TILEMAP_DIR_EXT );
for( int t=0; t<tileMapList.length; t++ ) {
// we load the tileMap objects
TileMap tileMap = (TileMap) rManager.RestoreObject( tileMapList[t] + TILEMAP_FILE );
tileMap.SetPreloader(tileMapList[t] + TILEMAP_FILE);
if( tileMap==null ) {
Debug.signal(Debug.WARNING, this, "Failed to load TileMap : "+tileMapList[t]);
continue;
}
world.addTileMap( tileMap );
tileMapCount++;
if( pleaseLoadTreeForEditor ) {
map = EditorPlugIn.createNode( tileMap );
EditorPlugIn.treeOfTileMapNode.add( map );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -