HelperBuffTable.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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.util.List;
  20. import java.util.logging.Logger;
  21. import javolution.util.FastList;
  22. import net.sf.l2j.L2DatabaseFactory;
  23. import net.sf.l2j.gameserver.templates.L2HelperBuff;
  24. import net.sf.l2j.gameserver.templates.StatsSet;
  25. /**
  26. * This class represents the Newbie Helper Buff list
  27. *
  28. * Author: Ayor
  29. *
  30. */
  31. public class HelperBuffTable
  32. {
  33. private static Logger _log = Logger.getLogger(HennaTable.class.getName());
  34. /** The table containing all Buff of the Newbie Helper */
  35. private List<L2HelperBuff> _helperBuff;
  36. private boolean _initialized = true;
  37. /** The player level since Newbie Helper can give the fisrt buff <BR>
  38. * Used to generate message : "Come back here when you have reached level ...") */
  39. private int _magicClassLowestLevel = 100;
  40. private int _physicClassLowestLevel = 100;
  41. /** The player level above which Newbie Helper won't give any buff <BR>
  42. * Used to generate message : "Only novice character of level ... or less can receive my support magic.") */
  43. private int _magicClassHighestLevel = 1;
  44. private int _physicClassHighestLevel = 1;
  45. private int _servitorLowestLevel = 100;
  46. private int _servitorHighestLevel = 1;
  47. public static HelperBuffTable getInstance()
  48. {
  49. return SingletonHolder._instance;
  50. }
  51. /**
  52. * Create and Load the Newbie Helper Buff list from SQL Table helper_buff_list
  53. */
  54. private HelperBuffTable()
  55. {
  56. _helperBuff = new FastList<L2HelperBuff>();
  57. restoreHelperBuffData();
  58. }
  59. /**
  60. * Read and Load the Newbie Helper Buff list from SQL Table helper_buff_list
  61. */
  62. private void restoreHelperBuffData()
  63. {
  64. Connection con = null;
  65. try
  66. {
  67. try
  68. {
  69. con = L2DatabaseFactory.getInstance().getConnection();
  70. PreparedStatement statement = con.prepareStatement("SELECT * FROM helper_buff_list");
  71. ResultSet helperbuffdata = statement.executeQuery();
  72. fillHelperBuffTable(helperbuffdata);
  73. helperbuffdata.close();
  74. statement.close();
  75. }
  76. catch (Exception e)
  77. {
  78. _log.severe("Table helper_buff_list not found : Update your DataPack" + e);
  79. e.printStackTrace();
  80. }
  81. }
  82. finally
  83. {
  84. try
  85. {
  86. con.close();
  87. }
  88. catch (Exception e)
  89. {
  90. }
  91. }
  92. }
  93. /**
  94. * Load the Newbie Helper Buff list from SQL Table helper_buff_list
  95. */
  96. private void fillHelperBuffTable(ResultSet HelperBuffData) throws Exception
  97. {
  98. while (HelperBuffData.next())
  99. {
  100. StatsSet helperBuffDat = new StatsSet();
  101. int id = HelperBuffData.getInt("id");
  102. helperBuffDat.set("id", id);
  103. helperBuffDat.set("skillID", HelperBuffData.getInt("skill_id"));
  104. helperBuffDat.set("skillLevel", HelperBuffData.getInt("skill_level"));
  105. helperBuffDat.set("lowerLevel", HelperBuffData.getInt("lower_level"));
  106. helperBuffDat.set("upperLevel", HelperBuffData.getInt("upper_level"));
  107. helperBuffDat.set("isMagicClass", HelperBuffData.getString("is_magic_class"));
  108. helperBuffDat.set("forSummon", HelperBuffData.getString("forSummon"));
  109. // Calulate the range level in wich player must be to obtain buff from Newbie Helper
  110. if ("false".equals(HelperBuffData.getString("is_magic_class")))
  111. {
  112. if (HelperBuffData.getInt("lower_level") < _physicClassLowestLevel)
  113. _physicClassLowestLevel = HelperBuffData.getInt("lower_level");
  114. if (HelperBuffData.getInt("upper_level") > _physicClassHighestLevel)
  115. _physicClassHighestLevel = HelperBuffData.getInt("upper_level");
  116. }
  117. else
  118. {
  119. if (HelperBuffData.getInt("lower_level") < _magicClassLowestLevel)
  120. _magicClassLowestLevel = HelperBuffData.getInt("lower_level");
  121. if (HelperBuffData.getInt("upper_level") > _magicClassHighestLevel)
  122. _magicClassHighestLevel = HelperBuffData.getInt("upper_level");
  123. }
  124. if ("true".equals(HelperBuffData.getString("forSummon")))
  125. {
  126. if (HelperBuffData.getInt("lower_level") < _servitorLowestLevel)
  127. _servitorLowestLevel = HelperBuffData.getInt("lower_level");
  128. if (HelperBuffData.getInt("upper_level") > _servitorHighestLevel)
  129. _servitorHighestLevel = HelperBuffData.getInt("upper_level");
  130. }
  131. // Add this Helper Buff to the Helper Buff List
  132. L2HelperBuff template = new L2HelperBuff(helperBuffDat);
  133. _helperBuff.add(template);
  134. }
  135. _log.config("Helper Buff Table: Loaded " + _helperBuff.size() + " Templates.");
  136. }
  137. public boolean isInitialized()
  138. {
  139. return _initialized;
  140. }
  141. /**
  142. * Return the Helper Buff List
  143. */
  144. public List<L2HelperBuff> getHelperBuffTable()
  145. {
  146. return _helperBuff;
  147. }
  148. /**
  149. * @return Returns the magicClassHighestLevel.
  150. */
  151. public int getMagicClassHighestLevel()
  152. {
  153. return _magicClassHighestLevel;
  154. }
  155. /**
  156. * @return Returns the magicClassLowestLevel.
  157. */
  158. public int getMagicClassLowestLevel()
  159. {
  160. return _magicClassLowestLevel;
  161. }
  162. /**
  163. * @return Returns the physicClassHighestLevel.
  164. */
  165. public int getPhysicClassHighestLevel()
  166. {
  167. return _physicClassHighestLevel;
  168. }
  169. /**
  170. * @return Returns the physicClassLowestLevel.
  171. */
  172. public int getPhysicClassLowestLevel()
  173. {
  174. return _physicClassLowestLevel;
  175. }
  176. /**
  177. * @return Returns the servitorLowestLevel.
  178. */
  179. public int getServitorLowestLevel()
  180. {
  181. return _servitorLowestLevel;
  182. }
  183. /**
  184. @return Returns the servitorHighestLevel.
  185. */
  186. public int getServitorHighestLevel()
  187. {
  188. return _servitorHighestLevel;
  189. }
  190. @SuppressWarnings("synthetic-access")
  191. private static class SingletonHolder
  192. {
  193. protected static final HelperBuffTable _instance = new HelperBuffTable();
  194. }
  195. }