Переглянути джерело

BETA: Splitting `IPositionable` into 2 interfaces.
* `ILocational` : Contains only getters.
* `IPositionable` : Extends `ILocational` with addition of setters.
* Adding 1 more method `setXYZ(int x, int y ,int z)`.

* Reviewed by: jurchiks, Nos, UnAfraid, Zoey76

xban1x 11 роки тому
батько
коміт
6d8fb8f1b1

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/GeoData.java

@@ -25,7 +25,7 @@ import com.l2jserver.gameserver.model.L2Object;
 import com.l2jserver.gameserver.model.L2Spawn;
 import com.l2jserver.gameserver.model.Location;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
-import com.l2jserver.gameserver.util.Point3D;
+import com.l2jserver.gameserver.model.interfaces.ILocational;
 
 /**
  * @author -Nemesiss-
@@ -118,7 +118,7 @@ public class GeoData
 	 * @param worldPosition the world position
 	 * @return {@code true} if the character can see the target at the given world position, {@code false} otherwise
 	 */
-	public boolean canSeeTarget(L2Object cha, Point3D worldPosition)
+	public boolean canSeeTarget(L2Object cha, ILocational worldPosition)
 	{
 		// If geodata is off do simple check :]
 		// Don't allow casting on players on different dungeon levels etc

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/GeoEngine.java

@@ -45,7 +45,7 @@ import com.l2jserver.gameserver.model.Location;
 import com.l2jserver.gameserver.model.actor.instance.L2DefenderInstance;
 import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
-import com.l2jserver.gameserver.util.Point3D;
+import com.l2jserver.gameserver.model.interfaces.ILocational;
 
 /**
  * Geodata engine implementation.
@@ -99,7 +99,7 @@ public class GeoEngine extends GeoData
 	}
 	
 	@Override
-	public boolean canSeeTarget(L2Object cha, Point3D target)
+	public boolean canSeeTarget(L2Object cha, ILocational target)
 	{
 		if (DoorTable.getInstance().checkIfDoorsBetween(cha.getX(), cha.getY(), cha.getZ(), target.getX(), target.getY(), target.getZ(), cha.getInstanceId(), true))
 		{

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

@@ -50,6 +50,7 @@ import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
 import com.l2jserver.gameserver.model.effects.L2Effect;
 import com.l2jserver.gameserver.model.effects.L2EffectType;
+import com.l2jserver.gameserver.model.interfaces.ILocational;
 import com.l2jserver.gameserver.model.items.L2Weapon;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
 import com.l2jserver.gameserver.model.items.type.L2WeaponType;
@@ -60,7 +61,6 @@ import com.l2jserver.gameserver.network.SystemMessageId;
 import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
 import com.l2jserver.gameserver.network.serverpackets.AutoAttackStop;
 import com.l2jserver.gameserver.taskmanager.AttackStanceTaskManager;
-import com.l2jserver.gameserver.util.Point3D;
 import com.l2jserver.util.Rnd;
 
 /**
@@ -964,7 +964,7 @@ public class L2CharacterAI extends AbstractAI
 		// do nothing
 	}
 	
-	protected boolean maybeMoveToPosition(Point3D worldPosition, int offset)
+	protected boolean maybeMoveToPosition(ILocational worldPosition, int offset)
 	{
 		if (worldPosition == null)
 		{

+ 12 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Spawn.java

@@ -211,6 +211,18 @@ public class L2Spawn implements IPositionable, IIdentifiable
 		_location.setZ(z);
 	}
 	
+	/**
+	 * Set the x, y, z position of the spawn point.
+	 * @param z the z coordinate
+	 */
+	@Override
+	public void setXYZ(int x, int y, int z)
+	{
+		setX(x);
+		setY(y);
+		setZ(z);
+	}
+	
 	/**
 	 * @return the heading of L2NpcInstance when they are spawned.
 	 */

+ 26 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/Location.java

@@ -117,6 +117,20 @@ public class Location implements IPositionable
 		_z = z;
 	}
 	
+	/**
+	 * Set the x, y, z coordinates.
+	 * @param x the x coordinate
+	 * @param y the y coordinate
+	 * @param z the z coordinate
+	 */
+	@Override
+	public void setXYZ(int x, int y, int z)
+	{
+		setX(x);
+		setY(y);
+		setZ(z);
+	}
+	
 	/**
 	 * Get the heading.
 	 * @return the heading
@@ -158,7 +172,7 @@ public class Location implements IPositionable
 	}
 	
 	@Override
-	public Location getLocation()
+	public IPositionable getLocation()
 	{
 		return this;
 	}
@@ -173,6 +187,17 @@ public class Location implements IPositionable
 		_instanceId = loc.getInstanceId();
 	}
 	
+	@Override
+	public boolean equals(Object obj)
+	{
+		if ((obj != null) && (obj instanceof Location))
+		{
+			final Location loc = (Location) obj;
+			return (getX() == loc.getX()) && (getY() == loc.getY()) && (getZ() == loc.getZ()) && (getHeading() == loc.getHeading()) && (getInstanceId() == loc.getInstanceId());
+		}
+		return false;
+	}
+	
 	@Override
 	public String toString()
 	{

+ 2 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/holders/NpcRoutesHolder.java

@@ -23,6 +23,7 @@ import java.util.Map;
 
 import com.l2jserver.gameserver.model.Location;
 import com.l2jserver.gameserver.model.actor.L2Npc;
+import com.l2jserver.gameserver.model.interfaces.ILocational;
 
 /**
  * Holds depending between NPC's spawn point and route
@@ -65,7 +66,7 @@ public class NpcRoutesHolder
 	 * @param loc
 	 * @return unique text string for given Location.
 	 */
-	private String getUniqueKey(Location loc)
+	private String getUniqueKey(ILocational loc)
 	{
 		return (loc.getX() + "-" + loc.getY() + "-" + loc.getZ());
 	}

+ 39 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/interfaces/ILocational.java

@@ -0,0 +1,39 @@
+/*
+ * 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.model.interfaces;
+
+
+/**
+ * Simple interface for location of object.
+ * @author xban1x
+ */
+public interface ILocational
+{
+	public int getX();
+	
+	public int getY();
+	
+	public int getZ();
+	
+	public int getHeading();
+	
+	public int getInstanceId();
+	
+	public ILocational getLocation();
+}

+ 4 - 14
L2J_Server_BETA/java/com/l2jserver/gameserver/model/interfaces/IPositionable.java

@@ -21,29 +21,19 @@ package com.l2jserver.gameserver.model.interfaces;
 import com.l2jserver.gameserver.model.Location;
 
 /**
- * Positionable objects interface.
+ * Interface for changing location of object.
  * @author Zoey76
  */
-public interface IPositionable
+public interface IPositionable extends ILocational
 {
-	public int getX();
-	
-	public int getY();
-	
-	public int getZ();
-	
-	public int getHeading();
-	
-	public int getInstanceId();
-	
-	public Location getLocation();
-	
 	public void setX(int x);
 	
 	public void setY(int y);
 	
 	public void setZ(int z);
 	
+	public void setXYZ(int x, int y, int z);
+	
 	public void setHeading(int heading);
 	
 	public void setInstanceId(int instanceId);

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/zone/L2ZoneType.java

@@ -31,9 +31,9 @@ import com.l2jserver.gameserver.enums.InstanceType;
 import com.l2jserver.gameserver.enums.QuestEventType;
 import com.l2jserver.gameserver.instancemanager.InstanceManager;
 import com.l2jserver.gameserver.model.L2Object;
-import com.l2jserver.gameserver.model.Location;
 import com.l2jserver.gameserver.model.actor.L2Character;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.model.interfaces.ILocational;
 import com.l2jserver.gameserver.model.quest.Quest;
 import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
 
@@ -363,7 +363,7 @@ public abstract class L2ZoneType
 	 * @param loc
 	 * @return
 	 */
-	public boolean isInsideZone(Location loc)
+	public boolean isInsideZone(ILocational loc)
 	{
 		return _zone.isInsideZone(loc.getX(), loc.getY(), loc.getZ());
 	}

+ 1 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/util/Point3D.java

@@ -139,6 +139,7 @@ public class Point3D implements IPositionable
 		_instanceId.set(loc.getInstanceId());
 	}
 	
+	@Override
 	public void setXYZ(int x, int y, int z)
 	{
 		_x.set(x);