Просмотр исходного кода

BETA: Core part for [DP9851]
* Added missing JavaDocs
* Reviewed by: Zoey76

xban1x 12 лет назад
Родитель
Сommit
fd13428983

+ 2 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/GameServer.java

@@ -73,6 +73,7 @@ import com.l2jserver.gameserver.datatables.OfflineTradersTable;
 import com.l2jserver.gameserver.datatables.OptionsData;
 import com.l2jserver.gameserver.datatables.PetDataTable;
 import com.l2jserver.gameserver.datatables.RecipeData;
+import com.l2jserver.gameserver.datatables.SkillLearnData;
 import com.l2jserver.gameserver.datatables.SkillTable;
 import com.l2jserver.gameserver.datatables.SkillTreesData;
 import com.l2jserver.gameserver.datatables.SpawnTable;
@@ -266,6 +267,7 @@ public class GameServer
 		
 		printSection("NPCs");
 		HerbDropTable.getInstance();
+		SkillLearnData.getInstance();
 		NpcTable.getInstance();
 		WalkingManager.getInstance();
 		StaticObjects.getInstance();

+ 1 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/CategoryData.java

@@ -32,6 +32,7 @@ import com.l2jserver.gameserver.engines.DocumentParser;
 import com.l2jserver.gameserver.model.CategoryType;
 
 /**
+ * This class holds different categories containing class ids or npc ids.
  * @author Nos, xban1x
  */
 public final class CategoryData extends DocumentParser

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

@@ -39,7 +39,6 @@ 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;
 
@@ -65,9 +64,6 @@ public class NpcTable
 	private static final String SELECT_NPC_ELEMENTALS_ALL = "SELECT * FROM npc_elementals ORDER BY npc_id";
 	private static final String SELECT_NPC_ELEMENTALS_BY_ID = "SELECT * FROM npc_elementals WHERE npc_id = ?";
 	
-	private static final String SELECT_SKILL_LEARN_ALL = "SELECT * FROM skill_learn";
-	private static final String SELECT_SKILL_LEARN_BY_ID = "SELECT * FROM skill_learn WHERE npc_id = ?";
-	
 	private static final String SELECT_MINION_ALL = "SELECT * FROM minions ORDER BY boss_id";
 	private static final String SELECT_MINION_BY_ID = "SELECT * FROM minions WHERE boss_id = ?";
 	
@@ -104,7 +100,7 @@ public class NpcTable
 		loadNpcs(0);
 		loadNpcsSkills(0);
 		loadNpcsDrop(0);
-		loadNpcsSkillLearn(0);
+		SkillLearnData.getInstance().setAllNpcSkillLearn();
 		loadMinions(0);
 		loadNpcsAI(0);
 		loadNpcsElement(0);
@@ -220,7 +216,7 @@ public class NpcTable
 			if (skills)
 			{
 				loadNpcsSkills(id);
-				loadNpcsSkillLearn(id);
+				SkillLearnData.getInstance().setNpcSkillLearn(id);
 			}
 			if (drops)
 			{
@@ -802,50 +798,6 @@ public class NpcTable
 		return count;
 	}
 	
-	/**
-	 * Id equals to zero or lesser means all.
-	 * @param id of the NPC to load it's skill learn list.
-	 */
-	private void loadNpcsSkillLearn(int id)
-	{
-		final String query = (id > 0) ? SELECT_SKILL_LEARN_BY_ID : SELECT_SKILL_LEARN_ALL;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement(query))
-		{
-			if (id > 0)
-			{
-				statement.setInt(1, id);
-			}
-			
-			int count = 0;
-			try (ResultSet rs = statement.executeQuery())
-			{
-				int npcId;
-				int classId;
-				L2NpcTemplate npc;
-				while (rs.next())
-				{
-					npcId = rs.getInt("npc_id");
-					classId = rs.getInt("class_id");
-					npc = getTemplate(npcId);
-					if (npc == null)
-					{
-						_log.warning(getClass().getSimpleName() + ": Error getting NPC template ID " + npcId + " while trying to load skill trainer data.");
-						continue;
-					}
-					
-					count++;
-					npc.addTeachInfo(ClassId.getClassId(classId));
-				}
-			}
-			_log.info(getClass().getSimpleName() + ": Loaded " + count + " Skill Learn.");
-		}
-		catch (Exception e)
-		{
-			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC trainer data.", e);
-		}
-	}
-	
 	/**
 	 * Id equals to zero or lesser means all.
 	 * @param id of the NPC to load it's minions.

+ 109 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SkillLearnData.java

@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2004-2013 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.datatables;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+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;
+
+/**
+ * Holds all skill learn data for all npcs.
+ * @author xban1x
+ */
+public final class SkillLearnData extends DocumentParser
+{
+	private static final Logger _log = Logger.getLogger(SkillLearnData.class.getName());
+	private final Map<Integer, List<ClassId>> _skillLearn = new HashMap<>();
+	
+	protected SkillLearnData()
+	{
+		load();
+	}
+	
+	@Override
+	public void load()
+	{
+		parseDatapackFile("data/skillLearn.xml");
+		_log.info(getClass().getSimpleName() + ": Loaded " + _skillLearn.size() + " Skill Learn data");
+	}
+	
+	@Override
+	protected void parseDocument()
+	{
+		for (Node node = getCurrentDocument().getFirstChild(); node != null; node = node.getNextSibling())
+		{
+			if ("list".equalsIgnoreCase(node.getNodeName()))
+			{
+				for (Node list_node = node.getFirstChild(); list_node != null; list_node = list_node.getNextSibling())
+				{
+					if ("npc".equalsIgnoreCase(list_node.getNodeName()))
+					{
+						final List<ClassId> classIds = new ArrayList<>();
+						for (Node c = list_node.getFirstChild(); c != null; c = c.getNextSibling())
+						{
+							if ("classId".equalsIgnoreCase(c.getNodeName()))
+							{
+								classIds.add(ClassId.getClassId(Integer.parseInt(c.getTextContent())));
+							}
+						}
+						_skillLearn.put(parseInteger(list_node.getAttributes(), "id"), classIds);
+					}
+				}
+			}
+		}
+	}
+	
+	public void setAllNpcSkillLearn()
+	{
+		for (int npcId : _skillLearn.keySet())
+		{
+			setNpcSkillLearn(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));
+	}
+	
+	public static SkillLearnData getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
+	private static class SingletonHolder
+	{
+		protected final static SkillLearnData _instance = new SkillLearnData();
+	}
+}

+ 1 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/CategoryType.java

@@ -19,6 +19,7 @@
 package com.l2jserver.gameserver.model;
 
 /**
+ * This class defines all category types.
  * @author xban1x
  */
 public enum CategoryType

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/templates/L2NpcTemplate.java

@@ -460,9 +460,9 @@ public final class L2NpcTemplate extends L2CharTemplate
 		getSuicideSkills().add(skill);
 	}
 	
-	public void addTeachInfo(ClassId classId)
+	public void addTeachInfo(List<ClassId> teachInfo)
 	{
-		_teachInfo.add(classId);
+		_teachInfo.addAll(teachInfo);
 	}
 	
 	public void addUniversalSkill(L2Skill skill)