L2SkillLearn.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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.model.base.Race;
  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 Race[] _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. final int[] allowedRaces = set.getIntegerArray("race");
  79. final int totalRaces = allowedRaces.length;
  80. _races = new Race[totalRaces];
  81. for (int i = 0; i < totalRaces; i++)
  82. {
  83. _races[i] = Race.values()[allowedRaces[i]];
  84. }
  85. }
  86. else
  87. {
  88. _races = null;
  89. }
  90. if (!set.getString("preReqSkillIdLvl", "").isEmpty())
  91. {
  92. _preReqSkillIdLvl = new int[2];
  93. try
  94. {
  95. _preReqSkillIdLvl[0] = Integer.parseInt(set.getString("preReqSkillIdLvl").split(",")[0]);
  96. _preReqSkillIdLvl[1] = Integer.parseInt(set.getString("preReqSkillIdLvl").split(",")[1]);
  97. }
  98. catch (Exception e)
  99. {
  100. _log.severe(getClass().getSimpleName() + ": Malformed preReqSkillIdLvl for Learn Skill Id " + _skillId + " and level " + _skillLvl + "!");
  101. }
  102. }
  103. else
  104. {
  105. _preReqSkillIdLvl = null;
  106. }
  107. _socialClass = set.getInteger("socialClass", 0);
  108. _residenceSkill = set.getBool("residenceSkill", false);
  109. if (!set.getString("residenceIds", "").isEmpty())
  110. {
  111. _residenceIds = set.getIntegerArray("residenceIds");
  112. }
  113. else
  114. {
  115. _residenceIds = null;
  116. }
  117. if (!set.getString("subClassLvlNumber", "").isEmpty())
  118. {
  119. final String[] subLvLNumList = set.getString("subClassLvlNumber").split(";");
  120. _subClassLvlNumber = new int[subLvLNumList.length][2];
  121. int i = 0;
  122. for (String subLvlNum : subLvLNumList)
  123. {
  124. try
  125. {
  126. _subClassLvlNumber[i][0] = Integer.parseInt(subLvlNum.split(",")[0]);
  127. _subClassLvlNumber[i][1] = Integer.parseInt(subLvlNum.split(",")[1]);
  128. i++;
  129. }
  130. catch (Exception e)
  131. {
  132. _log.severe(getClass().getSimpleName() + ": Malformed subClassLvlNumber for Learn Skill Id " + _skillId + " and level " + _skillLvl + "!");
  133. }
  134. }
  135. }
  136. else
  137. {
  138. _subClassLvlNumber = null;
  139. }
  140. _learnedByNpc = set.getBool("learnedByNpc", false);
  141. _learnedByFS = set.getBool("learnedByFS", false);
  142. }
  143. /**
  144. * @return the name of this skill.
  145. */
  146. public String getName()
  147. {
  148. return _skillName;
  149. }
  150. /**
  151. * @return the ID of this skill.
  152. */
  153. public int getSkillId()
  154. {
  155. return _skillId;
  156. }
  157. /**
  158. * @return the level of this skill.
  159. */
  160. public int getSkillLevel()
  161. {
  162. return _skillLvl;
  163. }
  164. /**
  165. * @return the minimum level required to acquire this skill.
  166. */
  167. public int getGetLevel()
  168. {
  169. return _getLevel;
  170. }
  171. /**
  172. * @return the amount of SP/Clan Reputation to acquire this skill.
  173. */
  174. public int getLevelUpSp()
  175. {
  176. return _levelUpSp;
  177. }
  178. /**
  179. * @return {@code true} if the skill is auto-get, this skill is automatically delivered.
  180. */
  181. public boolean isAutoGet()
  182. {
  183. return _autoGet;
  184. }
  185. /**
  186. * @return the multidimensional array with the item IDs and amounts required to acquire this skill.
  187. */
  188. public int[][] getItemsIdCount()
  189. {
  190. return _itemsIdCount;
  191. }
  192. /**
  193. * @return the array with the races that can acquire this skill.
  194. */
  195. public Race[] getRaces()
  196. {
  197. return _races;
  198. }
  199. /**
  200. * @return the array with required skill IDs and levels to acquire this skill.
  201. */
  202. public int[] getPreReqSkillIdLvl()
  203. {
  204. return _preReqSkillIdLvl;
  205. }
  206. /**
  207. * @return the social class required to get this skill.
  208. */
  209. public int getSocialClass()
  210. {
  211. return _socialClass;
  212. }
  213. /**
  214. * @return {@code true} if this skill is a Residence skill.
  215. */
  216. public boolean isResidencialSkill()
  217. {
  218. return _residenceSkill;
  219. }
  220. /**
  221. * @return the array with the IDs where this skill is available.
  222. */
  223. public int[] getRecidenceIds()
  224. {
  225. return _residenceIds;
  226. }
  227. /**
  228. * @return the array with Sub-Class conditions, amount of subclasses and level.
  229. */
  230. public int[][] getSubClassConditions()
  231. {
  232. return _subClassLvlNumber;
  233. }
  234. /**
  235. * @return {@code true} if this skill is learned from Npc.
  236. */
  237. public boolean isLearnedByNpc()
  238. {
  239. return _learnedByNpc;
  240. }
  241. /**
  242. * @return {@code true} if this skill is learned by Forgotten Scroll.
  243. */
  244. public boolean isLearnedByFS()
  245. {
  246. return _learnedByFS;
  247. }
  248. /**
  249. * Used for AltGameSkillLearn mod.<br>
  250. * If the alternative skill learn system is enabled and the player is learning a skill from a different class apply a fee.<br>
  251. * If the player is learning a skill from other class type (mage learning warrior skills or vice versa) the fee is higher.
  252. * @param playerClass the player class Id.
  253. * @param learningClass the skill learning player class Id.
  254. * @return the amount of SP required to acquire this skill, by calculating the cost for the alternative skill learn system.
  255. */
  256. public int getCalculatedLevelUpSp(ClassId playerClass, ClassId learningClass)
  257. {
  258. if ((playerClass == null) || (learningClass == null))
  259. {
  260. return _levelUpSp;
  261. }
  262. int levelUpSp = _levelUpSp;
  263. // If the alternative skill learn system is enabled and the player is learning a skill from a different class apply a fee.
  264. if (Config.ALT_GAME_SKILL_LEARN && (playerClass != learningClass))
  265. {
  266. // If the player is learning a skill from other class type (mage learning warrior skills or vice versa) the fee is higher.
  267. if (playerClass.isMage() != learningClass.isMage())
  268. {
  269. levelUpSp *= 3;
  270. }
  271. else
  272. {
  273. levelUpSp *= 2;
  274. }
  275. }
  276. return levelUpSp;
  277. }
  278. }