LevelUpData.java 3.7 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 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. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  55. Statement s = con.createStatement();
  56. ResultSet rs = s.executeQuery(SELECT_ALL))
  57. {
  58. L2LvlupData lvlDat;
  59. while (rs.next())
  60. {
  61. lvlDat = new L2LvlupData();
  62. lvlDat.setClassid(rs.getInt(CLASS_ID));
  63. lvlDat.setClassLvl(rs.getInt(CLASS_LVL));
  64. lvlDat.setClassHpBase(rs.getFloat(HP_BASE));
  65. lvlDat.setClassHpAdd(rs.getFloat(HP_ADD));
  66. lvlDat.setClassHpModifier(rs.getFloat(HP_MOD));
  67. lvlDat.setClassCpBase(rs.getFloat(CP_BASE));
  68. lvlDat.setClassCpAdd(rs.getFloat(CP_ADD));
  69. lvlDat.setClassCpModifier(rs.getFloat(CP_MOD));
  70. lvlDat.setClassMpBase(rs.getFloat(MP_BASE));
  71. lvlDat.setClassMpAdd(rs.getFloat(MP_ADD));
  72. lvlDat.setClassMpModifier(rs.getFloat(MP_MOD));
  73. _lvlTable.put(lvlDat.getClassid(), lvlDat);
  74. }
  75. }
  76. catch (Exception e)
  77. {
  78. _log.log(Level.SEVERE, "Error loading Level Up data.", e);
  79. }
  80. _log.info("LevelUpData: Loaded " + _lvlTable.size() + " Character Level Up Templates.");
  81. }
  82. /**
  83. * @param classId
  84. * @return
  85. */
  86. public L2LvlupData getTemplate(int classId)
  87. {
  88. return _lvlTable.get(classId);
  89. }
  90. public L2LvlupData getTemplate(ClassId classId)
  91. {
  92. return _lvlTable.get(classId.getId());
  93. }
  94. private static class SingletonHolder
  95. {
  96. protected static final LevelUpData _instance = new LevelUpData();
  97. }
  98. }