CharTemplateTable.java 6.3 KB

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