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