SkillSpellbookTable.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.Map;
  19. import java.util.logging.Logger;
  20. import javolution.util.FastMap;
  21. import net.sf.l2j.L2DatabaseFactory;
  22. import net.sf.l2j.gameserver.model.L2Skill;
  23. public class SkillSpellbookTable
  24. {
  25. private static Logger _log = Logger.getLogger(SkillTreeTable.class.getName());
  26. private static SkillSpellbookTable _instance;
  27. private static Map<Integer, Integer> _skillSpellbooks;
  28. public static SkillSpellbookTable getInstance()
  29. {
  30. if (_instance == null)
  31. _instance = new SkillSpellbookTable();
  32. return _instance;
  33. }
  34. private SkillSpellbookTable()
  35. {
  36. _skillSpellbooks = new FastMap<Integer, Integer>();
  37. java.sql.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. public int getBookForSkill(int skillId, int level)
  63. {
  64. if(skillId == L2Skill.SKILL_DIVINE_INSPIRATION && level != -1)
  65. {
  66. switch(level)
  67. {
  68. case 1: return 8618; // Ancient Book - Divine Inspiration (Modern Language Version)
  69. case 2: return 8619; // Ancient Book - Divine Inspiration (Original Language Version)
  70. case 3: return 8620; // Ancient Book - Divine Inspiration (Manuscript)
  71. case 4: return 8621; // Ancient Book - Divine Inspiration (Original Version)
  72. default: return -1;
  73. }
  74. }
  75. if (!_skillSpellbooks.containsKey(skillId))
  76. return -1;
  77. return _skillSpellbooks.get(skillId);
  78. }
  79. public int getBookForSkill(L2Skill skill)
  80. {
  81. return getBookForSkill(skill.getId(), -1);
  82. }
  83. public int getBookForSkill(L2Skill skill, int level)
  84. {
  85. return getBookForSkill(skill.getId(), level);
  86. }
  87. }