HelperBuffTable.java 6.4 KB

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