Explorar o código

Added automatic removal of summoned NPCs from summoner's list.
Added new method to summon NPCs, with less parameters.

Zoey76 %!s(int64=10) %!d(string=hai) anos
pai
achega
d26b6f1f21

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

@@ -519,8 +519,9 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
 	 */
 	public void onDecay()
 	{
-		L2WorldRegion reg = getWorldRegion();
 		decayMe();
+		
+		final L2WorldRegion reg = getWorldRegion();
 		if (reg != null)
 		{
 			reg.removeFromZones(this);

+ 9 - 2
L2J_Server/java/com/l2jserver/gameserver/model/actor/L2Npc.java

@@ -1394,6 +1394,13 @@ public class L2Npc extends L2Character
 		
 		// Notify Walking Manager
 		WalkingManager.getInstance().onDeath(this);
+		
+		// Removes itself from the summoned list.
+		final L2Character summoner = getSummoner();
+		if ((summoner != null) && summoner.isNpc())
+		{
+			((L2Npc) summoner).removeSummonedNpc(getObjectId());
+		}
 	}
 	
 	/**
@@ -1410,8 +1417,6 @@ public class L2Npc extends L2Character
 	@Override
 	public boolean deleteMe()
 	{
-		L2WorldRegion oldRegion = getWorldRegion();
-		
 		try
 		{
 			onDecay();
@@ -1426,6 +1431,7 @@ public class L2Npc extends L2Character
 			getSkillChannelized().abortChannelization();
 		}
 		
+		final L2WorldRegion oldRegion = getWorldRegion();
 		if (oldRegion != null)
 		{
 			oldRegion.removeFromZones(this);
@@ -1992,6 +1998,7 @@ public class L2Npc extends L2Character
 	{
 		if (_summonedNpcs != null)
 		{
+			System.out.println("Removing npc!!");
 			_summonedNpcs.remove(objectId);
 		}
 	}

+ 1 - 1
L2J_Server/java/com/l2jserver/gameserver/model/entity/Hero.java

@@ -938,7 +938,7 @@ public class Hero
 	}
 	
 	/**
-	 * Verifies if the given object ID belongs to a unclaimed hero.
+	 * Verifies if the given object ID belongs to an unclaimed hero.
 	 * @param objectId the player's object ID to verify
 	 * @return {@code true} if player is unclaimed hero
 	 */

+ 13 - 0
L2J_Server/java/com/l2jserver/gameserver/model/events/AbstractScript.java

@@ -1556,6 +1556,19 @@ public abstract class AbstractScript extends ManagedScript
 		return addSpawn(npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), false, 0, false, 0);
 	}
 	
+	/**
+	 * Add a temporary spawn of the specified NPC.
+	 * @param summoner the NPC that requires this spawn
+	 * @param npcId the ID of the NPC to spawn
+	 * @param pos the object containing the spawn location coordinates
+	 * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
+	 * @return the {@link L2Npc} object of the newly spawned NPC, {@code null} if the NPC doesn't exist
+	 */
+	public static L2Npc addSpawn(L2Npc summoner, int npcId, IPositionable pos, long despawnDelay)
+	{
+		return addSpawn(summoner, npcId, pos.getX(), pos.getY(), pos.getZ(), pos.getHeading(), false, despawnDelay, false, 0);
+	}
+	
 	/**
 	 * Add a temporary spawn of the specified NPC.
 	 * @param npcId the ID of the NPC to spawn