⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worldmanager.java

📁 Vyger offers a D & D and Rogue-like environment in a graphical online roleplay game.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
             // managing tile maps : PART II
             // we load all the tilemap of this world that saved in .area directory
             String areaMapList[] = rManager.listUniverseDirectories( worldList[w], AREA_EXT);
             for( int index=0; index<areaMapList.length; index++ ) {
                  String insideAreaTileMapList[] = rManager.listUniverseFiles( areaMapList[index], TILEMAP_EXT );
                  for( int index2=0; index2<insideAreaTileMapList.length; index2++ ) {
                      TileMap tileMap = (TileMap) rManager.RestoreObject( insideAreaTileMapList[index2] );
                      tileMap.SetPreloader(insideAreaTileMapList[index2]);
                      if( tileMap==null ) {
                          Debug.signal(Debug.WARNING, this, "Failed to load TileMap : "+insideAreaTileMapList[index2]);
                          continue;
                      }
                      world.addTileMap( tileMap );
                      tileMapCount++;
                      if( pleaseLoadTreeForEditor && index2==0 ) {
                          area = new DefaultMutableTreeNode( tileMap.getAreaName() );
                          EditorPlugIn.treeOfTileMapNode.add(area);
                      }
                      if( pleaseLoadTreeForEditor ) {
                          map = EditorPlugIn.createNode( tileMap );
                          area.add( map );
                      }
                  }
             }

        }

       Debug.signal( Debug.NOTICE, null, "World Manager loaded "+worldCount+" worlds, "+townCount+" towns, "
                    +buildingCount+" buildings, "+mapCount+" maps ans "+tileMapCount+" TileMaps.");

    /*** STEP 2 - WE LOAD OBJECTS (latest data) ***/
      int roomInventoryCount = 0;

      if(!loadDefault) {  // if loaddefault==true we only want to save default location data, not objects

          String objectsHome =  rManager.getUniverseDataDir()+DEFAULT_UNIVERSE_OBJECTS+"/";

          worldList = rManager.listUniverseDirectories( objectsHome );

     // ok, here we go ! we load all the objects we can find...
          for( int w=0; w<worldList.length; w++ ) {

          // we load the world that contain objects
             if(worldList[w].endsWith("/CVS/") || worldList[w].endsWith("\\CVS\\"))
                continue; // this is a CVS directory

          // we load all the towns of this world
             String townList[] = rManager.listUniverseDirectories( worldList[w] );

             for( int t=0; t<townList.length; t++ ) {

               // we load all this town's buildings
                  String buildingList[] = rManager.listUniverseDirectories( townList[t] );

                  for( int b=0; b<buildingList.length; b++ ) {

                     // we load all this building's maps
                        String mapList[] = rManager.listUniverseFiles( buildingList[b], MAP_SUFFIX );

                        for( int m=0; m<mapList.length; m++ ) {

                         // we load the map objects
                            RoomInventory roomInv = (RoomInventory) rManager.loadObject( mapList[m] );

                            if( roomInv==null ) {
                                Debug.signal(Debug.WARNING, this, "Failed to load inventory : "+mapList[m]);
                                continue;
                            }

                         // we associate the RoomInventory to its Room
                            Room associatedRoom = getRoom(roomInv.getLocation());
                            
                            if( associatedRoom==null ) {
                                Debug.signal(Debug.ERROR, this, "Failed to find room for roomInventory : "+mapList[m]);
                                continue;
                            }

                            associatedRoom.setInventory(roomInv);
                            roomInventoryCount++;
                        }
                  }
             }
        }
      }

      Debug.signal( Debug.NOTICE, null, "World Manager loaded "+roomInventoryCount+" room inventories." );

                    
    /*** STEP 3 - WE INIT THE WORLD ***/
       init();
   }

 /*------------------------------------------------------------------------------------*/

  /** To save the local game universe.
   *
   *  @param isDefault if true we save all data in their DEFAULT directory.
   *  @return true in case of success, false otherwise
   */
   public boolean saveUniverse( boolean isDefault ) {

     int worldCount=0, townCount=0, buildingCount=0, mapCount=0, tileMapCount=0;

   /*** STEP 1 - We only have to save location data if they are to be saved as default ***/

     if( isDefault ) {

        String universeHome = rManager.getUniverseDataDir()+DEFAULT_UNIVERSE+"/";

     // We create this directory... (we expect that the directory is outside the JAR)
        new File(universeHome).mkdirs();

     // ok, here we go ! we save all our world data...
        Debug.signal( Debug.NOTICE, this, "Saving Universe Data to :"+universeHome );

        for( int w=0; w<worldMaps.length; w++ ) {
             if( worldMaps[w]==null ) continue;
    
          // we create the world directory
             String worldHome =  universeHome + worldMaps[w].getShortName() + "/";
             new File(worldHome).mkdir();

          // we save the world object
             if( !rManager.saveObject( worldMaps[w], worldHome + WORLD_FILE ) ) {
                 Debug.signal(Debug.ERROR,this,"Failed to save world : "+worldHome );
                 continue;
             }

             worldCount++;

          // we save all the tilemap of this world
             TileMap tileMaps[] = worldMaps[w].getTileMaps();
             if( tileMaps != null ) {
             for( int t=0; t<tileMaps.length; t++ ) {
                  if( tileMaps[t]==null ) continue;
                       // we save the tilemap object
                      if( tileMaps[t].getAreaName().length() <= 0 ){
                          String tileMapHome =  worldHome + tileMaps[t].getShortName() + TILEMAP_DIR_EXT +"/";
                          new File(tileMapHome).mkdir();
                          if( !rManager.BackupObject( tileMaps[t], tileMapHome + TILEMAP_FILE ) ) {
                              Debug.signal(Debug.ERROR,this,"Failed to save tileMap : "+tileMapHome );
                              continue;
                          }
                      }
                      else{
                          String areaOfTile =  worldHome + tileMaps[t].getAreaName() + WorldManager.AREA_EXT + "/";
                          new File(areaOfTile).mkdir();
                          if( !rManager.BackupObject( tileMaps[t], areaOfTile
                          + tileMaps[t].getShortName() + WorldManager.TILEMAP_EXT  ) ){
                              Debug.signal(Debug.ERROR,this,"Failed to save tileMap : "+areaOfTile );
                              continue;
                          }                          
                      }
                      tileMapCount++;
                  }
             }
             
          // we save all the towns of this world
             TownMap towns[] = worldMaps[w].getTownMaps();
             if( towns == null ) continue;

             for( int t=0; t<towns.length; t++ ) {
                  if( towns[t]==null ) continue;

               // we save the town object
                  String townHome =  worldHome + towns[t].getShortName()+ TOWN_DIR_EXT +"/";
                  new File(townHome).mkdir();

                  if( !rManager.saveObject( towns[t], townHome + TOWN_FILE ) ) {
                      Debug.signal(Debug.ERROR,this,"Failed to save town : "+townHome );
                      continue;
                  }

                  townCount++;

               // we save all this town's buildings
                  Building buildings[] = towns[t].getBuildings();
                  if( buildings==null ) continue;

                  for( int b=0; b<buildings.length; b++ ) {
                       if( buildings[b]==null ) continue;

                    // we save the building objects
                       String buildingHome =  townHome + buildings[b].getShortName() + "/";
                       new File(buildingHome).mkdir();

                       if( !rManager.saveObject( buildings[b], buildingHome + BUILDING_FILE ) ) {
                           Debug.signal(Debug.ERROR,this,"Failed to save building : "+buildingHome );
                           continue;
                       }

                       buildingCount++;

                    // we save all this building's maps
                       InteriorMap interiorMaps[] = buildings[b].getInteriorMaps();
                       if( interiorMaps==null ) continue;

                       for( int m=0; m<interiorMaps.length; m++ ) {
                            if( interiorMaps[m]==null ) continue;

                         // we save the maps
                            String mapName =  buildingHome + interiorMaps[m].getShortName() + MAP_SUFFIX;

                            if( !rManager.saveObject( interiorMaps[m], mapName ) ) {
                                Debug.signal(Debug.ERROR,this,"Failed to save map : "+mapName );
                                continue;
                            }

                            mapCount++;
                       }
                  }
             }
        }
     }

    /*** STEP 2 - WE SAVE OBJECTS DATA
     ***
     *** Note that objects are only stored in Rooms (RoomInventory).
     ***/
     int inventoryCount = 0;

     if( ! isDefault ) {  // we only save objects if default==false ( default means location data only )

        String objectsHome =  rManager.getUniverseDataDir()+DEFAULT_UNIVERSE_OBJECTS+"/";

     // We create this directory... (we expect that the directory is outside the JAR)
        new File(objectsHome).mkdirs();

     // ok, here we go ! we save all our world data...
        Debug.signal( Debug.NOTICE, this, "Saving Universe's Objects to :"+objectsHome );

        for( int w=0; w<worldMaps.length; w++ ) {
             if( worldMaps[w]==null ) continue;
    
          // we create the world directory
             String worldHome =  objectsHome + worldMaps[w].getShortName() + "/";
             new File(worldHome).mkdir();

          // we save all the town objects of this world
             TownMap towns[] = worldMaps[w].getTownMaps();
             if( towns == null ) continue;

             for( int t=0; t<towns.length; t++ ) {
                  if( towns[t]==null ) continue;

               // we save the town object
                  String townHome =  worldHome + towns[t].getShortName()+"/";
                  new File(townHome).mkdir();

               // we save all this town's buildings
                  Building buildings[] = towns[t].getBuildings();
                  if( buildings==null ) continue;

                  for( int b=0; b<buildings.length; b++ ) {
                       if( buildings[b]==null ) continue;

                    // we save the building's objects
                       String buildingHome =  townHome + buildings[b].getShortName() + "/";
                       new File(buildingHome).mkdir();

                    // we save all this building's maps
                       InteriorMap interiorMaps[] = buildings[b].getInteriorMaps();
                       if( interiorMaps==null ) continue;

                       for( int m=0; m<interiorMaps.length; m++ ) {
                            if( interiorMaps[m]==null ) continue;

                         // we save all the RoomInventories
                            Room rooms[] = interiorMaps[m].getRooms();
                            if( rooms==null ) continue;

                            for( int r=0; r<rooms.length; r++ ) {
                                 if( rooms[r]==null || rooms[r].getInventory()==null ) continue;

                                 String inventoryName = buildingHome + INVENTORY_PREFIX
                                             + rooms[r].getMyInteriorMap().getInteriorMapID()
                                             +"-"+rooms[r].getRoomID() + INVENTORY_SUFFIX;

                                 if( !rManager.saveObject( rooms[r].getInventory(), inventoryName ) ) {
                                     Debug.signal(Debug.ERROR,this,"Failed to save room inventory : "+inventoryName );
                                     continue;
                                 }

                                 inventoryCount++;
                           }
                       }
                  }
             }
        }
     }

    /*** STEP 3 - Print some stats for control ***/
     if(isDefault)
         Debug.signal( Debug.NOTICE, this, "Saved "+worldCount+" worlds, "+townCount+" towns, "
                       +buildingCount+" buildings, "+mapCount+" maps, and "+tileMapCount+" tilemaps." );
     else
         Debug.signal( Debug.NOTICE, this, "Saved "+inventoryCount+" room inventories.");

     return true;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -