2
0

HelperBuffTable.java 6.3 KB

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