L2EnchantSkillLearn.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. @SuppressWarnings("unchecked")
  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. // not needed, just for easier debug
  99. private final String _name;
  100. private final int _level;
  101. private final int _spCost;
  102. private final int _minSkillLevel;
  103. private final int _exp;
  104. private final byte _rate76;
  105. private final byte _rate77;
  106. private final byte _rate78;
  107. public EnchantSkillDetail(int lvl, int minSkillLvl, String name, int cost, int exp, byte rate76, byte rate77, byte rate78)
  108. {
  109. _level = lvl;
  110. _minSkillLevel = minSkillLvl;
  111. _name = name.intern();
  112. _spCost = cost;
  113. _exp = exp;
  114. _rate76 = rate76;
  115. _rate77 = rate77;
  116. _rate78 = rate78;
  117. }
  118. /**
  119. * @return Returns the level.
  120. */
  121. public int getLevel()
  122. {
  123. return _level;
  124. }
  125. /**
  126. * @return Returns the minSkillLevel.
  127. */
  128. public int getMinSkillLevel()
  129. {
  130. return _minSkillLevel;
  131. }
  132. /**
  133. * @return Returns the name.
  134. */
  135. public String getName()
  136. {
  137. return _name;
  138. }
  139. /**
  140. * @return Returns the spCost.
  141. */
  142. public int getSpCost()
  143. {
  144. return _spCost;
  145. }
  146. public int getExp()
  147. {
  148. return _exp;
  149. }
  150. public byte getRate(L2PcInstance ply)
  151. {
  152. byte result;
  153. switch (ply.getLevel())
  154. {
  155. case 76:
  156. result = _rate76;
  157. break;
  158. case 77:
  159. result = _rate77;
  160. break;
  161. case 78:
  162. result = _rate78;
  163. break;
  164. default:
  165. result = _rate78;
  166. break;
  167. }
  168. return result;
  169. }
  170. }
  171. }