SkillLearnData.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.actor.templates.L2NpcTemplate;
  27. import com.l2jserver.gameserver.model.base.ClassId;
  28. /**
  29. * Holds all skill learn data for all npcs.
  30. * @author xban1x
  31. */
  32. public final class SkillLearnData extends DocumentParser
  33. {
  34. private final Map<Integer, List<ClassId>> _skillLearn = new HashMap<>();
  35. protected SkillLearnData()
  36. {
  37. load();
  38. }
  39. @Override
  40. public void load()
  41. {
  42. parseDatapackFile("data/skillLearn.xml");
  43. _log.info(getClass().getSimpleName() + ": Loaded " + _skillLearn.size() + " Skill Learn data.");
  44. }
  45. @Override
  46. protected void parseDocument()
  47. {
  48. for (Node node = getCurrentDocument().getFirstChild(); node != null; node = node.getNextSibling())
  49. {
  50. if ("list".equalsIgnoreCase(node.getNodeName()))
  51. {
  52. for (Node list_node = node.getFirstChild(); list_node != null; list_node = list_node.getNextSibling())
  53. {
  54. if ("npc".equalsIgnoreCase(list_node.getNodeName()))
  55. {
  56. final List<ClassId> classIds = new ArrayList<>();
  57. for (Node c = list_node.getFirstChild(); c != null; c = c.getNextSibling())
  58. {
  59. if ("classId".equalsIgnoreCase(c.getNodeName()))
  60. {
  61. classIds.add(ClassId.getClassId(Integer.parseInt(c.getTextContent())));
  62. }
  63. }
  64. _skillLearn.put(parseInteger(list_node.getAttributes(), "id"), classIds);
  65. }
  66. }
  67. }
  68. }
  69. }
  70. public void setAllNpcSkillLearn(Map<Integer, L2NpcTemplate> npcs)
  71. {
  72. for (int npcId : _skillLearn.keySet())
  73. {
  74. final L2NpcTemplate npc = npcs.get(npcId);
  75. if (npc == null)
  76. {
  77. _log.warning(getClass().getSimpleName() + ": Error getting NPC template Id " + npcId + " while trying to load skill trainer data.");
  78. continue;
  79. }
  80. npc.addTeachInfo(_skillLearn.get(npcId));
  81. }
  82. }
  83. public void setNpcSkillLearn(int npcId)
  84. {
  85. final L2NpcTemplate npc = NpcTable.getInstance().getTemplate(npcId);
  86. if (npc == null)
  87. {
  88. _log.warning(getClass().getSimpleName() + ": Error getting NPC template Id " + npcId + " while trying to load skill trainer data.");
  89. return;
  90. }
  91. npc.addTeachInfo(_skillLearn.get(npcId));
  92. }
  93. public static SkillLearnData getInstance()
  94. {
  95. return SingletonHolder._instance;
  96. }
  97. private static class SingletonHolder
  98. {
  99. protected final static SkillLearnData _instance = new SkillLearnData();
  100. }
  101. }