2
0

L2EnchantSkillLearn.java 5.2 KB

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