CharTemplateTable.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.sql.SQLException;
  20. import java.util.Map;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23. import javolution.util.FastMap;
  24. import net.sf.l2j.L2DatabaseFactory;
  25. import net.sf.l2j.gameserver.model.base.ClassId;
  26. import net.sf.l2j.gameserver.templates.StatsSet;
  27. import net.sf.l2j.gameserver.templates.chars.L2PcTemplate;
  28. /**
  29. * This class ...
  30. *
  31. * @version $Revision: 1.6.2.1.2.10 $ $Date: 2005/03/29 14:00:54 $
  32. */
  33. public class CharTemplateTable
  34. {
  35. private static final Logger LOG = Logger.getLogger(CharTemplateTable.class.getName());
  36. private final Map<Integer, L2PcTemplate> _templates = new FastMap<Integer, L2PcTemplate>();
  37. public static CharTemplateTable getInstance()
  38. {
  39. return SingletonHolder._instance;
  40. }
  41. private CharTemplateTable()
  42. {
  43. Connection con = null;
  44. try
  45. {
  46. con = L2DatabaseFactory.getInstance().getConnection();
  47. PreparedStatement statement = con.prepareStatement("SELECT * FROM class_list, char_templates, lvlupgain"
  48. + " WHERE class_list.id = char_templates.classId" + " AND class_list.id = lvlupgain.classId"
  49. + " ORDER BY class_list.id");
  50. ResultSet rset = statement.executeQuery();
  51. while (rset.next())
  52. {
  53. StatsSet set = new StatsSet();
  54. set.set("classId", rset.getInt("id"));
  55. set.set("className", rset.getString("className"));
  56. set.set("raceId", rset.getInt("raceId"));
  57. set.set("baseSTR", rset.getInt("STR"));
  58. set.set("baseCON", rset.getInt("CON"));
  59. set.set("baseDEX", rset.getInt("DEX"));
  60. set.set("baseINT", rset.getInt("_INT"));
  61. set.set("baseWIT", rset.getInt("WIT"));
  62. set.set("baseMEN", rset.getInt("MEN"));
  63. set.set("baseHpMax", rset.getFloat("defaultHpBase"));
  64. set.set("lvlHpAdd", rset.getFloat("defaultHpAdd"));
  65. set.set("lvlHpMod", rset.getFloat("defaultHpMod"));
  66. set.set("baseMpMax", rset.getFloat("defaultMpBase"));
  67. set.set("baseCpMax", rset.getFloat("defaultCpBase"));
  68. set.set("lvlCpAdd", rset.getFloat("defaultCpAdd"));
  69. set.set("lvlCpMod", rset.getFloat("defaultCpMod"));
  70. set.set("lvlMpAdd", rset.getFloat("defaultMpAdd"));
  71. set.set("lvlMpMod", rset.getFloat("defaultMpMod"));
  72. set.set("baseHpReg", 1.5);
  73. set.set("baseMpReg", 0.9);
  74. set.set("basePAtk", rset.getInt("p_atk"));
  75. set.set("basePDef", /*classId.isMage()? 77 : 129*/rset.getInt("p_def"));
  76. set.set("baseMAtk", rset.getInt("m_atk"));
  77. set.set("baseMDef", rset.getInt("char_templates.m_def"));
  78. set.set("classBaseLevel", rset.getInt("class_lvl"));
  79. set.set("basePAtkSpd", rset.getInt("p_spd"));
  80. set.set("baseMAtkSpd", /*classId.isMage()? 166 : 333*/rset.getInt("char_templates.m_spd"));
  81. set.set("baseCritRate", rset.getInt("char_templates.critical") / 10);
  82. set.set("baseRunSpd", rset.getInt("move_spd"));
  83. set.set("baseWalkSpd", 0);
  84. set.set("baseShldDef", 0);
  85. set.set("baseShldRate", 0);
  86. set.set("baseAtkRange", 40);
  87. set.set("spawnX", rset.getInt("x"));
  88. set.set("spawnY", rset.getInt("y"));
  89. set.set("spawnZ", rset.getInt("z"));
  90. L2PcTemplate ct;
  91. set.set("collision_radius", rset.getDouble("m_col_r"));
  92. set.set("collision_height", rset.getDouble("m_col_h"));
  93. ct = new L2PcTemplate(set);
  94. _templates.put(ct.classId.getId(), ct);
  95. }
  96. rset.close();
  97. statement.close();
  98. LOG.info("CharTemplateTable: Loaded " + _templates.size() + " Character Templates.");
  99. }
  100. catch (SQLException e)
  101. {
  102. LOG.log(Level.SEVERE, "Failed loading char templates", e);
  103. }
  104. finally
  105. {
  106. try
  107. {
  108. con.close();
  109. }
  110. catch (Exception e)
  111. {
  112. // nothing
  113. }
  114. }
  115. try
  116. {
  117. con = L2DatabaseFactory.getInstance().getConnection();
  118. PreparedStatement statement = con.prepareStatement("SELECT classId, itemId, amount, equipped FROM char_creation_items");
  119. ResultSet rset = statement.executeQuery();
  120. int classId, itemId, amount;
  121. boolean equipped;
  122. while (rset.next())
  123. {
  124. classId = rset.getInt("classId");
  125. itemId = rset.getInt("itemId");
  126. amount = rset.getInt("amount");
  127. equipped = rset.getString("equipped").equals("true");
  128. if (ItemTable.getInstance().getTemplate(itemId) != null)
  129. {
  130. if (classId == -1)
  131. {
  132. for (L2PcTemplate pct : _templates.values())
  133. {
  134. pct.addItem(itemId, amount, equipped);
  135. }
  136. }
  137. else
  138. {
  139. L2PcTemplate pct = _templates.get(classId);
  140. if (pct != null)
  141. {
  142. pct.addItem(itemId, amount, equipped);
  143. }
  144. else
  145. {
  146. LOG.warning("char_creation_items: Entry for undefined class, classId: " + classId);
  147. }
  148. }
  149. }
  150. else
  151. {
  152. LOG.warning("char_creation_items: No data for itemId: " + itemId + " defined for classId " + classId);
  153. }
  154. }
  155. }
  156. catch (SQLException e)
  157. {
  158. LOG.log(Level.SEVERE, "Failed loading char creation items.", e);
  159. }
  160. finally
  161. {
  162. try
  163. {
  164. con.close();
  165. }
  166. catch (Exception e)
  167. {
  168. // nothing
  169. }
  170. }
  171. }
  172. public L2PcTemplate getTemplate(ClassId classId)
  173. {
  174. return this.getTemplate(classId.getId());
  175. }
  176. public L2PcTemplate getTemplate(int classId)
  177. {
  178. return _templates.get(classId);
  179. }
  180. public final String getClassNameById(int classId)
  181. {
  182. L2PcTemplate pcTemplate = _templates.get(classId);
  183. if (pcTemplate == null)
  184. {
  185. throw new IllegalArgumentException("No template for classId: " + classId);
  186. }
  187. return pcTemplate.className;
  188. }
  189. @SuppressWarnings("synthetic-access")
  190. private static class SingletonHolder
  191. {
  192. protected static final CharTemplateTable _instance = new CharTemplateTable();
  193. }
  194. }