2
0

SkillSpellbookTable.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. }
  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 (!_skillSpellbooks.containsKey(skillId))
  83. return -1;
  84. return _skillSpellbooks.get(skillId);
  85. }
  86. public int getBookForSkill(L2Skill skill)
  87. {
  88. return getBookForSkill(skill.getId(), -1);
  89. }
  90. public int getBookForSkill(L2Skill skill, int level)
  91. {
  92. return getBookForSkill(skill.getId(), level);
  93. }
  94. }