Browse Source

BETA: Minor rework in instances:
* Created group system for instance spawn. There should be one <group name="general"></group> group, which spawned at instance creation (as usual). Besides, it is possible to create other group(s) (with any different name) to spawn it manually in script in appropriate moment of time via Instance.spawnGroup(String groupName) method. A way to unhardcode conditional instance spawn.
* Reviewed by: UnAfraid
* Minor rework for [5723]. If _instanceId isn't initialized in Location, teleToLocation(Location, int) will port player into main world. It creates some inconvenience, when using teleToLocation(Location, int) for teleportation inside instance.
* Reported by: Konstantinos

VlLight 12 years ago
parent
commit
bdedfbade7

+ 3 - 0
L2J_Server_BETA/build.bat

@@ -0,0 +1,3 @@
+@echo off
+c:/ant/bin/ant
+pause

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Object.java

@@ -334,7 +334,7 @@ public abstract class L2Object
 	 */
 	 */
 	public void setInstanceId(int instanceId)
 	public void setInstanceId(int instanceId)
 	{
 	{
-		if (_instanceId == instanceId)
+		if ((instanceId < 0) || (_instanceId == instanceId))
 		{
 		{
 			return;
 			return;
 		}
 		}

+ 29 - 27
L2J_Server_BETA/java/com/l2jserver/gameserver/model/Location.java

@@ -23,39 +23,24 @@ public final class Location
 	private final int _z;
 	private final int _z;
 	private int _heading;
 	private int _heading;
 	private int _instanceId;
 	private int _instanceId;
-	
+
 	public Location(int x, int y, int z)
 	public Location(int x, int y, int z)
 	{
 	{
 		_x = x;
 		_x = x;
 		_y = y;
 		_y = y;
 		_z = z;
 		_z = z;
+		_instanceId = -1;
 	}
 	}
-	
-	public Location(L2Object obj)
-	{
-		_x = obj.getX();
-		_y = obj.getY();
-		_z = obj.getZ();
-		_instanceId = obj.getInstanceId();
-	}
-	
-	public Location(L2Character obj)
-	{
-		_x = obj.getX();
-		_y = obj.getY();
-		_z = obj.getZ();
-		_heading = obj.getHeading();
-		_instanceId = obj.getInstanceId();
-	}
-	
+
 	public Location(int x, int y, int z, int heading)
 	public Location(int x, int y, int z, int heading)
 	{
 	{
 		_x = x;
 		_x = x;
 		_y = y;
 		_y = y;
 		_z = z;
 		_z = z;
 		_heading = heading;
 		_heading = heading;
+		_instanceId = -1;
 	}
 	}
-	
+
 	public Location(int x, int y, int z, int heading, int instanceId)
 	public Location(int x, int y, int z, int heading, int instanceId)
 	{
 	{
 		_x = x;
 		_x = x;
@@ -64,38 +49,55 @@ public final class Location
 		_heading = heading;
 		_heading = heading;
 		_instanceId = instanceId;
 		_instanceId = instanceId;
 	}
 	}
-	
+
+	public Location(L2Object obj)
+	{
+		_x = obj.getX();
+		_y = obj.getY();
+		_z = obj.getZ();
+		_instanceId = obj.getInstanceId();
+	}
+
+	public Location(L2Character obj)
+	{
+		_x = obj.getX();
+		_y = obj.getY();
+		_z = obj.getZ();
+		_heading = obj.getHeading();
+		_instanceId = obj.getInstanceId();
+	}
+
 	public int getX()
 	public int getX()
 	{
 	{
 		return _x;
 		return _x;
 	}
 	}
-	
+
 	public int getY()
 	public int getY()
 	{
 	{
 		return _y;
 		return _y;
 	}
 	}
-	
+
 	public int getZ()
 	public int getZ()
 	{
 	{
 		return _z;
 		return _z;
 	}
 	}
-	
+
 	public int getHeading()
 	public int getHeading()
 	{
 	{
 		return _heading;
 		return _heading;
 	}
 	}
-	
+
 	public int getInstanceId()
 	public int getInstanceId()
 	{
 	{
 		return _instanceId;
 		return _instanceId;
 	}
 	}
-	
+
 	@Override
 	@Override
 	public String toString()
 	public String toString()
 	{
 	{
 		return "[" + getClass().getSimpleName() + "] X: " + _x + " Y: " + _y + " Z: " + _z + " Heading: " + _heading + " InstanceId: " + _instanceId;
 		return "[" + getClass().getSimpleName() + "] X: " + _x + " Y: " + _y + " Z: " + _z + " Heading: " + _heading + " InstanceId: " + _instanceId;
 	}
 	}
-	
+
 	/**
 	/**
 	 * @param instanceId the instance Id to set
 	 * @param instanceId the instance Id to set
 	 */
 	 */

+ 88 - 39
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Instance.java

@@ -2,7 +2,9 @@ package com.l2jserver.gameserver.model.entity;
 
 
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.ScheduledFuture;
@@ -57,6 +59,7 @@ public class Instance
 	private final L2FastList<Integer> _players = new L2FastList<>(true);
 	private final L2FastList<Integer> _players = new L2FastList<>(true);
 	private final List<L2Npc> _npcs = new L2FastList<>(true);
 	private final List<L2Npc> _npcs = new L2FastList<>(true);
 	private final Map<Integer, L2DoorInstance> _doors = new L2FastMap<>(true);
 	private final Map<Integer, L2DoorInstance> _doors = new L2FastMap<>(true);
+	private final Map<String, List<L2Spawn>> _manualSpawn = new HashMap<>();
 	private Location _spawnLoc = null;
 	private Location _spawnLoc = null;
 	private boolean _allowSummon = true;
 	private boolean _allowSummon = true;
 	private long _emptyDestroyTime = -1;
 	private long _emptyDestroyTime = -1;
@@ -313,6 +316,7 @@ public class Instance
 			}
 			}
 		}
 		}
 		_npcs.clear();
 		_npcs.clear();
+		_manualSpawn.clear();
 	}
 	}
 	
 	
 	public void removeDoors()
 	public void removeDoors()
@@ -336,6 +340,32 @@ public class Instance
 		_doors.clear();
 		_doors.clear();
 	}
 	}
 	
 	
+	/**
+	 * Spawns group of instance NPC's
+	 * @param groupName - name of group from XML definition to spawn
+	 * @return list of spawned NPC's
+	 */
+	public List<L2Npc> spawnGroup(String groupName)
+	{
+		List<L2Npc> ret = null;
+		if (_manualSpawn.containsKey(groupName))
+		{
+			final List<L2Spawn> manualSpawn = _manualSpawn.get(groupName);
+			ret = new ArrayList<>(manualSpawn.size());
+			
+			for (L2Spawn spawnDat : manualSpawn)
+			{
+				ret.add(spawnDat.doSpawn());
+			}
+		}
+		else
+		{
+			_log.warning(getName() + " instance: cannot spawn NPC's, wrong group name: " + groupName);
+		}
+		
+		return ret;
+	}
+	
 	public void loadInstanceTemplate(String filename)
 	public void loadInstanceTemplate(String filename)
 	{
 	{
 		Document doc = null;
 		Document doc = null;
@@ -465,52 +495,71 @@ public class Instance
 			}
 			}
 			else if ("spawnlist".equalsIgnoreCase(n.getNodeName()))
 			else if ("spawnlist".equalsIgnoreCase(n.getNodeName()))
 			{
 			{
-				for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
+				for (Node group = n.getFirstChild(); group != null; group = group.getNextSibling())
 				{
 				{
-					int npcId = 0, x = 0, y = 0, z = 0, respawn = 0, heading = 0, delay = -1;
-					
-					if ("spawn".equalsIgnoreCase(d.getNodeName()))
+					if ("group".equalsIgnoreCase(group.getNodeName()))
 					{
 					{
-						
-						npcId = Integer.parseInt(d.getAttributes().getNamedItem("npcId").getNodeValue());
-						x = Integer.parseInt(d.getAttributes().getNamedItem("x").getNodeValue());
-						y = Integer.parseInt(d.getAttributes().getNamedItem("y").getNodeValue());
-						z = Integer.parseInt(d.getAttributes().getNamedItem("z").getNodeValue());
-						heading = Integer.parseInt(d.getAttributes().getNamedItem("heading").getNodeValue());
-						respawn = Integer.parseInt(d.getAttributes().getNamedItem("respawn").getNodeValue());
-						if (d.getAttributes().getNamedItem("onKillDelay") != null)
-						{
-							delay = Integer.parseInt(d.getAttributes().getNamedItem("onKillDelay").getNodeValue());
-						}
-						
-						npcTemplate = NpcTable.getInstance().getTemplate(npcId);
-						if (npcTemplate != null)
+						String spawnGroup = group.getAttributes().getNamedItem("name").getNodeValue();
+						List<L2Spawn> manualSpawn = new ArrayList<>();
+						for (Node d = group.getFirstChild(); d != null; d = d.getNextSibling())
 						{
 						{
-							spawnDat = new L2Spawn(npcTemplate);
-							spawnDat.setLocx(x);
-							spawnDat.setLocy(y);
-							spawnDat.setLocz(z);
-							spawnDat.setAmount(1);
-							spawnDat.setHeading(heading);
-							spawnDat.setRespawnDelay(respawn);
-							if (respawn == 0)
-							{
-								spawnDat.stopRespawn();
-							}
-							else
-							{
-								spawnDat.startRespawn();
-							}
-							spawnDat.setInstanceId(getId());
-							L2Npc spawned = spawnDat.doSpawn();
-							if ((delay >= 0) && (spawned instanceof L2Attackable))
+							int npcId = 0, x = 0, y = 0, z = 0, respawn = 0, heading = 0, delay = -1;
+							
+							if ("spawn".equalsIgnoreCase(d.getNodeName()))
 							{
 							{
-								((L2Attackable) spawned).setOnKillDelay(delay);
+								
+								npcId = Integer.parseInt(d.getAttributes().getNamedItem("npcId").getNodeValue());
+								x = Integer.parseInt(d.getAttributes().getNamedItem("x").getNodeValue());
+								y = Integer.parseInt(d.getAttributes().getNamedItem("y").getNodeValue());
+								z = Integer.parseInt(d.getAttributes().getNamedItem("z").getNodeValue());
+								heading = Integer.parseInt(d.getAttributes().getNamedItem("heading").getNodeValue());
+								respawn = Integer.parseInt(d.getAttributes().getNamedItem("respawn").getNodeValue());
+								if (d.getAttributes().getNamedItem("onKillDelay") != null)
+								{
+									delay = Integer.parseInt(d.getAttributes().getNamedItem("onKillDelay").getNodeValue());
+								}
+								
+								npcTemplate = NpcTable.getInstance().getTemplate(npcId);
+								if (npcTemplate != null)
+								{
+									spawnDat = new L2Spawn(npcTemplate);
+									spawnDat.setLocx(x);
+									spawnDat.setLocy(y);
+									spawnDat.setLocz(z);
+									spawnDat.setAmount(1);
+									spawnDat.setHeading(heading);
+									spawnDat.setRespawnDelay(respawn);
+									if (respawn == 0)
+									{
+										spawnDat.stopRespawn();
+									}
+									else
+									{
+										spawnDat.startRespawn();
+									}
+									spawnDat.setInstanceId(getId());
+									if (spawnGroup.equals("general"))
+									{
+										L2Npc spawned = spawnDat.doSpawn();
+										if ((delay >= 0) && (spawned instanceof L2Attackable))
+										{
+											((L2Attackable) spawned).setOnKillDelay(delay);
+										}
+									}
+									else
+									{
+										manualSpawn.add(spawnDat);
+									}
+								}
+								else
+								{
+									_log.warning("Instance: Data missing in NPC table for ID: " + npcId + " in Instance " + getId());
+								}
 							}
 							}
 						}
 						}
-						else
+						if (!manualSpawn.isEmpty())
 						{
 						{
-							_log.warning("Instance: Data missing in NPC table for ID: " + npcId + " in Instance " + getId());
+							_manualSpawn.put(spawnGroup, manualSpawn);
 						}
 						}
 					}
 					}
 				}
 				}