NpcWalkerRoutesData.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.Level;
  25. import org.w3c.dom.NamedNodeMap;
  26. import org.w3c.dom.Node;
  27. import com.l2jserver.Config;
  28. import com.l2jserver.gameserver.engines.DocumentParser;
  29. import com.l2jserver.gameserver.model.L2NpcWalkerNode;
  30. import com.l2jserver.gameserver.network.NpcStringId;
  31. /**
  32. * Main Table to Load Npc Walkers Routes and Chat.
  33. * @author Rayan, JIV
  34. */
  35. public class NpcWalkerRoutesData extends DocumentParser
  36. {
  37. private static final Map<Integer, List<L2NpcWalkerNode>> _routes = new HashMap<>();
  38. protected NpcWalkerRoutesData()
  39. {
  40. if (Config.ALLOW_NPC_WALKERS)
  41. {
  42. load();
  43. }
  44. }
  45. @Override
  46. public void load()
  47. {
  48. _routes.clear();
  49. parseDatapackFile("data/WalkerRoutes.xml");
  50. _log.info(getClass().getSimpleName() + ": Loaded " + _routes.size() + " Npc Walker Routes.");
  51. }
  52. @Override
  53. protected void parseDocument()
  54. {
  55. final Node n = getCurrentDocument().getFirstChild();
  56. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  57. {
  58. if (d.getNodeName().equals("walker"))
  59. {
  60. List<L2NpcWalkerNode> list = new ArrayList<>(5);
  61. final Integer npcId = parseInteger(d.getAttributes(), "npcId");
  62. for (Node r = d.getFirstChild(); r != null; r = r.getNextSibling())
  63. {
  64. if (r.getNodeName().equals("route"))
  65. {
  66. NamedNodeMap attrs = r.getAttributes();
  67. int id = parseInt(attrs, "id");
  68. int x = parseInt(attrs, "X");
  69. int y = parseInt(attrs, "Y");
  70. int z = parseInt(attrs, "Z");
  71. int delay = parseInt(attrs, "delay");
  72. String chatString = null;
  73. NpcStringId npcString = null;
  74. Node node = attrs.getNamedItem("string");
  75. if (node != null)
  76. {
  77. chatString = node.getNodeValue();
  78. }
  79. else
  80. {
  81. node = attrs.getNamedItem("npcString");
  82. if (node != null)
  83. {
  84. npcString = NpcStringId.getNpcStringId(node.getNodeValue());
  85. if (npcString == null)
  86. {
  87. _log.log(Level.WARNING, getClass().getSimpleName() + ": Unknown npcstring '" + node.getNodeValue() + ".");
  88. continue;
  89. }
  90. }
  91. else
  92. {
  93. node = attrs.getNamedItem("npcStringId");
  94. if (node != null)
  95. {
  96. npcString = NpcStringId.getNpcStringId(parseInt(node));
  97. if (npcString == null)
  98. {
  99. _log.log(Level.WARNING, getClass().getSimpleName() + ": Unknown npcstring '" + node.getNodeValue() + ".");
  100. continue;
  101. }
  102. }
  103. }
  104. }
  105. list.add(new L2NpcWalkerNode(id, npcString, chatString, x, y, z, delay, parseBoolean(attrs, "run")));
  106. }
  107. }
  108. _routes.put(npcId, list);
  109. }
  110. }
  111. }
  112. public List<L2NpcWalkerNode> getRouteForNpc(int id)
  113. {
  114. return _routes.get(id);
  115. }
  116. public static NpcWalkerRoutesData getInstance()
  117. {
  118. return SingletonHolder._instance;
  119. }
  120. private static class SingletonHolder
  121. {
  122. protected static final NpcWalkerRoutesData _instance = new NpcWalkerRoutesData();
  123. }
  124. }