فهرست منبع

BETA: Improvement Spawn system

  * New listener is add OnNpcTeleport
  * onSpawn is not called anymore when npc teleport to handle teleport need to use onTeleport
  * OnNpcSpawn clean (remove isTeleport) not need anymore
  * Change order in GameServer for properly load spawns
  * SpawnTable not load data on Constructor anymore

 Now onSpawn called in constructor is not needed anymore.
Require Data Pack support for new changes
Zealar 10 سال پیش
والد
کامیت
7cfcf501a1

+ 4 - 4
L2J_Server_BETA/java/com/l2jserver/gameserver/GameServer.java

@@ -283,12 +283,9 @@ public class GameServer
 		DoorTable.getInstance();
 		DoorTable.getInstance();
 		ItemAuctionManager.getInstance();
 		ItemAuctionManager.getInstance();
 		CastleManager.getInstance().loadInstances();
 		CastleManager.getInstance().loadInstances();
-		FortManager.getInstance().loadInstances();
 		NpcBufferTable.getInstance();
 		NpcBufferTable.getInstance();
 		DayNightSpawnManager.getInstance().trim().notifyChangeMode();
 		DayNightSpawnManager.getInstance().trim().notifyChangeMode();
 		GrandBossManager.getInstance().initZones();
 		GrandBossManager.getInstance().initZones();
-		FourSepulchersManager.getInstance().init();
-		DimensionalRiftManager.getInstance();
 		EventDroplist.getInstance();
 		EventDroplist.getInstance();
 		
 		
 		printSection("Siege");
 		printSection("Siege");
@@ -345,8 +342,11 @@ public class GameServer
 			_log.severe(getClass().getSimpleName() + ": Failed loading scripts.cfg, scripts are not going to be loaded!");
 			_log.severe(getClass().getSimpleName() + ": Failed loading scripts.cfg, scripts are not going to be loaded!");
 		}
 		}
 		
 		
-		SpawnTable.getInstance();
+		SpawnTable.getInstance().load();
+		FourSepulchersManager.getInstance().init();
+		DimensionalRiftManager.getInstance();
 		RaidBossSpawnManager.getInstance();
 		RaidBossSpawnManager.getInstance();
+		FortManager.getInstance().loadInstances();
 		
 		
 		QuestManager.getInstance().report();
 		QuestManager.getInstance().report();
 		
 		

+ 0 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SpawnTable.java

@@ -60,11 +60,6 @@ public final class SpawnTable extends DocumentParser
 	
 	
 	private int _xmlSpawnCount = 0;
 	private int _xmlSpawnCount = 0;
 	
 	
-	protected SpawnTable()
-	{
-		load();
-	}
-	
 	/**
 	/**
 	 * Wrapper to load all spawns.
 	 * Wrapper to load all spawns.
 	 */
 	 */

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

@@ -584,7 +584,7 @@ public class StatsSet implements IParserAdvUtils
 		Object obj = _set.get(key);
 		Object obj = _set.get(key);
 		if ((obj == null) || !(obj instanceof List<?>))
 		if ((obj == null) || !(obj instanceof List<?>))
 		{
 		{
-			return null;
+			return Collections.EMPTY_LIST;
 		}
 		}
 		
 		
 		return (List<MinionHolder>) obj;
 		return (List<MinionHolder>) obj;

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

@@ -75,6 +75,7 @@ import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcCanBeSeen;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcEventReceived;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcEventReceived;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillFinished;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillFinished;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSpawn;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSpawn;
+import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcTeleport;
 import com.l2jserver.gameserver.model.events.returns.TerminateReturn;
 import com.l2jserver.gameserver.model.events.returns.TerminateReturn;
 import com.l2jserver.gameserver.model.holders.ItemHolder;
 import com.l2jserver.gameserver.model.holders.ItemHolder;
 import com.l2jserver.gameserver.model.items.L2Item;
 import com.l2jserver.gameserver.model.items.L2Item;
@@ -1392,7 +1393,14 @@ public class L2Npc extends L2Character
 		_spiritshotamount = getTemplate().getSpiritShot();
 		_spiritshotamount = getTemplate().getSpiritShot();
 		_killingBlowWeaponId = 0;
 		_killingBlowWeaponId = 0;
 		
 		
-		EventDispatcher.getInstance().notifyEventAsync(new OnNpcSpawn(this, isTeleporting()), this);
+		if (isTeleporting())
+		{
+			EventDispatcher.getInstance().notifyEventAsync(new OnNpcTeleport(this), this);
+		}
+		else
+		{
+			EventDispatcher.getInstance().notifyEventAsync(new OnNpcSpawn(this), this);
+		}
 		
 		
 		if (!isTeleporting())
 		if (!isTeleporting())
 		{
 		{

+ 25 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/events/AbstractScript.java

@@ -83,6 +83,7 @@ import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcMoveRouteFi
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillFinished;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillFinished;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillSee;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillSee;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSpawn;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSpawn;
+import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcTeleport;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAggroRangeEnter;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAggroRangeEnter;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAttack;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAttack;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableFactionCall;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableFactionCall;
@@ -413,6 +414,30 @@ public abstract class AbstractScript extends ManagedScript
 	
 	
 	// ---------------------------------------------------------------------------------------------------------------------------
 	// ---------------------------------------------------------------------------------------------------------------------------
 	
 	
+	/**
+	 * Provides instant callback operation when teleport {@link L2Npc}.
+	 * @param callback
+	 * @param npcIds
+	 * @return
+	 */
+	protected final List<AbstractEventListener> setNpcTeleportId(Consumer<OnNpcTeleport> callback, Collection<Integer> npcIds)
+	{
+		return registerConsumer(callback, EventType.ON_NPC_TELEPORT, ListenerRegisterType.NPC, npcIds);
+	}
+	
+	/**
+	 * Provides instant callback operation when teleport {@link L2Npc}.
+	 * @param callback
+	 * @param npcIds
+	 * @return
+	 */
+	protected final List<AbstractEventListener> setNpcTeleportId(Consumer<OnNpcTeleport> callback, int... npcIds)
+	{
+		return registerConsumer(callback, EventType.ON_NPC_TELEPORT, ListenerRegisterType.NPC, npcIds);
+	}
+	
+	// ---------------------------------------------------------------------------------------------------------------------------
+	
 	/**
 	/**
 	 * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc} and must receive quest state.
 	 * Provides instant callback operation when {@link L2PcInstance} talk to {@link L2Npc} and must receive quest state.
 	 * @param npcIds
 	 * @param npcIds

+ 2 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/events/EventType.java

@@ -38,6 +38,7 @@ import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcMoveRouteFi
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillFinished;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillFinished;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillSee;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSkillSee;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSpawn;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcSpawn;
+import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcTeleport;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAggroRangeEnter;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAggroRangeEnter;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAttack;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAttack;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableFactionCall;
 import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableFactionCall;
@@ -156,6 +157,7 @@ public enum EventType
 	ON_NPC_SKILL_SEE(OnNpcSkillSee.class, void.class),
 	ON_NPC_SKILL_SEE(OnNpcSkillSee.class, void.class),
 	ON_NPC_SPAWN(OnNpcSpawn.class, void.class),
 	ON_NPC_SPAWN(OnNpcSpawn.class, void.class),
 	ON_NPC_TALK(null, void.class),
 	ON_NPC_TALK(null, void.class),
+	ON_NPC_TELEPORT(OnNpcTeleport.class, void.class),
 	
 	
 	// Olympiad events
 	// Olympiad events
 	ON_OLYMPIAD_MATCH_RESULT(OnOlympiadMatchResult.class, void.class),
 	ON_OLYMPIAD_MATCH_RESULT(OnOlympiadMatchResult.class, void.class),

+ 1 - 8
L2J_Server_BETA/java/com/l2jserver/gameserver/model/events/impl/character/npc/OnNpcSpawn.java

@@ -28,12 +28,10 @@ import com.l2jserver.gameserver.model.events.impl.IBaseEvent;
 public class OnNpcSpawn implements IBaseEvent
 public class OnNpcSpawn implements IBaseEvent
 {
 {
 	private final L2Npc _npc;
 	private final L2Npc _npc;
-	private final boolean _isTeleporting;
 	
 	
-	public OnNpcSpawn(L2Npc npc, boolean isTeleporting)
+	public OnNpcSpawn(L2Npc npc)
 	{
 	{
 		_npc = npc;
 		_npc = npc;
-		_isTeleporting = isTeleporting;
 	}
 	}
 	
 	
 	public L2Npc getNpc()
 	public L2Npc getNpc()
@@ -41,11 +39,6 @@ public class OnNpcSpawn implements IBaseEvent
 		return _npc;
 		return _npc;
 	}
 	}
 	
 	
-	public boolean isTeleporting()
-	{
-		return _isTeleporting;
-	}
-	
 	@Override
 	@Override
 	public EventType getType()
 	public EventType getType()
 	{
 	{

+ 47 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/events/impl/character/npc/OnNpcTeleport.java

@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2004-2014 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.events.impl.character.npc;
+
+import com.l2jserver.gameserver.model.actor.L2Npc;
+import com.l2jserver.gameserver.model.events.EventType;
+import com.l2jserver.gameserver.model.events.impl.IBaseEvent;
+
+/**
+ * @author Zealar
+ */
+public class OnNpcTeleport implements IBaseEvent
+{
+	private final L2Npc _npc;
+	
+	public OnNpcTeleport(L2Npc npc)
+	{
+		_npc = npc;
+	}
+	
+	public L2Npc getNpc()
+	{
+		return _npc;
+	}
+	
+	@Override
+	public EventType getType()
+	{
+		return EventType.ON_NPC_TELEPORT;
+	}
+}

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

@@ -491,6 +491,21 @@ public class Quest extends AbstractScript implements IIdentifiable
 		}
 		}
 	}
 	}
 	
 	
+	/**
+	 * @param npc the teleport NPC
+	 */
+	public final void notifyTeleport(L2Npc npc)
+	{
+		try
+		{
+			onTeleport(npc);
+		}
+		catch (Exception e)
+		{
+			_log.log(Level.WARNING, "Exception on onTeleport() in notifyTeleport(): " + e.getMessage(), e);
+		}
+	}
+	
 	/**
 	/**
 	 * @param event
 	 * @param event
 	 * @param npc
 	 * @param npc
@@ -1177,6 +1192,14 @@ public class Quest extends AbstractScript implements IIdentifiable
 		return null;
 		return null;
 	}
 	}
 	
 	
+	/**
+	 * This function is called whenever an NPC is teleport.<br>
+	 * @param npc this parameter contains a reference to the exact instance of the NPC who just teleport.
+	 */
+	protected void onTeleport(L2Npc npc)
+	{
+	}
+	
 	/**
 	/**
 	 * This function is called whenever an NPC is called by another NPC in the same faction.
 	 * This function is called whenever an NPC is called by another NPC in the same faction.
 	 * @param npc this parameter contains a reference to the exact instance of the NPC who is being asked for help.
 	 * @param npc this parameter contains a reference to the exact instance of the NPC who is being asked for help.
@@ -1895,6 +1918,24 @@ public class Quest extends AbstractScript implements IIdentifiable
 		setNpcTalkId(npcIds);
 		setNpcTalkId(npcIds);
 	}
 	}
 	
 	
+	/**
+	 * Add this quest to the list of quests that the passed npc will respond to for Teleport Events.
+	 * @param npcIds the IDs of the NPCs to register
+	 */
+	public void addTeleportId(int... npcIds)
+	{
+		setNpcTeleportId(event -> notifyTeleport(event.getNpc()), npcIds);
+	}
+	
+	/**
+	 * Add this quest to the list of quests that the passed npc will respond to for Teleport Events.
+	 * @param npcIds the IDs of the NPCs to register
+	 */
+	public void addTeleportId(Collection<Integer> npcIds)
+	{
+		setNpcTeleportId(event -> notifyTeleport(event.getNpc()), npcIds);
+	}
+	
 	/**
 	/**
 	 * Add this quest to the list of quests that the passed npc will respond to for spawn events.
 	 * Add this quest to the list of quests that the passed npc will respond to for spawn events.
 	 * @param npcIds the IDs of the NPCs to register
 	 * @param npcIds the IDs of the NPCs to register

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/util/MinionList.java

@@ -154,7 +154,7 @@ public class MinionList
 		deleteSpawnedMinions();
 		deleteSpawnedMinions();
 		
 		
 		// if master has spawn and can respawn - try to reuse minions
 		// if master has spawn and can respawn - try to reuse minions
-		if ((_reusedMinionReferences == null) && (_master.getTemplate().getParameters().getMinionList("SummonPrivateRate") == null) && (_master.getTemplate().getParameters().getMinionList("Privates") != null) && (_master.getSpawn() != null) && _master.getSpawn().isRespawnEnabled())
+		if ((_reusedMinionReferences == null) && (_master.getTemplate().getParameters().getSet().get("SummonPrivateRate") == null) && !_master.getTemplate().getParameters().getMinionList("Privates").isEmpty() && (_master.getSpawn() != null) && _master.getSpawn().isRespawnEnabled())
 		{
 		{
 			_reusedMinionReferences = new FastList<L2MonsterInstance>().shared();
 			_reusedMinionReferences = new FastList<L2MonsterInstance>().shared();
 		}
 		}