L2SkillLearn.java 7.9 KB

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