|
@@ -1675,57 +1675,84 @@ public abstract class AbstractScript extends ManagedScript
|
|
|
* @see #addSpawn(int, int, int, int, int, boolean, long, boolean)
|
|
|
*/
|
|
|
public static L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
|
|
|
+ {
|
|
|
+ return addSpawn(null, npcId, x, y, z, heading, randomOffset, despawnDelay, isSummonSpawn, instanceId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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 x the X coordinate of the spawn location
|
|
|
+ * @param y the Y coordinate of the spawn location
|
|
|
+ * @param z the Z coordinate (height) of the spawn location
|
|
|
+ * @param heading the heading of the NPC
|
|
|
+ * @param randomOffset if {@code true}, adds +/- 50~100 to X/Y coordinates of the spawn location
|
|
|
+ * @param despawnDelay time in milliseconds till the NPC is despawned (0 - only despawned on server shutdown)
|
|
|
+ * @param isSummonSpawn if {@code true}, displays a summon animation on NPC spawn
|
|
|
+ * @param instanceId the ID of the instance to spawn the NPC in (0 - the open world)
|
|
|
+ * @return the {@link L2Npc} object of the newly spawned NPC or {@code null} if the NPC doesn't exist
|
|
|
+ * @see #addSpawn(int, IPositionable, boolean, long, boolean, int)
|
|
|
+ * @see #addSpawn(int, int, int, int, int, boolean, long)
|
|
|
+ * @see #addSpawn(int, int, int, int, int, boolean, long, boolean)
|
|
|
+ */
|
|
|
+ public static L2Npc addSpawn(L2Npc summoner, int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- L2NpcTemplate template = NpcData.getInstance().getTemplate(npcId);
|
|
|
+ final L2NpcTemplate template = NpcData.getInstance().getTemplate(npcId);
|
|
|
if (template == null)
|
|
|
{
|
|
|
- _log.log(Level.SEVERE, "addSpawn(): no NPC template found for NPC #" + npcId + "!");
|
|
|
+ _log.severe("Couldn't find NPC template for ID:" + npcId + "!");
|
|
|
+ return null;
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ if ((x == 0) && (y == 0))
|
|
|
{
|
|
|
- if ((x == 0) && (y == 0))
|
|
|
- {
|
|
|
- _log.log(Level.SEVERE, "addSpawn(): invalid spawn coordinates for NPC #" + npcId + "!");
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (randomOffset)
|
|
|
+ _log.log(Level.SEVERE, "addSpawn(): invalid spawn coordinates for NPC #" + npcId + "!");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (randomOffset)
|
|
|
+ {
|
|
|
+ int offset = Rnd.get(50, 100);
|
|
|
+ if (Rnd.nextBoolean())
|
|
|
{
|
|
|
- int offset = Rnd.get(50, 100);
|
|
|
- if (Rnd.nextBoolean())
|
|
|
- {
|
|
|
- offset *= -1;
|
|
|
- }
|
|
|
- x += offset;
|
|
|
-
|
|
|
- offset = Rnd.get(50, 100);
|
|
|
- if (Rnd.nextBoolean())
|
|
|
- {
|
|
|
- offset *= -1;
|
|
|
- }
|
|
|
- y += offset;
|
|
|
+ offset *= -1;
|
|
|
}
|
|
|
- L2Spawn spawn = new L2Spawn(template);
|
|
|
- spawn.setInstanceId(instanceId);
|
|
|
- spawn.setHeading(heading);
|
|
|
- spawn.setX(x);
|
|
|
- spawn.setY(y);
|
|
|
- spawn.setZ(z);
|
|
|
- spawn.stopRespawn();
|
|
|
- L2Npc result = spawn.spawnOne(isSummonSpawn);
|
|
|
+ x += offset;
|
|
|
|
|
|
- if (despawnDelay > 0)
|
|
|
+ offset = Rnd.get(50, 100);
|
|
|
+ if (Rnd.nextBoolean())
|
|
|
{
|
|
|
- result.scheduleDespawn(despawnDelay);
|
|
|
+ offset *= -1;
|
|
|
}
|
|
|
-
|
|
|
- return result;
|
|
|
+ y += offset;
|
|
|
+ }
|
|
|
+
|
|
|
+ final L2Spawn spawn = new L2Spawn(template);
|
|
|
+ spawn.setInstanceId(instanceId);
|
|
|
+ spawn.setHeading(heading);
|
|
|
+ spawn.setX(x);
|
|
|
+ spawn.setY(y);
|
|
|
+ spawn.setZ(z);
|
|
|
+ spawn.stopRespawn();
|
|
|
+
|
|
|
+ final L2Npc npc = spawn.spawnOne(isSummonSpawn);
|
|
|
+ if (despawnDelay > 0)
|
|
|
+ {
|
|
|
+ npc.scheduleDespawn(despawnDelay);
|
|
|
}
|
|
|
+
|
|
|
+ if (summoner != null)
|
|
|
+ {
|
|
|
+ summoner.addSummonedNpc(npc);
|
|
|
+ }
|
|
|
+ return npc;
|
|
|
}
|
|
|
- catch (Exception e1)
|
|
|
+ catch (Exception e)
|
|
|
{
|
|
|
- _log.warning("Could not spawn NPC #" + npcId + "; error: " + e1.getMessage());
|
|
|
+ _log.warning("Could not spawn NPC #" + npcId + "; error: " + e.getMessage());
|
|
|
}
|
|
|
|
|
|
return null;
|