LevelUpData.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.map.hash.TIntObjectHashMap;
  17. import java.sql.Connection;
  18. import java.sql.ResultSet;
  19. import java.sql.Statement;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import com.l2jserver.L2DatabaseFactory;
  23. import com.l2jserver.gameserver.model.L2LvlupData;
  24. import com.l2jserver.gameserver.model.base.ClassId;
  25. /**
  26. * This class ...
  27. *
  28. * @author NightMarez
  29. * @version $Revision: 1.3.2.4.2.3 $ $Date: 2005/03/27 15:29:18 $
  30. */
  31. public class LevelUpData
  32. {
  33. private static final String SELECT_ALL = "SELECT classid, defaulthpbase, defaulthpadd, defaulthpmod, defaultcpbase, defaultcpadd, defaultcpmod, defaultmpbase, defaultmpadd, defaultmpmod, class_lvl FROM lvlupgain";
  34. private static final String CLASS_LVL = "class_lvl";
  35. private static final String MP_MOD = "defaultmpmod";
  36. private static final String MP_ADD = "defaultmpadd";
  37. private static final String MP_BASE = "defaultmpbase";
  38. private static final String HP_MOD = "defaulthpmod";
  39. private static final String HP_ADD = "defaulthpadd";
  40. private static final String HP_BASE = "defaulthpbase";
  41. private static final String CP_MOD = "defaultcpmod";
  42. private static final String CP_ADD = "defaultcpadd";
  43. private static final String CP_BASE = "defaultcpbase";
  44. private static final String CLASS_ID = "classid";
  45. private static Logger _log = Logger.getLogger(LevelUpData.class.getName());
  46. private TIntObjectHashMap<L2LvlupData> _lvlTable;
  47. public static LevelUpData getInstance()
  48. {
  49. return SingletonHolder._instance;
  50. }
  51. protected LevelUpData()
  52. {
  53. _lvlTable = new TIntObjectHashMap<>();
  54. Connection con = null;
  55. try
  56. {
  57. con = L2DatabaseFactory.getInstance().getConnection();
  58. try (Statement s = con.createStatement();
  59. ResultSet rs = s.executeQuery(SELECT_ALL))
  60. {
  61. L2LvlupData lvlDat;
  62. while (rs.next())
  63. {
  64. lvlDat = new L2LvlupData();
  65. lvlDat.setClassid(rs.getInt(CLASS_ID));
  66. lvlDat.setClassLvl(rs.getInt(CLASS_LVL));
  67. lvlDat.setClassHpBase(rs.getFloat(HP_BASE));
  68. lvlDat.setClassHpAdd(rs.getFloat(HP_ADD));
  69. lvlDat.setClassHpModifier(rs.getFloat(HP_MOD));
  70. lvlDat.setClassCpBase(rs.getFloat(CP_BASE));
  71. lvlDat.setClassCpAdd(rs.getFloat(CP_ADD));
  72. lvlDat.setClassCpModifier(rs.getFloat(CP_MOD));
  73. lvlDat.setClassMpBase(rs.getFloat(MP_BASE));
  74. lvlDat.setClassMpAdd(rs.getFloat(MP_ADD));
  75. lvlDat.setClassMpModifier(rs.getFloat(MP_MOD));
  76. _lvlTable.put(lvlDat.getClassid(), lvlDat);
  77. }
  78. }
  79. _log.info("LevelUpData: Loaded " + _lvlTable.size() + " Character Level Up Templates.");
  80. }
  81. catch (Exception e)
  82. {
  83. _log.log(Level.SEVERE, "Error loading Level Up data.", e);
  84. }
  85. finally
  86. {
  87. L2DatabaseFactory.close(con);
  88. }
  89. }
  90. /**
  91. * @param classId
  92. * @return
  93. */
  94. public L2LvlupData getTemplate(int classId)
  95. {
  96. return _lvlTable.get(classId);
  97. }
  98. public L2LvlupData getTemplate(ClassId classId)
  99. {
  100. return _lvlTable.get(classId.getId());
  101. }
  102. private static class SingletonHolder
  103. {
  104. protected static final LevelUpData _instance = new LevelUpData();
  105. }
  106. }