L2EnchantSkillLearn.java 5.9 KB

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