NpcBuffersData.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 ai.npc.NpcBuffers;
  20. import java.util.Collection;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import java.util.Set;
  24. import java.util.logging.Level;
  25. import org.w3c.dom.NamedNodeMap;
  26. import org.w3c.dom.Node;
  27. import com.l2jserver.gameserver.engines.DocumentParser;
  28. import com.l2jserver.gameserver.model.StatsSet;
  29. /**
  30. * @author UnAfraid
  31. */
  32. public class NpcBuffersData extends DocumentParser
  33. {
  34. private final Map<Integer, NpcBufferData> _npcBuffers = new HashMap<>();
  35. protected NpcBuffersData()
  36. {
  37. load();
  38. }
  39. @Override
  40. public void load()
  41. {
  42. parseDatapackFile("data/scripts/ai/npc/NpcBuffers/NpcBuffersData.xml");
  43. _log.log(Level.INFO, getClass().getSimpleName() + ": Loaded: " + _npcBuffers.size() + " buffers data.");
  44. }
  45. @Override
  46. protected void parseDocument()
  47. {
  48. StatsSet set;
  49. Node attr;
  50. NamedNodeMap attrs;
  51. for (Node n = getCurrentDocument().getFirstChild(); n != null; n = n.getNextSibling())
  52. {
  53. if ("list".equalsIgnoreCase(n.getNodeName()))
  54. {
  55. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  56. {
  57. if ("npc".equalsIgnoreCase(d.getNodeName()))
  58. {
  59. attrs = d.getAttributes();
  60. final int npcId = parseInteger(attrs, "id");
  61. final NpcBufferData npc = new NpcBufferData(npcId);
  62. for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
  63. {
  64. switch (c.getNodeName())
  65. {
  66. case "skill":
  67. {
  68. attrs = c.getAttributes();
  69. set = new StatsSet();
  70. for (int i = 0; i < attrs.getLength(); i++)
  71. {
  72. attr = attrs.item(i);
  73. set.set(attr.getNodeName(), attr.getNodeValue());
  74. }
  75. npc.addSkill(new NpcBufferSkillData(set));
  76. break;
  77. }
  78. }
  79. }
  80. _npcBuffers.put(npcId, npc);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. public NpcBufferData getNpcBuffer(int npcId)
  87. {
  88. return _npcBuffers.get(npcId);
  89. }
  90. public Collection<NpcBufferData> getNpcBuffers()
  91. {
  92. return _npcBuffers.values();
  93. }
  94. public Set<Integer> getNpcBufferIds()
  95. {
  96. return _npcBuffers.keySet();
  97. }
  98. }