L2EnchantSkillLearn.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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.model;
  16. import java.util.List;
  17. import com.l2jserver.gameserver.datatables.SkillTreeTable;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import javolution.util.FastTable;
  20. /**
  21. * This class ...
  22. *
  23. * @version $Revision: 1.2.4.2 $ $Date: 2005/03/27 15:29:33 $
  24. */
  25. @SuppressWarnings("unchecked")
  26. public final class L2EnchantSkillLearn
  27. {
  28. private final int _id;
  29. private final int _baseLvl;
  30. private List<EnchantSkillDetail>[] _enchantDetails = new List[0];
  31. public L2EnchantSkillLearn(int id, int baseLvl)
  32. {
  33. _id = id;
  34. _baseLvl = baseLvl;
  35. }
  36. /**
  37. * @return Returns the id.
  38. */
  39. public int getId()
  40. {
  41. return _id;
  42. }
  43. /**
  44. * @return Returns the minLevel.
  45. */
  46. public int getBaseLevel()
  47. {
  48. return _baseLvl;
  49. }
  50. public void addEnchantDetail(EnchantSkillDetail esd)
  51. {
  52. int enchantType = L2EnchantSkillLearn.getEnchantType(esd.getLevel());
  53. if (enchantType < 0)
  54. {
  55. throw new IllegalArgumentException("Skill enchantments should have level higher then 100");
  56. }
  57. else
  58. {
  59. if (enchantType >= _enchantDetails.length)
  60. {
  61. List<EnchantSkillDetail>[] newArray = new List[enchantType+1];
  62. System.arraycopy(_enchantDetails, 0, newArray, 0, _enchantDetails.length);
  63. _enchantDetails = newArray;
  64. _enchantDetails[enchantType] = new FastTable<EnchantSkillDetail>();
  65. }
  66. int index = L2EnchantSkillLearn.getEnchantIndex(esd.getLevel());
  67. _enchantDetails[enchantType].add(index, esd);
  68. }
  69. }
  70. public List<EnchantSkillDetail>[] getEnchantRoutes()
  71. {
  72. return _enchantDetails;
  73. }
  74. public EnchantSkillDetail getEnchantSkillDetail(int level)
  75. {
  76. int enchantType = L2EnchantSkillLearn.getEnchantType(level);
  77. if (enchantType < 0 || enchantType >= _enchantDetails.length)
  78. {
  79. return null;
  80. }
  81. int index = L2EnchantSkillLearn.getEnchantIndex(level);
  82. if (index < 0 || index >= _enchantDetails[enchantType].size())
  83. {
  84. return null;
  85. }
  86. return _enchantDetails[enchantType].get(index);
  87. }
  88. public static int getEnchantIndex(int level)
  89. {
  90. return (level % 100) - 1;
  91. }
  92. public static int getEnchantType(int level)
  93. {
  94. return ((level - 1) / 100) - 1;
  95. }
  96. public static class EnchantSkillDetail
  97. {
  98. private final int _level;
  99. private final int _spCost;
  100. private final int _minSkillLevel;
  101. private final int _exp;
  102. private final byte _rate76,_rate77,_rate78,_rate79,_rate80,_rate81,_rate82,_rate83,_rate84,_rate85;
  103. public EnchantSkillDetail(int lvl, int minSkillLvl, int cost, int exp, byte rate76, byte rate77, byte rate78, byte rate79, byte rate80, byte rate81, byte rate82, byte rate83, byte rate84, byte rate85)
  104. {
  105. _level = lvl;
  106. _minSkillLevel = minSkillLvl;
  107. _spCost = cost;
  108. _exp = exp;
  109. _rate76 = rate76;
  110. _rate77 = rate77;
  111. _rate78 = rate78;
  112. _rate79 = rate79;
  113. _rate80 = rate80;
  114. _rate81 = rate81;
  115. _rate82 = rate82;
  116. _rate83 = rate83;
  117. _rate84 = rate84;
  118. _rate85 = rate85;
  119. }
  120. /**
  121. * @return Returns the level.
  122. */
  123. public int getLevel()
  124. {
  125. return _level;
  126. }
  127. /**
  128. * @return Returns the minSkillLevel.
  129. */
  130. public int getMinSkillLevel()
  131. {
  132. return _minSkillLevel;
  133. }
  134. /**
  135. * @return Returns the spCost.
  136. */
  137. public int getSpCost()
  138. {
  139. return _spCost;
  140. }
  141. public int getAdena()
  142. {
  143. return _exp / SkillTreeTable.ADENA_XP_DIV;
  144. }
  145. public byte getRate(L2PcInstance ply)
  146. {
  147. byte result;
  148. switch (ply.getLevel())
  149. {
  150. case 76:
  151. result = _rate76;
  152. break;
  153. case 77:
  154. result = _rate77;
  155. break;
  156. case 78:
  157. result = _rate78;
  158. break;
  159. case 79:
  160. result = _rate79;
  161. break;
  162. case 80:
  163. result = _rate80;
  164. break;
  165. case 81:
  166. result = _rate81;
  167. break;
  168. case 82:
  169. result = _rate82;
  170. break;
  171. case 83:
  172. result = _rate83;
  173. break;
  174. case 84:
  175. result = _rate84;
  176. break;
  177. case 85:
  178. result = _rate85;
  179. break;
  180. default:
  181. result = _rate85;
  182. break;
  183. }
  184. return result;
  185. }
  186. }
  187. }