Package net.sf.l2j.gameserver.model.zone

Examples of net.sf.l2j.gameserver.model.zone.L2ZoneType


              int maxZ = Integer.parseInt(attrs.getNamedItem("maxZ").getNodeValue());
              String zoneType = attrs.getNamedItem("type").getNodeValue();
              String zoneShape = attrs.getNamedItem("shape").getNodeValue();

              // Create the zone
              L2ZoneType temp = null;

              if (zoneType.equals("FishingZone"))
                 temp = new L2FishingZone();
              else if (zoneType.equals("ClanHallZone"))
                 temp = new L2ClanHallZone();
              else if (zoneType.equals("PeaceZone"))
                temp = new L2PeaceZone();
              else if (zoneType.equals("Town"))
                temp = new L2TownZone();
              else if (zoneType.equals("OlympiadStadium"))
                temp = new L2OlympiadStadiumZone();
              else if (zoneType.equals("CastleZone"))
                temp = new L2CastleZone();
              else if (zoneType.equals("DamageZone"))
                temp = new L2DamageZone();
              else if (zoneType.equals("Arena"))
                temp = new L2ArenaZone();
              else if (zoneType.equals("MotherTree"))
                temp = new L2MotherTreeZone();
              else if (zoneType.equals("BigheadZone"))
                temp = new L2BigheadZone();
              else if (zoneType.equals("NoLandingZone"))
                temp = new L2NoLandingZone();
              else if (zoneType.equals("JailZone"))
                temp = new L2JailZone();
              else if (zoneType.equals("DerbyTrackZone"))
                temp = new L2DerbyTrackZone();


              // Check for unknown type
              if (temp == null)
              {
                _log.warning("ZoneData: No such zone type: "+zoneType);
                continue;
              }

              // Get the zone shape from sql
              try
              {
                PreparedStatement statement = null;

                // Set the correct query
                statement = con.prepareStatement("SELECT x,y FROM zone_vertices WHERE id=? ORDER BY 'order' ASC ");

                statement.setInt(1, zoneId);
                ResultSet rset = statement.executeQuery();

                // Create this zone.  Parsing for cuboids is a bit different than for other polygons
                // cuboids need exactly 2 points to be defined.  Other polygons need at least 3 (one per vertex)
                if (zoneShape.equals("Cuboid"))
                {
                  int[] x = {0,0};
                  int[] y = {0,0};
                  boolean successfulLoad = true;
                 
                  for (int i=0;i<2; i++)
                  {
                    if ( rset.next() )
                    {
                      x[i] = rset.getInt("x");
                      y[i] = rset.getInt("y");
                    }
                    else
                    {
                      _log.warning("ZoneData: Missing cuboid vertex in sql data for zone: "+zoneId);
                      rset.close();
                      statement.close();
                      successfulLoad = false;
                      break;
                    }
                  }

                  if (successfulLoad)
                    temp.setZone(new ZoneCuboid(x[0],x[1], y[0],y[1],minZ,maxZ));
                  else
                    continue;
                }
                else if (zoneShape.equals("NPoly"))
                {
                  FastList<Integer> fl_x = new FastList<Integer>(), fl_y = new FastList<Integer>();

                  // Load the rest
                  while (rset.next())
                  {
                    fl_x.add(rset.getInt("x"));
                    fl_y.add(rset.getInt("y"));
                  }

                  // An nPoly needs to have at least 3 vertices
                  if ((fl_x.size() == fl_y.size()) && (fl_x.size() > 2))
                  {
                    // Create arrays
                    int[] aX = new int[fl_x.size()];
                    int[] aY = new int[fl_y.size()];
 
                    // This runs only at server startup so dont complain :>
                    for (int i=0; i < fl_x.size(); i++) { aX[i] = fl_x.get(i); aY[i] = fl_y.get(i); }
 
                    // Create the zone
                    temp.setZone(new ZoneNPoly(aX, aY, minZ, maxZ));
                  }
                  else
                  {
                    _log.warning("ZoneData: Bad sql data for zone: "+zoneId);
                    rset.close();
                    statement.close();
                    continue;
                  }
                }
                else
                {
                  _log.warning("ZoneData: Unknown shape: "+zoneShape);
                  rset.close();
                  statement.close();
                  continue;
                }

                rset.close();
                statement.close();
              }
              catch (Exception e)
              {
                _log.warning("ZoneData: Failed to load zone coordinates: " + e);
              }


              // Check for aditional parameters
              for (Node cd=d.getFirstChild(); cd != null; cd = cd.getNextSibling())
              {
                if ("stat".equalsIgnoreCase(cd.getNodeName()))
                {
                  attrs = cd.getAttributes();
                  String name = attrs.getNamedItem("name").getNodeValue();
                                String val = attrs.getNamedItem("val").getNodeValue();

                                temp.setParameter(name, val);
                }
              }

              // Skip checks for fishing zones & add to fishing zone manager
              if (temp instanceof L2FishingZone)
              {
                FishingZoneManager.getInstance().addFishingZone((L2FishingZone)temp);
                continue;
              }

              // Register the zone into any world region it intersects with...
              // currently 11136 test for each zone :>
              int ax,ay,bx,by;
              for (int x=0; x < worldRegions.length; x++)
              {
                for (int y=0; y < worldRegions[x].length; y++)
                {
                  ax = (x-L2World.OFFSET_X) << L2World.SHIFT_BY;
                  bx = ((x+1)-L2World.OFFSET_X) << L2World.SHIFT_BY;
                  ay = (y-L2World.OFFSET_Y) << L2World.SHIFT_BY;
                  by = ((y+1)-L2World.OFFSET_Y) << L2World.SHIFT_BY;

                  if (temp.getZone().intersectsRectangle(ax, bx, ay, by))
                  {
                    if (Config.DEBUG)
                    {
                      _log.info("Zone ("+zoneId+") added to: "+x+" "+y);
                    }
View Full Code Here

TOP

Related Classes of net.sf.l2j.gameserver.model.zone.L2ZoneType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.