SkillLearnData.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.datatables;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.logging.Logger;
  25. import org.w3c.dom.Node;
  26. import com.l2jserver.gameserver.engines.DocumentParser;
  27. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  28. import com.l2jserver.gameserver.model.base.ClassId;
  29. /**
  30. * Holds all skill learn data for all npcs.
  31. * @author xban1x
  32. */
  33. public final class SkillLearnData extends DocumentParser
  34. {
  35. private static final Logger _log = Logger.getLogger(SkillLearnData.class.getName());
  36. private final Map<Integer, List<ClassId>> _skillLearn = new HashMap<>();
  37. protected SkillLearnData()
  38. {
  39. load();
  40. }
  41. @Override
  42. public void load()
  43. {
  44. parseDatapackFile("data/skillLearn.xml");
  45. _log.info(getClass().getSimpleName() + ": Loaded " + _skillLearn.size() + " Skill Learn data");
  46. }
  47. @Override
  48. protected void parseDocument()
  49. {
  50. for (Node node = getCurrentDocument().getFirstChild(); node != null; node = node.getNextSibling())
  51. {
  52. if ("list".equalsIgnoreCase(node.getNodeName()))
  53. {
  54. for (Node list_node = node.getFirstChild(); list_node != null; list_node = list_node.getNextSibling())
  55. {
  56. if ("npc".equalsIgnoreCase(list_node.getNodeName()))
  57. {
  58. final List<ClassId> classIds = new ArrayList<>();
  59. for (Node c = list_node.getFirstChild(); c != null; c = c.getNextSibling())
  60. {
  61. if ("classId".equalsIgnoreCase(c.getNodeName()))
  62. {
  63. classIds.add(ClassId.getClassId(Integer.parseInt(c.getTextContent())));
  64. }
  65. }
  66. _skillLearn.put(parseInteger(list_node.getAttributes(), "id"), classIds);
  67. }
  68. }
  69. }
  70. }
  71. }
  72. public void setAllNpcSkillLearn()
  73. {
  74. for (int npcId : _skillLearn.keySet())
  75. {
  76. setNpcSkillLearn(npcId);
  77. }
  78. }
  79. public void setNpcSkillLearn(int npcId)
  80. {
  81. final L2NpcTemplate npc = NpcTable.getInstance().getTemplate(npcId);
  82. if (npc == null)
  83. {
  84. _log.warning(getClass().getSimpleName() + ": Error getting NPC template ID " + npcId + " while trying to load skill trainer data.");
  85. return;
  86. }
  87. npc.addTeachInfo(_skillLearn.get(npcId));
  88. }
  89. public static SkillLearnData getInstance()
  90. {
  91. return SingletonHolder._instance;
  92. }
  93. private static class SingletonHolder
  94. {
  95. protected final static SkillLearnData _instance = new SkillLearnData();
  96. }
  97. }