Browse Source

BETA: Adding some useful methods to Quest class to prevent from copying same code in bunch of places:
* addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
* openDoor(int doorId, int instanceId)
* closeDoor(int doorId, int instanceId)
* getDoor(int doorId, int instanceId)
* teleportPlayer(L2PcInstance player, Location loc, int instanceId)
* teleportPlayer(L2PcInstance player, Location loc, int instanceId, boolean allowRandomOffset)

* Also little cleanup in L2World its not necessary to remove object by object from knownlist when at the end all the knownlist will be cleared.

Rumen Nikiforov 12 năm trước cách đây
mục cha
commit
73331f8310

+ 1 - 9
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2World.java

@@ -378,8 +378,6 @@ public final class L2World
 			return;
 		}
 		
-		// removeObject(object);
-		
 		if (oldRegion != null)
 		{
 			// Remove the object from the L2ObjectHashSet(L2Object) _visibleObjects of L2WorldRegion
@@ -389,13 +387,12 @@ public final class L2World
 			// Go through all surrounding L2WorldRegion L2Characters
 			for (L2WorldRegion reg : oldRegion.getSurroundingRegions())
 			{
-				Collection<L2Object> vObj = reg.getVisibleObjects().values();
+				final Collection<L2Object> vObj = reg.getVisibleObjects().values();
 				for (L2Object obj : vObj)
 				{
 					if (obj != null)
 					{
 						obj.getKnownList().removeKnownObject(object);
-						object.getKnownList().removeKnownObject(obj);
 					}
 				}
 			}
@@ -413,12 +410,7 @@ public final class L2World
 				{
 					removeFromAllPlayers(player);
 				}
-				
-				// If selected L2Object is a GM L2PcInstance, remove it from Set(L2PcInstance) _gmList of GmListTable
-				// if (((L2PcInstance)object).isGM())
-				// GmListTable.getInstance().deleteGm((L2PcInstance)object);
 			}
-			
 		}
 	}
 	

+ 102 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/quest/Quest.java

@@ -39,9 +39,11 @@ import com.l2jserver.L2DatabaseFactory;
 import com.l2jserver.gameserver.GameTimeController;
 import com.l2jserver.gameserver.ThreadPoolManager;
 import com.l2jserver.gameserver.cache.HtmCache;
+import com.l2jserver.gameserver.datatables.DoorTable;
 import com.l2jserver.gameserver.datatables.ItemTable;
 import com.l2jserver.gameserver.datatables.NpcTable;
 import com.l2jserver.gameserver.idfactory.IdFactory;
+import com.l2jserver.gameserver.instancemanager.InstanceManager;
 import com.l2jserver.gameserver.instancemanager.QuestManager;
 import com.l2jserver.gameserver.instancemanager.ZoneManager;
 import com.l2jserver.gameserver.model.IL2Procedure;
@@ -53,10 +55,12 @@ import com.l2jserver.gameserver.model.Location;
 import com.l2jserver.gameserver.model.actor.L2Character;
 import com.l2jserver.gameserver.model.actor.L2Npc;
 import com.l2jserver.gameserver.model.actor.L2Trap;
+import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
 import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.model.actor.instance.L2TrapInstance;
 import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
+import com.l2jserver.gameserver.model.entity.Instance;
 import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
 import com.l2jserver.gameserver.model.items.L2Item;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
@@ -2758,6 +2762,20 @@ public class Quest extends ManagedScript
 		return addSpawn(npcId, loc.getX(), loc.getY(), loc.getZ(), loc.getHeading(), randomOffset, despawnDelay, isSummonSpawn, 0);
 	}
 	
+	/**
+	 * @param npcId
+	 * @param loc
+	 * @param randomOffset
+	 * @param despawnDelay
+	 * @param isSummonSpawn
+	 * @param instanceId
+	 * @return
+	 */
+	public L2Npc addSpawn(int npcId, Location loc, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
+	{
+		return addSpawn(npcId, loc.getX(), loc.getY(), loc.getZ(), loc.getHeading(), randomOffset, despawnDelay, isSummonSpawn, instanceId);
+	}
+	
 	/**
 	 * @param npcId
 	 * @param x
@@ -3599,4 +3617,88 @@ public class Quest extends ManagedScript
 	{
 		// To be overridden in quest scripts.
 	}
+	
+	/**
+	 * Opens the door if presents on the instance and its not open.
+	 * @param doorId
+	 * @param instanceId
+	 */
+	public void openDoor(int doorId, int instanceId)
+	{
+		final L2DoorInstance door = getDoor(doorId, instanceId);
+		if (door == null)
+		{
+			_log.log(Level.WARNING, getClass().getSimpleName() + ": called openDoor(" + doorId + ", " + instanceId + "); but door wasnt found!", new NullPointerException());
+		}
+		else if (!door.getOpen())
+		{
+			door.openMe();
+		}
+	}
+	
+	/**
+	 * Closes the door if presents on the instance and its open
+	 * @param doorId
+	 * @param instanceId
+	 */
+	public void closeDoor(int doorId, int instanceId)
+	{
+		final L2DoorInstance door = getDoor(doorId, instanceId);
+		if (door == null)
+		{
+			_log.log(Level.WARNING, getClass().getSimpleName() + ": called closeDoor(" + doorId + ", " + instanceId + "); but door wasnt found!", new NullPointerException());
+		}
+		else if (door.getOpen())
+		{
+			door.closeMe();
+		}
+	}
+	
+	/**
+	 * Retriving Door from instances or from the real world.
+	 * @param doorId
+	 * @param instanceId
+	 * @return {@link L2DoorInstance}
+	 */
+	public L2DoorInstance getDoor(int doorId, int instanceId)
+	{
+		L2DoorInstance door = null;
+		if (instanceId <= 0)
+		{
+			door = DoorTable.getInstance().getDoor(doorId);
+		}
+		else
+		{
+			final Instance inst = InstanceManager.getInstance().getInstance(instanceId);
+			if (inst != null)
+			{
+				door = inst.getDoor(doorId);
+			}
+		}
+		return door;
+	}
+	
+	/**
+	 * Teleport player to/from instance
+	 * @param player
+	 * @param loc
+	 * @param instanceId
+	 */
+	public void teleportPlayer(L2PcInstance player, Location loc, int instanceId)
+	{
+		teleportPlayer(player, loc, instanceId, true);
+	}
+	
+	/**
+	 * Teleport player to/from instance
+	 * @param player
+	 * @param loc
+	 * @param instanceId
+	 * @param allowRandomOffset
+	 */
+	public void teleportPlayer(L2PcInstance player, Location loc, int instanceId, boolean allowRandomOffset)
+	{
+		player.setInstanceId(instanceId);
+		player.teleToLocation(loc, allowRandomOffset);
+	}
 }