L2SkillLearn.java 7.2 KB

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