NpcBuffersData.java 2.8 KB

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