NpcWalkerRoutesTable.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.datatables;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.util.logging.Logger;
  19. import javolution.util.FastList;
  20. import net.sf.l2j.L2DatabaseFactory;
  21. import net.sf.l2j.gameserver.model.L2NpcWalkerNode;
  22. /**
  23. * Main Table to Load Npc Walkers Routes and Chat SQL Table.<br>
  24. *
  25. * @author Rayan RPG for L2Emu Project
  26. *
  27. * @since 927
  28. *
  29. */
  30. public class NpcWalkerRoutesTable
  31. {
  32. private final static Logger _log = Logger.getLogger(SpawnTable.class.getName());
  33. private static NpcWalkerRoutesTable _instance;
  34. private FastList<L2NpcWalkerNode> _routes;
  35. public static NpcWalkerRoutesTable getInstance()
  36. {
  37. if (_instance == null)
  38. {
  39. _instance = new NpcWalkerRoutesTable();
  40. _log.info("Initializing Walkers Routes Table.");
  41. }
  42. return _instance;
  43. }
  44. private NpcWalkerRoutesTable()
  45. {
  46. }
  47. //FIXME: NPE while loading. :S
  48. public void load()
  49. {
  50. _routes = new FastList<L2NpcWalkerNode>();
  51. java.sql.Connection con = null;
  52. try
  53. {
  54. con = L2DatabaseFactory.getInstance().getConnection();
  55. PreparedStatement statement = con.prepareStatement("SELECT route_id, npc_id, move_point, chatText, move_x, move_y, move_z, delay, running FROM walker_routes");
  56. ResultSet rset = statement.executeQuery();
  57. L2NpcWalkerNode route;
  58. while (rset.next())
  59. {
  60. route = new L2NpcWalkerNode();
  61. route.setRouteId(rset.getInt("route_id"));
  62. route.setNpcId(rset.getInt("npc_id"));
  63. route.setMovePoint(rset.getString("move_point"));
  64. route.setChatText(rset.getString("chatText"));
  65. route.setMoveX(rset.getInt("move_x"));
  66. route.setMoveY(rset.getInt("move_y"));
  67. route.setMoveZ(rset.getInt("move_z"));
  68. route.setDelay(rset.getInt("delay"));
  69. route.setRunning(rset.getBoolean("running"));
  70. _routes.add(route);
  71. }
  72. rset.close();
  73. statement.close();
  74. _log.info("WalkerRoutesTable: Loaded " + _routes.size() + " Npc Walker Routes.");
  75. rset.close();
  76. statement.close();
  77. }
  78. catch (Exception e)
  79. {
  80. _log.severe("WalkerRoutesTable: Error while loading Npc Walkers Routes: " + e.getMessage());
  81. }
  82. finally
  83. {
  84. try
  85. {
  86. con.close();
  87. }
  88. catch (Exception e)
  89. {
  90. }
  91. }
  92. }
  93. public FastList<L2NpcWalkerNode> getRouteForNpc(int id)
  94. {
  95. FastList<L2NpcWalkerNode> _return = new FastList<L2NpcWalkerNode>();
  96. for (FastList.Node<L2NpcWalkerNode> n = _routes.head(), end = _routes.tail(); (n = n.getNext()) != end;)
  97. {
  98. if (n.getValue().getNpcId() == id)
  99. {
  100. _return.add(n.getValue());
  101. }
  102. }
  103. return _return;
  104. }
  105. }