L2SkillLearn.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.enums.Race;
  24. import com.l2jserver.gameserver.model.base.ClassId;
  25. import com.l2jserver.gameserver.model.base.SocialClass;
  26. import com.l2jserver.gameserver.model.holders.ItemHolder;
  27. import com.l2jserver.gameserver.model.holders.SkillHolder;
  28. /**
  29. * @author Zoey76
  30. */
  31. public final class L2SkillLearn
  32. {
  33. private final String _skillName;
  34. private final int _skillId;
  35. private final int _skillLvl;
  36. private final int _getLevel;
  37. private final boolean _autoGet;
  38. private final int _levelUpSp;
  39. private final List<ItemHolder> _requiredItems = new ArrayList<>();
  40. private final List<Race> _races = new ArrayList<>();
  41. private final List<SkillHolder> _preReqSkills = new ArrayList<>();
  42. private SocialClass _socialClass;
  43. private final boolean _residenceSkill;
  44. private final List<Integer> _residenceIds = new ArrayList<>();
  45. private final List<SubClassData> _subClassLvlNumber = new ArrayList<>();
  46. private final boolean _learnedByNpc;
  47. private final boolean _learnedByFS;
  48. public class SubClassData
  49. {
  50. private final int slot;
  51. private final int lvl;
  52. public SubClassData(int pSlot, int pLvl)
  53. {
  54. slot = pSlot;
  55. lvl = pLvl;
  56. }
  57. /**
  58. * @return the sub-class slot.
  59. */
  60. public int getSlot()
  61. {
  62. return slot;
  63. }
  64. /**
  65. * @return the required sub-class level.
  66. */
  67. public int getLvl()
  68. {
  69. return lvl;
  70. }
  71. }
  72. /**
  73. * Constructor for L2SkillLearn.
  74. * @param set the set with the L2SkillLearn data.
  75. */
  76. public L2SkillLearn(StatsSet set)
  77. {
  78. _skillName = set.getString("skillName");
  79. _skillId = set.getInt("skillId");
  80. _skillLvl = set.getInt("skillLvl");
  81. _getLevel = set.getInt("getLevel");
  82. _autoGet = set.getBoolean("autoGet", false);
  83. _levelUpSp = set.getInt("levelUpSp", 0);
  84. _residenceSkill = set.getBoolean("residenceSkill", false);
  85. _learnedByNpc = set.getBoolean("learnedByNpc", false);
  86. _learnedByFS = set.getBoolean("learnedByFS", false);
  87. }
  88. /**
  89. * @return the name of this skill.
  90. */
  91. public String getName()
  92. {
  93. return _skillName;
  94. }
  95. /**
  96. * @return the ID of this skill.
  97. */
  98. public int getSkillId()
  99. {
  100. return _skillId;
  101. }
  102. /**
  103. * @return the level of this skill.
  104. */
  105. public int getSkillLevel()
  106. {
  107. return _skillLvl;
  108. }
  109. /**
  110. * @return the minimum level required to acquire this skill.
  111. */
  112. public int getGetLevel()
  113. {
  114. return _getLevel;
  115. }
  116. /**
  117. * @return the amount of SP/Clan Reputation to acquire this skill.
  118. */
  119. public int getLevelUpSp()
  120. {
  121. return _levelUpSp;
  122. }
  123. /**
  124. * @return {@code true} if the skill is auto-get, this skill is automatically delivered.
  125. */
  126. public boolean isAutoGet()
  127. {
  128. return _autoGet;
  129. }
  130. /**
  131. * @return the list with the item holders required to acquire this skill.
  132. */
  133. public List<ItemHolder> getRequiredItems()
  134. {
  135. return _requiredItems;
  136. }
  137. /**
  138. * Adds a required item holder to learn this skill.
  139. * @param item the required item holder.
  140. */
  141. public void addRequiredItem(ItemHolder item)
  142. {
  143. _requiredItems.add(item);
  144. }
  145. /**
  146. * @return a list with the races that can acquire this skill.
  147. */
  148. public List<Race> getRaces()
  149. {
  150. return _races;
  151. }
  152. /**
  153. * Adds a required race to learn this skill.
  154. * @param race the required race.
  155. */
  156. public void addRace(Race race)
  157. {
  158. _races.add(race);
  159. }
  160. /**
  161. * @return the list of skill holders required to acquire this skill.
  162. */
  163. public List<SkillHolder> getPreReqSkills()
  164. {
  165. return _preReqSkills;
  166. }
  167. /**
  168. * Adds a required skill holder to learn this skill.
  169. * @param skill the required skill holder.
  170. */
  171. public void addPreReqSkill(SkillHolder skill)
  172. {
  173. _preReqSkills.add(skill);
  174. }
  175. /**
  176. * @return the social class required to get this skill.
  177. */
  178. public SocialClass getSocialClass()
  179. {
  180. return _socialClass;
  181. }
  182. /**
  183. * Sets the social class if hasn't been set before.
  184. * @param socialClass the social class to set.
  185. */
  186. public void setSocialClass(SocialClass socialClass)
  187. {
  188. if (_socialClass == null)
  189. {
  190. _socialClass = socialClass;
  191. }
  192. }
  193. /**
  194. * @return {@code true} if this skill is a Residence skill.
  195. */
  196. public boolean isResidencialSkill()
  197. {
  198. return _residenceSkill;
  199. }
  200. /**
  201. * @return a list with the Ids where this skill is available.
  202. */
  203. public List<Integer> getResidenceIds()
  204. {
  205. return _residenceIds;
  206. }
  207. /**
  208. * Adds a required residence Id.
  209. * @param id the residence Id to add.
  210. */
  211. public void addResidenceId(Integer id)
  212. {
  213. _residenceIds.add(id);
  214. }
  215. /**
  216. * @return a list with Sub-Class conditions, amount of subclasses and level.
  217. */
  218. public List<SubClassData> getSubClassConditions()
  219. {
  220. return _subClassLvlNumber;
  221. }
  222. /**
  223. * Adds a required residence Id.
  224. * @param slot the sub-class slot.
  225. * @param lvl the required sub-class level.
  226. */
  227. public void addSubclassConditions(int slot, int lvl)
  228. {
  229. _subClassLvlNumber.add(new SubClassData(slot, lvl));
  230. }
  231. /**
  232. * @return {@code true} if this skill is learned from Npc.
  233. */
  234. public boolean isLearnedByNpc()
  235. {
  236. return _learnedByNpc;
  237. }
  238. /**
  239. * @return {@code true} if this skill is learned by Forgotten Scroll.
  240. */
  241. public boolean isLearnedByFS()
  242. {
  243. return _learnedByFS;
  244. }
  245. /**
  246. * Used for AltGameSkillLearn mod.<br>
  247. * If the alternative skill learn system is enabled and the player is learning a skill from a different class apply a fee.<br>
  248. * If the player is learning a skill from other class type (mage learning warrior skills or vice versa) the fee is higher.
  249. * @param playerClass the player class Id.
  250. * @param learningClass the skill learning player class Id.
  251. * @return the amount of SP required to acquire this skill, by calculating the cost for the alternative skill learn system.
  252. */
  253. public int getCalculatedLevelUpSp(ClassId playerClass, ClassId learningClass)
  254. {
  255. if ((playerClass == null) || (learningClass == null))
  256. {
  257. return _levelUpSp;
  258. }
  259. int levelUpSp = _levelUpSp;
  260. // If the alternative skill learn system is enabled and the player is learning a skill from a different class apply a fee.
  261. if (Config.ALT_GAME_SKILL_LEARN && (playerClass != learningClass))
  262. {
  263. // If the player is learning a skill from other class type (mage learning warrior skills or vice versa) the fee is higher.
  264. if (playerClass.isMage() != learningClass.isMage())
  265. {
  266. levelUpSp *= 3;
  267. }
  268. else
  269. {
  270. levelUpSp *= 2;
  271. }
  272. }
  273. return levelUpSp;
  274. }
  275. }