SkillSpellbookTable.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 com.l2jserver.gameserver.datatables;
  16. import gnu.trove.TIntIntHashMap;
  17. import java.sql.Connection;
  18. import java.sql.PreparedStatement;
  19. import java.sql.ResultSet;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.L2DatabaseFactory;
  24. import com.l2jserver.gameserver.model.L2Skill;
  25. public class SkillSpellbookTable
  26. {
  27. private static Logger _log = Logger.getLogger(SkillTreeTable.class.getName());
  28. private static TIntIntHashMap _skillSpellbooks;
  29. public static SkillSpellbookTable getInstance()
  30. {
  31. return SingletonHolder._instance;
  32. }
  33. private SkillSpellbookTable()
  34. {
  35. if (!Config.SP_BOOK_NEEDED)
  36. return;
  37. _skillSpellbooks = new TIntIntHashMap();
  38. Connection con = null;
  39. try
  40. {
  41. con = L2DatabaseFactory.getInstance().getConnection();
  42. PreparedStatement statement = con.prepareStatement("SELECT skill_id, item_id FROM skill_spellbooks");
  43. ResultSet spbooks = statement.executeQuery();
  44. while (spbooks.next())
  45. _skillSpellbooks.put(spbooks.getInt("skill_id"), spbooks.getInt("item_id"));
  46. spbooks.close();
  47. statement.close();
  48. _log.info("SkillSpellbookTable: Loaded " + _skillSpellbooks.size() + " Spellbooks.");
  49. }
  50. catch (Exception e)
  51. {
  52. _log.log(Level.WARNING, "Error while loading spellbook data: " + e.getMessage(), e);
  53. }
  54. finally
  55. {
  56. L2DatabaseFactory.close(con);
  57. }
  58. }
  59. public int getBookForSkill(int skillId, int level)
  60. {
  61. if (skillId == L2Skill.SKILL_DIVINE_INSPIRATION && level != -1)
  62. {
  63. switch (level)
  64. {
  65. case 1:
  66. return 8618; // Ancient Book - Divine Inspiration (Modern Language Version)
  67. case 2:
  68. return 8619; // Ancient Book - Divine Inspiration (Original Language Version)
  69. case 3:
  70. return 8620; // Ancient Book - Divine Inspiration (Manuscript)
  71. case 4:
  72. return 8621; // Ancient Book - Divine Inspiration (Original Version)
  73. default:
  74. return -1;
  75. }
  76. }
  77. if (!Config.SP_BOOK_NEEDED)
  78. return (-1);
  79. if (!_skillSpellbooks.containsKey(skillId))
  80. return -1;
  81. return _skillSpellbooks.get(skillId);
  82. }
  83. public int getBookForSkill(L2Skill skill)
  84. {
  85. return getBookForSkill(skill.getId(), -1);
  86. }
  87. public int getBookForSkill(L2Skill skill, int level)
  88. {
  89. return getBookForSkill(skill.getId(), level);
  90. }
  91. @SuppressWarnings("synthetic-access")
  92. private static class SingletonHolder
  93. {
  94. protected static final SkillSpellbookTable _instance = new SkillSpellbookTable();
  95. }
  96. }