Răsfoiți Sursa

BETA: Reworking a little bit SkillLearnData to match previous implementations.

Rumen Nikiforov 12 ani în urmă
părinte
comite
87d71640ba

+ 31 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/NpcTable.java

@@ -39,6 +39,7 @@ import com.l2jserver.gameserver.model.L2MinionData;
 import com.l2jserver.gameserver.model.L2NpcAIData;
 import com.l2jserver.gameserver.model.StatsSet;
 import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
+import com.l2jserver.gameserver.model.base.ClassId;
 import com.l2jserver.gameserver.model.skills.L2Skill;
 import com.l2jserver.gameserver.model.stats.BaseStats;
 
@@ -100,7 +101,7 @@ public class NpcTable
 		loadNpcs(0);
 		loadNpcsSkills(0);
 		loadNpcsDrop(0);
-		SkillLearnData.getInstance().setAllNpcSkillLearn(_npcs);
+		loadNpcsSkillLearn(0);
 		loadMinions(0);
 		loadNpcsAI(0);
 		loadNpcsElement(0);
@@ -216,7 +217,7 @@ public class NpcTable
 			if (skills)
 			{
 				loadNpcsSkills(id);
-				SkillLearnData.getInstance().setNpcSkillLearn(id);
+				loadNpcsSkillLearn(id);
 			}
 			if (drops)
 			{
@@ -726,6 +727,34 @@ public class NpcTable
 		}
 	}
 	
+	/**
+	 * Id equals to zero or lesser means all.
+	 * @param id of the NPC to load it's skill learn list.
+	 */
+	public void loadNpcsSkillLearn(int id)
+	{
+		if (id > 0)
+		{
+			final List<ClassId> teachInfo = SkillLearnData.getInstance().getSkillLearnData(id);
+			final L2NpcTemplate template = _npcs.get(id);
+			if ((teachInfo != null) && (template != null))
+			{
+				template.addTeachInfo(teachInfo);
+			}
+		}
+		else
+		{
+			for (L2NpcTemplate template : _npcs.values())
+			{
+				final List<ClassId> teachInfo = SkillLearnData.getInstance().getSkillLearnData(template.getNpcId());
+				if (teachInfo != null)
+				{
+					template.addTeachInfo(teachInfo);
+				}
+			}
+		}
+	}
+	
 	/**
 	 * Load npcs drop.
 	 * @param con the con

+ 11 - 26
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SkillLearnData.java

@@ -26,7 +26,6 @@ import java.util.Map;
 import org.w3c.dom.Node;
 
 import com.l2jserver.gameserver.engines.DocumentParser;
-import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
 import com.l2jserver.gameserver.model.base.ClassId;
 
 /**
@@ -43,7 +42,7 @@ public final class SkillLearnData extends DocumentParser
 	}
 	
 	@Override
-	public void load()
+	public synchronized void load()
 	{
 		parseDatapackFile("data/skillLearn.xml");
 		_log.info(getClass().getSimpleName() + ": Loaded " + _skillLearn.size() + " Skill Learn data.");
@@ -75,33 +74,19 @@ public final class SkillLearnData extends DocumentParser
 		}
 	}
 	
-	public void setAllNpcSkillLearn(Map<Integer, L2NpcTemplate> npcs)
+	/**
+	 * @param npcId
+	 * @return {@link List} of {@link ClassId}'s that this npcId can teach.
+	 */
+	public List<ClassId> getSkillLearnData(int npcId)
 	{
-		for (int npcId : _skillLearn.keySet())
-		{
-			final L2NpcTemplate npc = npcs.get(npcId);
-			if (npc == null)
-			{
-				_log.warning(getClass().getSimpleName() + ": Error getting NPC template Id " + npcId + " while trying to load skill trainer data.");
-				continue;
-			}
-			
-			npc.addTeachInfo(_skillLearn.get(npcId));
-		}
-	}
-	
-	public void setNpcSkillLearn(int npcId)
-	{
-		final L2NpcTemplate npc = NpcTable.getInstance().getTemplate(npcId);
-		if (npc == null)
-		{
-			_log.warning(getClass().getSimpleName() + ": Error getting NPC template Id " + npcId + " while trying to load skill trainer data.");
-			return;
-		}
-		
-		npc.addTeachInfo(_skillLearn.get(npcId));
+		return _skillLearn.get(npcId);
 	}
 	
+	/**
+	 * Gets the single instance of SkillLearnData.
+	 * @return single instance of SkillLearnData
+	 */
 	public static SkillLearnData getInstance()
 	{
 		return SingletonHolder._instance;