浏览代码

BETA: Minor rework of Quest class:
* Refactored registering methods to accept array/collection.
* Reusing code.
* Removed return type of registering methods.
* Patch by: xBan1x
* Reviewed by: Zoey76, Adry_85

Rumen Nikiforov 12 年之前
父节点
当前提交
eb66ab4a7c
共有 1 个文件被更改,包括 216 次插入63 次删除
  1. 216 63
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/quest/Quest.java

+ 216 - 63
L2J_Server_BETA/java/com/l2jserver/gameserver/model/quest/Quest.java

@@ -1913,20 +1913,17 @@ public class Quest extends ManagedScript
 	/**
 	 * Add this quest to the list of quests that the passed mob will respond to for the specified Event type.
 	 * @param eventType type of event being registered
-	 * @param npcIds NPC Ids to register
+	 * @param npcId NPC Id to register
 	 */
-	public void addEventId(QuestEventType eventType, int... npcIds)
+	public void addEventId(QuestEventType eventType, int npcId)
 	{
 		try
 		{
-			for (int npcId : npcIds)
+			final L2NpcTemplate t = NpcTable.getInstance().getTemplate(npcId);
+			if (t != null)
 			{
-				final L2NpcTemplate t = NpcTable.getInstance().getTemplate(npcId);
-				if (t != null)
-				{
-					t.addQuestEvent(eventType, this);
-					_questInvolvedNpcs.add(npcId);
-				}
+				t.addQuestEvent(eventType, this);
+				_questInvolvedNpcs.add(npcId);
 			}
 		}
 		catch (Exception e)
@@ -1935,6 +1932,32 @@ public class Quest extends ManagedScript
 		}
 	}
 	
+	/**
+	 * Add this quest to the list of quests that the passed mob will respond to for the specified Event type.
+	 * @param eventType type of event being registered
+	 * @param npcIds NPC Ids to register
+	 */
+	public void addEventId(QuestEventType eventType, int... npcIds)
+	{
+		for (int npcId : npcIds)
+		{
+			addEventId(eventType, npcId);
+		}
+	}
+	
+	/**
+	 * Add this quest to the list of quests that the passed mob will respond to for the specified Event type.
+	 * @param eventType type of event being registered
+	 * @param npcIds NPC Ids to register
+	 */
+	public void addEventId(QuestEventType eventType, Collection<Integer> npcIds)
+	{
+		for (int npcId : npcIds)
+		{
+			addEventId(eventType, npcId);
+		}
+	}
+	
 	// TODO: Remove after all Jython scripts are replaced with Java versions.
 	public void addStartNpc(int npcId)
 	{
@@ -1970,6 +1993,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.QUEST_START, npcIds);
 	}
 	
+	/**
+	 * Add the quest to the NPC's startQuest
+	 * @param npcIds
+	 */
+	public void addStartNpc(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.QUEST_START, npcIds);
+	}
+	
 	/**
 	 * Add the quest to the NPC's first-talk (default action dialog)
 	 * @param npcIds
@@ -1979,6 +2011,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_FIRST_TALK, npcIds);
 	}
 	
+	/**
+	 * Add the quest to the NPC's first-talk (default action dialog)
+	 * @param npcIds
+	 */
+	public void addFirstTalkId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_FIRST_TALK, npcIds);
+	}
+	
 	/**
 	 * Add the NPC to the AcquireSkill dialog
 	 * @param npcIds
@@ -1988,6 +2029,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_SKILL_LEARN, npcIds);
 	}
 	
+	/**
+	 * Add the NPC to the AcquireSkill dialog
+	 * @param npcIds
+	 */
+	public void addAcquireSkillId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_SKILL_LEARN, npcIds);
+	}
+	
 	/**
 	 * Add this quest to the list of quests that the passed mob will respond to for Attack Events.
 	 * @param npcIds
@@ -1997,6 +2047,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_ATTACK, npcIds);
 	}
 	
+	/**
+	 * Add this quest to the list of quests that the passed mob will respond to for Attack Events.
+	 * @param npcIds
+	 */
+	public void addAttackId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_ATTACK, npcIds);
+	}
+	
 	/**
 	 * Add this quest to the list of quests that the passed mob will respond to for Kill Events.
 	 * @param killIds
@@ -2012,10 +2071,7 @@ public class Quest extends ManagedScript
 	 */
 	public void addKillId(Collection<Integer> killIds)
 	{
-		for (int killId : killIds)
-		{
-			addEventId(QuestEventType.ON_KILL, killId);
-		}
+		addEventId(QuestEventType.ON_KILL, killIds);
 	}
 	
 	/**
@@ -2027,6 +2083,11 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_TALK, npcIds);
 	}
 	
+	public void addTalkId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_TALK, npcIds);
+	}
+	
 	/**
 	 * Add this quest to the list of quests that the passed npc will respond to for Spawn Events.
 	 * @param npcIds Id of the NPC
@@ -2036,6 +2097,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_SPAWN, npcIds);
 	}
 	
+	/**
+	 * Add this quest to the list of quests that the passed npc will respond to for Spawn Events.
+	 * @param npcIds Id of the NPC
+	 */
+	public void addSpawnId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_SPAWN, npcIds);
+	}
+	
 	/**
 	 * Add this quest to the list of quests that the passed npc will respond to for Skill-See Events.
 	 * @param npcIds Id of the NPC
@@ -2045,6 +2115,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_SKILL_SEE, npcIds);
 	}
 	
+	/**
+	 * Add this quest to the list of quests that the passed npc will respond to for Skill-See Events.
+	 * @param npcIds Id of the NPC
+	 */
+	public void addSkillSeeId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_SKILL_SEE, npcIds);
+	}
+	
 	/**
 	 * @param npcIds
 	 */
@@ -2053,6 +2132,14 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_SPELL_FINISHED, npcIds);
 	}
 	
+	/**
+	 * @param npcIds
+	 */
+	public void addSpellFinishedId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_SPELL_FINISHED, npcIds);
+	}
+	
 	/**
 	 * @param npcIds
 	 */
@@ -2061,6 +2148,14 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_TRAP_ACTION, npcIds);
 	}
 	
+	/**
+	 * @param npcIds
+	 */
+	public void addTrapActionId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_TRAP_ACTION, npcIds);
+	}
+	
 	/**
 	 * Add this quest to the list of quests that the passed npc will respond to for Faction Call Events.
 	 * @param npcIds Id of the NPC
@@ -2070,6 +2165,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_FACTION_CALL, npcIds);
 	}
 	
+	/**
+	 * Add this quest to the list of quests that the passed npc will respond to for Faction Call Events.
+	 * @param npcIds Id of the NPC
+	 */
+	public void addFactionCallId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_FACTION_CALL, npcIds);
+	}
+	
 	/**
 	 * Add this quest to the list of quests that the passed npc will respond to for Character See Events.
 	 * @param npcIds Id of the NPC
@@ -2079,6 +2183,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_AGGRO_RANGE_ENTER, npcIds);
 	}
 	
+	/**
+	 * Add this quest to the list of quests that the passed npc will respond to for Character See Events.
+	 * @param npcIds Id of the NPC
+	 */
+	public void addAggroRangeEnterId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_AGGRO_RANGE_ENTER, npcIds);
+	}
+	
 	/**
 	 * @param npcIds NPC Ids to register to on see creature event
 	 */
@@ -2088,80 +2201,84 @@ public class Quest extends ManagedScript
 	}
 	
 	/**
+	 * @param npcIds NPC Ids to register to on see creature event
+	 */
+	public void addSeeCreatureId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_SEE_CREATURE, npcIds);
+	}
+	
+	/**
+	 * Register onEnterZone trigger for Zone
+	 * @param zoneId
+	 */
+	public void addEnterZoneId(int zoneId)
+	{
+		final L2ZoneType zone = ZoneManager.getInstance().getZoneById(zoneId);
+		if (zone != null)
+		{
+			zone.addQuestEvent(QuestEventType.ON_ENTER_ZONE, this);
+		}
+	}
+	
+	/**
+	 * Register onEnterZone trigger for Zones
 	 * @param zoneIds
-	 * @return
 	 */
-	public L2ZoneType[] addEnterZoneId(int... zoneIds)
+	public void addEnterZoneId(int... zoneIds)
 	{
-		L2ZoneType[] value = new L2ZoneType[zoneIds.length];
-		int i = 0;
 		for (int zoneId : zoneIds)
 		{
-			try
-			{
-				L2ZoneType zone = ZoneManager.getInstance().getZoneById(zoneId);
-				if (zone != null)
-				{
-					zone.addQuestEvent(QuestEventType.ON_ENTER_ZONE, this);
-				}
-				value[i++] = zone;
-			}
-			catch (Exception e)
-			{
-				_log.log(Level.WARNING, "Exception on addEnterZoneId(): " + e.getMessage(), e);
-				continue;
-			}
+			addEnterZoneId(zoneId);
 		}
-		return value;
 	}
 	
 	/**
+	 * Register onEnterZone trigger for Zones
 	 * @param zoneIds
-	 * @return
 	 */
-	public L2ZoneType[] addExitZoneId(int... zoneIds)
+	public void addEnterZoneId(Collection<Integer> zoneIds)
 	{
-		L2ZoneType[] value = new L2ZoneType[zoneIds.length];
-		int i = 0;
 		for (int zoneId : zoneIds)
 		{
-			try
-			{
-				L2ZoneType zone = ZoneManager.getInstance().getZoneById(zoneId);
-				if (zone != null)
-				{
-					zone.addQuestEvent(QuestEventType.ON_EXIT_ZONE, this);
-				}
-				value[i++] = zone;
-			}
-			catch (Exception e)
-			{
-				_log.log(Level.WARNING, "Exception on addEnterZoneId(): " + e.getMessage(), e);
-				continue;
-			}
+			addEnterZoneId(zoneId);
 		}
-		return value;
 	}
 	
 	/**
+	 * Register onExitZone trigger for Zone
 	 * @param zoneId
-	 * @return
 	 */
-	public L2ZoneType addExitZoneId(int zoneId)
+	public void addExitZoneId(int zoneId)
 	{
-		try
+		L2ZoneType zone = ZoneManager.getInstance().getZoneById(zoneId);
+		if (zone != null)
 		{
-			L2ZoneType zone = ZoneManager.getInstance().getZoneById(zoneId);
-			if (zone != null)
-			{
-				zone.addQuestEvent(QuestEventType.ON_EXIT_ZONE, this);
-			}
-			return zone;
+			zone.addQuestEvent(QuestEventType.ON_EXIT_ZONE, this);
 		}
-		catch (Exception e)
+	}
+	
+	/**
+	 * Register onExitZone trigger for Zones
+	 * @param zoneIds
+	 */
+	public void addExitZoneId(int... zoneIds)
+	{
+		for (int zoneId : zoneIds)
 		{
-			_log.log(Level.WARNING, "Exception on addExitZoneId(): " + e.getMessage(), e);
-			return null;
+			addExitZoneId(zoneId);
+		}
+	}
+	
+	/**
+	 * Register onExitZone trigger for Zones
+	 * @param zoneIds
+	 */
+	public void addExitZoneId(Collection<Integer> zoneIds)
+	{
+		for (int zoneId : zoneIds)
+		{
+			addExitZoneId(zoneId);
 		}
 	}
 	
@@ -2174,6 +2291,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_EVENT_RECEIVED, npcIds);
 	}
 	
+	/**
+	 * Register onEventReceived trigger for NPC
+	 * @param npcIds
+	 */
+	public void addEventReceivedId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_EVENT_RECEIVED, npcIds);
+	}
+	
 	/**
 	 * Register onMoveFinished trigger for NPC
 	 * @param npcIds
@@ -2183,6 +2309,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_MOVE_FINISHED, npcIds);
 	}
 	
+	/**
+	 * Register onMoveFinished trigger for NPC
+	 * @param npcIds
+	 */
+	public void addMoveFinishedId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_MOVE_FINISHED, npcIds);
+	}
+	
 	/**
 	 * Register onNodeArrived trigger for NPC
 	 * @param npcIds id of NPC to register
@@ -2192,6 +2327,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_NODE_ARRIVED, npcIds);
 	}
 	
+	/**
+	 * Register onNodeArrived trigger for NPC
+	 * @param npcIds id of NPC to register
+	 */
+	public void addNodeArrivedId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_NODE_ARRIVED, npcIds);
+	}
+	
 	/**
 	 * Register onRouteFinished trigger for NPC
 	 * @param npcIds id of NPC to register
@@ -2201,6 +2345,15 @@ public class Quest extends ManagedScript
 		addEventId(QuestEventType.ON_ROUTE_FINISHED, npcIds);
 	}
 	
+	/**
+	 * Register onRouteFinished trigger for NPC
+	 * @param npcIds id of NPC to register
+	 */
+	public void addRouteFinishedId(Collection<Integer> npcIds)
+	{
+		addEventId(QuestEventType.ON_ROUTE_FINISHED, npcIds);
+	}
+	
 	/**
 	 * Use this method to get a random party member from a player's party.<br>
 	 * Useful when distributing rewards after killing an NPC.