2
0

SkillLearnData.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 org.w3c.dom.Node;
  25. import com.l2jserver.gameserver.engines.DocumentParser;
  26. import com.l2jserver.gameserver.model.base.ClassId;
  27. /**
  28. * Holds all skill learn data for all npcs.
  29. * @author xban1x
  30. */
  31. public final class SkillLearnData extends DocumentParser
  32. {
  33. private final Map<Integer, List<ClassId>> _skillLearn = new HashMap<>();
  34. protected SkillLearnData()
  35. {
  36. load();
  37. }
  38. @Override
  39. public synchronized void load()
  40. {
  41. parseDatapackFile("data/skillLearn.xml");
  42. _log.info(getClass().getSimpleName() + ": Loaded " + _skillLearn.size() + " Skill Learn data.");
  43. }
  44. @Override
  45. protected void parseDocument()
  46. {
  47. for (Node node = getCurrentDocument().getFirstChild(); node != null; node = node.getNextSibling())
  48. {
  49. if ("list".equalsIgnoreCase(node.getNodeName()))
  50. {
  51. for (Node list_node = node.getFirstChild(); list_node != null; list_node = list_node.getNextSibling())
  52. {
  53. if ("npc".equalsIgnoreCase(list_node.getNodeName()))
  54. {
  55. final List<ClassId> classIds = new ArrayList<>();
  56. for (Node c = list_node.getFirstChild(); c != null; c = c.getNextSibling())
  57. {
  58. if ("classId".equalsIgnoreCase(c.getNodeName()))
  59. {
  60. classIds.add(ClassId.getClassId(Integer.parseInt(c.getTextContent())));
  61. }
  62. }
  63. _skillLearn.put(parseInteger(list_node.getAttributes(), "id"), classIds);
  64. }
  65. }
  66. }
  67. }
  68. }
  69. /**
  70. * @param npcId
  71. * @return {@link List} of {@link ClassId}'s that this npcId can teach.
  72. */
  73. public List<ClassId> getSkillLearnData(int npcId)
  74. {
  75. return _skillLearn.get(npcId);
  76. }
  77. /**
  78. * Gets the single instance of SkillLearnData.
  79. * @return single instance of SkillLearnData
  80. */
  81. public static SkillLearnData getInstance()
  82. {
  83. return SingletonHolder._instance;
  84. }
  85. private static class SingletonHolder
  86. {
  87. protected final static SkillLearnData _instance = new SkillLearnData();
  88. }
  89. }