HelperBuffTable.java 6.2 KB

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