Преглед на файлове

BETA: `Geodata#getSpawnHeight` uses just `z` coordinate now removed `zmin` and `zmax`.

Reviewed by: !UnAfraid
Nos преди 10 години
родител
ревизия
066512994c

+ 13 - 4
L2J_Server_BETA/java/com/l2jserver/gameserver/GeoData.java

@@ -180,14 +180,23 @@ public class GeoData implements IGeoDriver
 	 * Gets the spawn height.
 	 * @param x the x coordinate
 	 * @param y the y coordinate
-	 * @param zmin the minimum z coordinate
-	 * @param zmax the the maximum z coordinate
+	 * @param z the the z coordinate
 	 * @return the spawn height
 	 */
-	public int getSpawnHeight(int x, int y, int zmin, int zmax)
+	public int getSpawnHeight(int x, int y, int z)
 	{
 		// + 30, defend against defective geodata and invalid spawn z :(
-		return getNextLowerZ(getGeoX(x), getGeoY(y), zmax + 30);
+		return getNextLowerZ(getGeoX(x), getGeoY(y), z + 30);
+	}
+	
+	/**
+	 * Gets the spawn height.
+	 * @param location the location
+	 * @return the spawn height
+	 */
+	public int getSpawnHeight(Location location)
+	{
+		return getSpawnHeight(location.getX(), location.getY(), location.getZ());
 	}
 	
 	/**

+ 10 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2AttackableAI.java

@@ -631,7 +631,9 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 		// Order to the L2MonsterInstance to random walk (1/100)
 		else if ((npc.getSpawn() != null) && (Rnd.nextInt(RANDOM_WALK_RATE) == 0) && !npc.isNoRndWalk())
 		{
-			int x1, y1, z1;
+			int x1 = 0;
+			int y1 = 0;
+			int z1 = 0;
 			final int range = Config.MAX_DRIFT_RANGE;
 			
 			for (Skill sk : _skillrender.getAISkills(AISkillScope.BUFF))
@@ -646,10 +648,13 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 			if ((npc.getSpawn().getX() == 0) && (npc.getSpawn().getY() == 0) && (npc.getSpawn().getSpawnTerritory() == null))
 			{
 				// Calculate a destination point in the spawn area
-				int p[] = TerritoryTable.getInstance().getRandomPoint(npc.getSpawn().getLocationId());
-				x1 = p[0];
-				y1 = p[1];
-				z1 = p[2];
+				final Location location = TerritoryTable.getInstance().getRandomPoint(npc.getSpawn().getLocationId());
+				if (location != null)
+				{
+					x1 = location.getX();
+					y1 = location.getY();
+					z1 = location.getZ();
+				}
 				
 				// Calculate the distance between the current position of the L2Character and the target (x,y)
 				double distance2 = npc.calculateDistance(x1, y1, 0, false, true);

+ 2 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/TerritoryTable.java

@@ -29,6 +29,7 @@ import java.util.logging.Logger;
 
 import com.l2jserver.L2DatabaseFactory;
 import com.l2jserver.gameserver.model.L2Territory;
+import com.l2jserver.gameserver.model.Location;
 
 /**
  * @author Balancer, Mr
@@ -52,7 +53,7 @@ public class TerritoryTable
 	 * @param terr the territory Id?
 	 * @return the random point
 	 */
-	public int[] getRandomPoint(int terr)
+	public Location getRandomPoint(int terr)
 	{
 		return _territory.get(terr).getRandomPoint();
 	}

+ 10 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2GroupSpawn.java

@@ -52,7 +52,9 @@ public class L2GroupSpawn extends L2Spawn
 				return null;
 			}
 			
-			int newlocx, newlocy, newlocz;
+			int newlocx = 0;
+			int newlocy = 0;
+			int newlocz = 0;
 			
 			if ((getX() == 0) && (getY() == 0))
 			{
@@ -61,10 +63,13 @@ public class L2GroupSpawn extends L2Spawn
 					return null;
 				}
 				
-				int p[] = TerritoryTable.getInstance().getRandomPoint(getLocationId());
-				newlocx = p[0];
-				newlocy = p[1];
-				newlocz = p[2];
+				final Location location = TerritoryTable.getInstance().getRandomPoint(getLocationId());
+				if (location != null)
+				{
+					newlocx = location.getX();
+					newlocy = location.getY();
+					newlocz = location.getZ();
+				}
 			}
 			else
 			{

+ 11 - 6
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Spawn.java

@@ -555,7 +555,9 @@ public class L2Spawn implements IPositionable, IIdentifiable, INamable
 	 */
 	private L2Npc initializeNpcInstance(L2Npc mob)
 	{
-		int newlocx, newlocy, newlocz;
+		int newlocx = 0;
+		int newlocy = 0;
+		int newlocz = 0;
 		
 		// If Locx and Locy are not defined, the L2NpcInstance must be spawned in an area defined by location or spawn territory
 		// New method
@@ -575,12 +577,15 @@ public class L2Spawn implements IPositionable, IIdentifiable, INamable
 			}
 			
 			// Calculate the random position in the location area
-			int p[] = TerritoryTable.getInstance().getRandomPoint(getLocationId());
+			final Location location = TerritoryTable.getInstance().getRandomPoint(getLocationId());
 			
 			// Set the calculated position of the L2NpcInstance
-			newlocx = p[0];
-			newlocy = p[1];
-			newlocz = p[3];
+			if (location != null)
+			{
+				newlocx = location.getX();
+				newlocy = location.getY();
+				newlocz = location.getZ();
+			}
 		}
 		else
 		{
@@ -593,7 +598,7 @@ public class L2Spawn implements IPositionable, IIdentifiable, INamable
 		// don't correct z of flying npc's
 		if (!mob.isFlying())
 		{
-			newlocz = GeoData.getInstance().getSpawnHeight(newlocx, newlocy, newlocz, newlocz);
+			newlocz = GeoData.getInstance().getSpawnHeight(newlocx, newlocy, newlocz);
 		}
 		
 		mob.stopAllEffects();

+ 11 - 17
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Territory.java

@@ -153,9 +153,8 @@ public class L2Territory
 		return (intersect_count % 2) == 1;
 	}
 	
-	public int[] getRandomPoint()
+	public Location getRandomPoint()
 	{
-		int[] p = new int[4];
 		if (_procMax > 0)
 		{
 			int pos = 0;
@@ -165,40 +164,35 @@ public class L2Territory
 				pos += p1._proc;
 				if (rnd <= pos)
 				{
-					p[0] = p1._x;
-					p[1] = p1._y;
-					p[2] = p1._zmin;
-					p[3] = p1._zmax;
-					return p;
+					return new Location(p1._x, p1._y, Rnd.get(p1._zmin, p1._zmax));
 				}
 			}
 			
 		}
 		for (int i = 0; i < 100; i++)
 		{
-			p[0] = Rnd.get(_xMin, _xMax);
-			p[1] = Rnd.get(_yMin, _yMax);
-			if (isInside(p[0], p[1]))
+			int x = Rnd.get(_xMin, _xMax);
+			int y = Rnd.get(_yMin, _yMax);
+			if (isInside(x, y))
 			{
 				double curdistance = 0;
-				p[2] = _zMin + 100;
-				p[3] = _zMax;
+				int zmin = _zMin;
 				for (Point p1 : _points)
 				{
-					double dx = p1._x - p[0];
-					double dy = p1._y - p[1];
+					double dx = p1._x - x;
+					double dy = p1._y - y;
 					double distance = Math.sqrt((dx * dx) + (dy * dy));
 					if ((curdistance == 0) || (distance < curdistance))
 					{
 						curdistance = distance;
-						p[2] = p1._zmin + 100;
+						zmin = p1._zmin;
 					}
 				}
-				return p;
+				return new Location(x, y, Rnd.get(zmin, _zMax));
 			}
 		}
 		_log.warning("Can't make point for territory " + _terr);
-		return p;
+		return null;
 	}
 	
 	public int getProcMax()

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/L2Character.java

@@ -4175,7 +4175,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
 		if ((Config.GEODATA > 0) && (Config.COORD_SYNCHRONIZE == 2) && !isFloating && !m.disregardingGeodata && ((GameTimeController.getInstance().getGameTicks() % 10) == 0 // once a second to reduce possible cpu load
 		) && GeoData.getInstance().hasGeo(xPrev, yPrev))
 		{
-			int geoHeight = GeoData.getInstance().getSpawnHeight(xPrev, yPrev, zPrev - 30, zPrev + 30);
+			int geoHeight = GeoData.getInstance().getSpawnHeight(xPrev, yPrev, zPrev);
 			dz = m._zDestination - geoHeight;
 			// quite a big difference, compare to validatePosition packet
 			if (isPlayer() && (Math.abs(getActingPlayer().getClientZ() - geoHeight) > 200) && (Math.abs(getActingPlayer().getClientZ() - geoHeight) < 1500))