L2SkillLearn.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.model.base.ClassId;
  19. import com.l2jserver.gameserver.templates.StatsSet;
  20. /**
  21. * @author Zoey76
  22. */
  23. public final class L2SkillLearn
  24. {
  25. private static final Logger _log = Logger.getLogger(L2SkillLearn.class.getName());
  26. private final String _skillName;
  27. private final int _skillId;
  28. private final int _skillLvl;
  29. private final int _getLevel;
  30. private final boolean _autoGet;
  31. private final int _levelUpSp;
  32. private final int[][] _itemsIdCount;
  33. private final int[] _races;
  34. private final int[] _preReqSkillIdLvl;
  35. private final int _socialClass;
  36. private final boolean _residenceSkill;
  37. private final int[] _residenceIds;
  38. private final int[][] _subClassLvlNumber;
  39. private final boolean _learnedByNpc;
  40. private final boolean _learnedByFS;
  41. /**
  42. * Constructor for L2SkillLearn.
  43. * @param set the set with the L2SkillLearn data.
  44. */
  45. public L2SkillLearn(StatsSet set)
  46. {
  47. _skillName = set.getString("skillName");
  48. _skillId = set.getInteger("skillId");
  49. _skillLvl = set.getInteger("skillLvl");
  50. _getLevel = set.getInteger("getLevel");
  51. _autoGet = set.getBool("autoGet", false);
  52. _levelUpSp = set.getInteger("levelUpSp", 0);
  53. if (!set.getString("itemsIdCount", "").isEmpty())
  54. {
  55. final String[] items = set.getString("itemsIdCount").split(";");
  56. _itemsIdCount = new int[items.length][2];
  57. int i = 0;
  58. for (String itemIdCount : items)
  59. {
  60. try
  61. {
  62. _itemsIdCount[i][0] = Integer.parseInt(itemIdCount.split(",")[0]);//Id
  63. _itemsIdCount[i][1] = Integer.parseInt(itemIdCount.split(",")[1]);//Count
  64. i++;
  65. }
  66. catch (Exception e)
  67. {
  68. _log.severe(getClass().getSimpleName() + ": Malformed itemsIdCount for Learn Skill Id " + _skillId + " and level " + _skillLvl + "!");
  69. }
  70. }
  71. }
  72. else
  73. {
  74. _itemsIdCount = null;
  75. }
  76. if (!set.getString("race", "").isEmpty())
  77. {
  78. _races = set.getIntegerArray("race");
  79. }
  80. else
  81. {
  82. _races = null;
  83. }
  84. if (!set.getString("preReqSkillIdLvl", "").isEmpty())
  85. {
  86. _preReqSkillIdLvl = new int[2];
  87. try
  88. {
  89. _preReqSkillIdLvl[0] = Integer.parseInt(set.getString("preReqSkillIdLvl").split(",")[0]);
  90. _preReqSkillIdLvl[1] = Integer.parseInt(set.getString("preReqSkillIdLvl").split(",")[1]);
  91. }
  92. catch (Exception e)
  93. {
  94. _log.severe(getClass().getSimpleName() + ": Malformed preReqSkillIdLvl for Learn Skill Id " + _skillId + " and level " + _skillLvl + "!");
  95. }
  96. }
  97. else
  98. {
  99. _preReqSkillIdLvl = null;
  100. }
  101. _socialClass = set.getInteger("socialClass", 0);
  102. _residenceSkill = set.getBool("residenceSkill", false);
  103. if (!set.getString("residenceIds", "").isEmpty())
  104. {
  105. _residenceIds = set.getIntegerArray("residenceIds");
  106. }
  107. else
  108. {
  109. _residenceIds = null;
  110. }
  111. if (!set.getString("subClassLvlNumber", "").isEmpty())
  112. {
  113. final String[] subLvLNumList = set.getString("subClassLvlNumber").split(";");
  114. _subClassLvlNumber = new int[subLvLNumList.length][2];
  115. int i = 0;
  116. for (String subLvlNum : subLvLNumList)
  117. {
  118. try
  119. {
  120. _subClassLvlNumber[i][0] = Integer.parseInt(subLvlNum.split(",")[0]);
  121. _subClassLvlNumber[i][1] = Integer.parseInt(subLvlNum.split(",")[1]);
  122. i++;
  123. }
  124. catch (Exception e)
  125. {
  126. _log.severe(getClass().getSimpleName() + ": Malformed subClassLvlNumber for Learn Skill Id " + _skillId + " and level " + _skillLvl + "!");
  127. }
  128. }
  129. }
  130. else
  131. {
  132. _subClassLvlNumber = null;
  133. }
  134. _learnedByNpc = set.getBool("learnedByNpc", false);
  135. _learnedByFS = set.getBool("learnedByFS", false);
  136. }
  137. /**
  138. * @return the name of this skill.
  139. */
  140. public String getName()
  141. {
  142. return _skillName;
  143. }
  144. /**
  145. * @return the ID of this skill.
  146. */
  147. public int getSkillId()
  148. {
  149. return _skillId;
  150. }
  151. /**
  152. * @return the level of this skill.
  153. */
  154. public int getSkillLevel()
  155. {
  156. return _skillLvl;
  157. }
  158. /**
  159. * @return the minimum level required to acquire this skill.
  160. */
  161. public int getGetLevel()
  162. {
  163. return _getLevel;
  164. }
  165. /**
  166. * @return the amount of SP/Clan Reputation to acquire this skill.
  167. */
  168. public int getLevelUpSp()
  169. {
  170. return _levelUpSp;
  171. }
  172. /**
  173. * @return {@code true} if the skill is auto-get, this skill is automatically delivered.
  174. */
  175. public boolean isAutoGet()
  176. {
  177. return _autoGet;
  178. }
  179. /**
  180. * @return the multidimensional array with the item IDs and amounts required to acquire this skill.
  181. */
  182. public int[][] getItemsIdCount()
  183. {
  184. return _itemsIdCount;
  185. }
  186. /**
  187. * @return the array with the races that can acquire this skill.
  188. */
  189. public int[] getRaces()
  190. {
  191. return _races;
  192. }
  193. /**
  194. * @return the array with required skill IDs and levels to acquire this skill.
  195. */
  196. public int[] getPreReqSkillIdLvl()
  197. {
  198. return _preReqSkillIdLvl;
  199. }
  200. /**
  201. * @return the social class required to get this skill.
  202. */
  203. public int getSocialClass()
  204. {
  205. return _socialClass;
  206. }
  207. /**
  208. * @return {@code true} if this skill is a Residence skill.
  209. */
  210. public boolean isResidencialSkill()
  211. {
  212. return _residenceSkill;
  213. }
  214. /**
  215. * @return the array with the IDs where this skill is available.
  216. */
  217. public int[] getRecidenceIds()
  218. {
  219. return _residenceIds;
  220. }
  221. /**
  222. * @return the array with Sub-Class conditions, amount of subclasses and level.
  223. */
  224. public int[][] getSubClassConditions()
  225. {
  226. return _subClassLvlNumber;
  227. }
  228. /**
  229. * @return {@code true} if this skill is learned from Npc.
  230. */
  231. public boolean isLearnedByNpc()
  232. {
  233. return _learnedByNpc;
  234. }
  235. /**
  236. * @return {@code true} if this skill is learned by Forgotten Scroll.
  237. */
  238. public boolean isLearnedByFS()
  239. {
  240. return _learnedByFS;
  241. }
  242. /**
  243. * Used for AltGameSkillLearn mod.<br>
  244. * If the alternative skill learn system is enabled and the player is learning a skill from a different class apply a fee.<br>
  245. * If the player is learning a skill from other class type (mage learning warrior skills or vice versa) the fee is higher.
  246. * @param playerClass the player class Id.
  247. * @param learningClass the skill learning player class Id.
  248. * @return the amount of SP required to acquire this skill, by calculating the cost for the alternative skill learn system.
  249. */
  250. public int getCalculatedLevelUpSp(ClassId playerClass, ClassId learningClass)
  251. {
  252. if ((playerClass == null) || (learningClass == null))
  253. {
  254. return _levelUpSp;
  255. }
  256. int levelUpSp = _levelUpSp;
  257. // If the alternative skill learn system is enabled and the player is learning a skill from a different class apply a fee.
  258. if (Config.ALT_GAME_SKILL_LEARN && (playerClass != learningClass))
  259. {
  260. // If the player is learning a skill from other class type (mage learning warrior skills or vice versa) the fee is higher.
  261. if (playerClass.isMage() != learningClass.isMage())
  262. {
  263. levelUpSp *= 3;
  264. }
  265. else
  266. {
  267. levelUpSp *= 2;
  268. }
  269. }
  270. return levelUpSp;
  271. }
  272. }