2
0

HelperBuffTable.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.datatables;
  20. import java.sql.Connection;
  21. import java.sql.ResultSet;
  22. import java.sql.Statement;
  23. import java.util.List;
  24. import java.util.logging.Level;
  25. import java.util.logging.Logger;
  26. import javolution.util.FastList;
  27. import com.l2jserver.L2DatabaseFactory;
  28. import com.l2jserver.gameserver.model.L2HelperBuff;
  29. import com.l2jserver.gameserver.model.StatsSet;
  30. /**
  31. * This class represents the Newbie Helper Buff list
  32. * @author Ayor
  33. */
  34. public class HelperBuffTable
  35. {
  36. private static Logger _log = Logger.getLogger(HelperBuffTable.class.getName());
  37. /** The table containing all Buff of the Newbie Helper */
  38. private final List<L2HelperBuff> _helperBuff;
  39. /**
  40. * The player level since Newbie Helper can give the fisrt buff <BR>
  41. * Used to generate message : "Come back here when you have reached level ...")
  42. */
  43. private int _magicClassLowestLevel = 100;
  44. private int _physicClassLowestLevel = 100;
  45. /**
  46. * The player level above which Newbie Helper won't give any buff <BR>
  47. * Used to generate message : "Only novice character of level ... or less can receive my support magic.")
  48. */
  49. private int _magicClassHighestLevel = 1;
  50. private int _physicClassHighestLevel = 1;
  51. private int _servitorLowestLevel = 100;
  52. private int _servitorHighestLevel = 1;
  53. public static HelperBuffTable getInstance()
  54. {
  55. return SingletonHolder._instance;
  56. }
  57. /**
  58. * Create and Load the Newbie Helper Buff list from SQL Table helper_buff_list
  59. */
  60. protected HelperBuffTable()
  61. {
  62. _helperBuff = new FastList<>();
  63. restoreHelperBuffData();
  64. }
  65. /**
  66. * Read and Load the Newbie Helper Buff list from SQL Table helper_buff_list
  67. */
  68. private void restoreHelperBuffData()
  69. {
  70. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  71. Statement s = con.createStatement();
  72. ResultSet HelperBuffData = s.executeQuery("SELECT * FROM helper_buff_list"))
  73. {
  74. while (HelperBuffData.next())
  75. {
  76. StatsSet helperBuffDat = new StatsSet();
  77. int id = HelperBuffData.getInt("id");
  78. helperBuffDat.set("id", id);
  79. helperBuffDat.set("skillID", HelperBuffData.getInt("skill_id"));
  80. helperBuffDat.set("skillLevel", HelperBuffData.getInt("skill_level"));
  81. helperBuffDat.set("lowerLevel", HelperBuffData.getInt("lower_level"));
  82. helperBuffDat.set("upperLevel", HelperBuffData.getInt("upper_level"));
  83. helperBuffDat.set("isMagicClass", HelperBuffData.getString("is_magic_class"));
  84. helperBuffDat.set("forSummon", HelperBuffData.getString("forSummon"));
  85. // Calulate the range level in wich player must be to obtain buff from Newbie Helper
  86. if ("false".equals(HelperBuffData.getString("is_magic_class")))
  87. {
  88. if (HelperBuffData.getInt("lower_level") < _physicClassLowestLevel)
  89. {
  90. _physicClassLowestLevel = HelperBuffData.getInt("lower_level");
  91. }
  92. if (HelperBuffData.getInt("upper_level") > _physicClassHighestLevel)
  93. {
  94. _physicClassHighestLevel = HelperBuffData.getInt("upper_level");
  95. }
  96. }
  97. else
  98. {
  99. if (HelperBuffData.getInt("lower_level") < _magicClassLowestLevel)
  100. {
  101. _magicClassLowestLevel = HelperBuffData.getInt("lower_level");
  102. }
  103. if (HelperBuffData.getInt("upper_level") > _magicClassHighestLevel)
  104. {
  105. _magicClassHighestLevel = HelperBuffData.getInt("upper_level");
  106. }
  107. }
  108. if ("true".equals(HelperBuffData.getString("forSummon")))
  109. {
  110. if (HelperBuffData.getInt("lower_level") < _servitorLowestLevel)
  111. {
  112. _servitorLowestLevel = HelperBuffData.getInt("lower_level");
  113. }
  114. if (HelperBuffData.getInt("upper_level") > _servitorHighestLevel)
  115. {
  116. _servitorHighestLevel = HelperBuffData.getInt("upper_level");
  117. }
  118. }
  119. // Add this Helper Buff to the Helper Buff List
  120. L2HelperBuff template = new L2HelperBuff(helperBuffDat);
  121. _helperBuff.add(template);
  122. }
  123. _log.info(getClass().getSimpleName() + ": Loaded " + _helperBuff.size() + " Templates.");
  124. }
  125. catch (Exception e)
  126. {
  127. _log.log(Level.SEVERE, getClass().getSimpleName() + ": Table helper_buff_list not found : Update your DataPack! Error : " + e.getMessage(), e);
  128. }
  129. }
  130. /**
  131. * @return the Helper Buff List
  132. */
  133. public List<L2HelperBuff> getHelperBuffTable()
  134. {
  135. return _helperBuff;
  136. }
  137. /**
  138. * @return Returns the magicClassHighestLevel.
  139. */
  140. public int getMagicClassHighestLevel()
  141. {
  142. return _magicClassHighestLevel;
  143. }
  144. /**
  145. * @return Returns the magicClassLowestLevel.
  146. */
  147. public int getMagicClassLowestLevel()
  148. {
  149. return _magicClassLowestLevel;
  150. }
  151. /**
  152. * @return Returns the physicClassHighestLevel.
  153. */
  154. public int getPhysicClassHighestLevel()
  155. {
  156. return _physicClassHighestLevel;
  157. }
  158. /**
  159. * @return Returns the physicClassLowestLevel.
  160. */
  161. public int getPhysicClassLowestLevel()
  162. {
  163. return _physicClassLowestLevel;
  164. }
  165. /**
  166. * @return Returns the servitorLowestLevel.
  167. */
  168. public int getServitorLowestLevel()
  169. {
  170. return _servitorLowestLevel;
  171. }
  172. /**
  173. * @return Returns the servitorHighestLevel.
  174. */
  175. public int getServitorHighestLevel()
  176. {
  177. return _servitorHighestLevel;
  178. }
  179. private static class SingletonHolder
  180. {
  181. protected static final HelperBuffTable _instance = new HelperBuffTable();
  182. }
  183. }