Ver código fonte

BETA: Reworking isInsideRadius method.
* Now we have only 2 methods, 1 accepting primitives, 1 accepting objects.
* Removing ExtensionFunction, it isn't used anywhere.

* Reviewed by: UnAfraid, Zoey76

xban1x 11 anos atrás
pai
commit
8ac5301b88

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2AttackableAI.java

@@ -675,7 +675,7 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 				y1 = npc.getSpawn().getY();
 				z1 = npc.getSpawn().getZ();
 				
-				if (!npc.isInsideRadius(x1, y1, range, false))
+				if (!npc.isInsideRadius(x1, y1, 0, range, false, false))
 				{
 					npc.setisReturningToSpawnPoint(true);
 				}
@@ -885,7 +885,7 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 						newY = mostHate.getY() - newY;
 					}
 					
-					if (!npc.isInsideRadius(newX, newY, collision, false))
+					if (!npc.isInsideRadius(newX, newY, 0, collision, false, false))
 					{
 						int newZ = npc.getZ() + 30;
 						if ((Config.GEODATA == 0) || GeoData.getInstance().canMoveFromToTarget(npc.getX(), npc.getY(), npc.getZ(), newX, newY, newZ, npc.getInstanceId()))

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2CharacterAI.java

@@ -977,7 +977,7 @@ public class L2CharacterAI extends AbstractAI
 			return false; // skill radius -1
 		}
 		
-		if (!_actor.isInsideRadius(worldPosition.getX(), worldPosition.getY(), offset + _actor.getTemplate().getCollisionRadius(), false))
+		if (!_actor.isInsideRadius(worldPosition, offset + _actor.getTemplate().getCollisionRadius(), false, false))
 		{
 			if (_actor.isMovementDisabled())
 			{

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

@@ -93,6 +93,7 @@ import com.l2jserver.gameserver.model.holders.SkillHolder;
 import com.l2jserver.gameserver.model.holders.SkillUseHolder;
 import com.l2jserver.gameserver.model.interfaces.IChanceSkillTrigger;
 import com.l2jserver.gameserver.model.interfaces.IDeletable;
+import com.l2jserver.gameserver.model.interfaces.ILocational;
 import com.l2jserver.gameserver.model.interfaces.IPositionable;
 import com.l2jserver.gameserver.model.interfaces.ISkillsHolder;
 import com.l2jserver.gameserver.model.itemcontainer.Inventory;
@@ -4729,35 +4730,16 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
 	}
 	
 	/**
-	 * Check if this object is inside the given radius around the given object. Warning: doesn't cover collision radius!
-	 * @param object the target
-	 * @param radius the radius around the target
-	 * @param checkZ should we check Z axis also
-	 * @param strictCheck true if (distance < radius), false if (distance <= radius)
-	 * @return true is the L2Character is inside the radius.
-	 * @see #isInsideRadius(int, int, int, int, boolean, boolean)
-	 */
-	public final boolean isInsideRadius(L2Object object, int radius, boolean checkZ, boolean strictCheck)
-	{
-		return isInsideRadius(object.getX(), object.getY(), object.getZ(), radius, checkZ, strictCheck);
-	}
-	
-	/**
-	 * Check if this object is inside the given plan radius around the given point. Warning: doesn't cover collision radius!
-	 * @param x X position of the target
-	 * @param y Y position of the target
+	 * Check if this object is inside the given radius around the given point.
+	 * @param loc Location of the target
 	 * @param radius the radius around the target
+	 * @param checkZAxis should we check Z axis also
 	 * @param strictCheck true if (distance < radius), false if (distance <= radius)
-	 * @return true is the L2Character is inside the radius.
+	 * @return true if the L2Character is inside the radius.
 	 */
-	public final boolean isInsideRadius(int x, int y, int radius, boolean strictCheck)
-	{
-		return isInsideRadius(x, y, 0, radius, false, strictCheck);
-	}
-	
-	public final boolean isInsideRadius(Location loc, int radius, boolean checkZ, boolean strictCheck)
+	public final boolean isInsideRadius(ILocational loc, int radius, boolean checkZAxis, boolean strictCheck)
 	{
-		return isInsideRadius(loc.getX(), loc.getY(), loc.getZ(), radius, checkZ, strictCheck);
+		return isInsideRadius(loc.getX(), loc.getY(), loc.getZ(), radius, checkZAxis, strictCheck);
 	}
 	
 	/**
@@ -4766,39 +4748,17 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
 	 * @param y Y position of the target
 	 * @param z Z position of the target
 	 * @param radius the radius around the target
-	 * @param checkZ should we check Z axis also
+	 * @param checkZAxis should we check Z axis also
 	 * @param strictCheck true if (distance < radius), false if (distance <= radius)
-	 * @return true is the L2Character is inside the radius.
+	 * @return true if the L2Character is inside the radius.
 	 */
-	public final boolean isInsideRadius(int x, int y, int z, int radius, boolean checkZ, boolean strictCheck)
+	public final boolean isInsideRadius(int x, int y, int z, int radius, boolean checkZAxis, boolean strictCheck)
 	{
-		double dx = x - getX();
-		double dy = y - getY();
-		double dz = z - getZ();
-		boolean isInsideRadius = false;
-		if (strictCheck)
-		{
-			if (checkZ)
-			{
-				isInsideRadius = ((dx * dx) + (dy * dy) + (dz * dz)) < (radius * radius);
-			}
-			else
-			{
-				isInsideRadius = ((dx * dx) + (dy * dy)) < (radius * radius);
-			}
-		}
-		else
-		{
-			if (checkZ)
-			{
-				isInsideRadius = ((dx * dx) + (dy * dy) + (dz * dz)) <= (radius * radius);
-			}
-			else
-			{
-				isInsideRadius = ((dx * dx) + (dy * dy)) <= (radius * radius);
-			}
-		}
-		return isInsideRadius;
+		final double dx = x - getX();
+		final double dy = y - getY();
+		final double dz = z - getZ();
+		final double distance = (dx * dx) + (dy * dy) + (checkZAxis ? (dz * dz) : 0);
+		return (strictCheck) ? (distance < (radius * radius)) : (distance <= (radius * radius));
 	}
 	
 	// /**

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

@@ -140,7 +140,7 @@ public class L2DefenderInstance extends L2Attackable
 		{
 			return;
 		}
-		if (!isInsideRadius(getSpawn().getX(), getSpawn().getY(), 40, false))
+		if (!isInsideRadius(getSpawn(), 40, false, false))
 		{
 			if (Config.DEBUG)
 			{

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

@@ -102,7 +102,7 @@ public class L2FortCommanderInstance extends L2DefenderInstance
 	@Override
 	public void returnHome()
 	{
-		if (!isInsideRadius(getSpawn().getX(), getSpawn().getY(), 200, false))
+		if (!isInsideRadius(getSpawn(), 200, false, false))
 		{
 			if (Config.DEBUG)
 			{

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

@@ -106,7 +106,7 @@ public class L2GuardInstance extends L2Attackable
 	@Override
 	public void returnHome()
 	{
-		if (!isInsideRadius(getSpawn().getX(), getSpawn().getY(), 150, false))
+		if (!isInsideRadius(getSpawn(), 150, false, false))
 		{
 			clearAggroList();
 			

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

@@ -40,7 +40,7 @@ public final class L2ObservationInstance extends L2Npc
 	{
 		String filename = null;
 		
-		if (isInsideRadius(-79884, 86529, 50, true) || isInsideRadius(-78858, 111358, 50, true) || isInsideRadius(-76973, 87136, 50, true) || isInsideRadius(-75850, 111968, 50, true))
+		if (isInsideRadius(-79884, 86529, 0, 50, false, true) || isInsideRadius(-78858, 111358, 0, 50, false, true) || isInsideRadius(-76973, 87136, 0, 50, false, true) || isInsideRadius(-75850, 111968, 0, 50, false, true))
 		{
 			if (val == 0)
 			{

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/zone/type/L2BossZone.java

@@ -286,7 +286,7 @@ public class L2BossZone extends L2ZoneType
 							{
 								continue;
 							}
-							if (!raid.isInsideRadius(raid.getSpawn().getX(), raid.getSpawn().getY(), 150, false))
+							if (!raid.isInsideRadius(raid.getSpawn(), 150, false, false))
 							{
 								raid.returnHome();
 							}

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestDropItem.java

@@ -166,7 +166,7 @@ public final class RequestDropItem extends L2GameClientPacket
 			return;
 		}
 		
-		if (!activeChar.isInsideRadius(_x, _y, 150, false) || (Math.abs(_z - activeChar.getZ()) > 50))
+		if (!activeChar.isInsideRadius(_x, _y, 0, 150, false, false) || (Math.abs(_z - activeChar.getZ()) > 50))
 		{
 			if (Config.DEBUG)
 			{

+ 0 - 41
L2J_Server_BETA/java/com/l2jserver/gameserver/util/ExtensionFunction.java

@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2004-2013 L2J Server
- * 
- * This file is part of L2J Server.
- * 
- * L2J Server is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * L2J Server is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package com.l2jserver.gameserver.util;
-
-/**
- * This interface can be implemented by extensions to register simple functions with the DynamicExtension handler.<br>
- * It's in the responsibility of the extensions to interpret the get and set functions.
- * @author Galun
- */
-public interface ExtensionFunction
-{
-	/**
-	 * get an object identified with a name (should have a human readable output with toString())
-	 * @param name the name of an object or a result of a function
-	 * @return the object
-	 */
-	public Object get(String name);
-	
-	/**
-	 * set the named object to the new value supplied in obj
-	 * @param name the name of the object
-	 * @param obj the new value
-	 */
-	public void set(String name, Object obj);
-}