SkillTreesData.java 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  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.datatables;
  16. import gnu.trove.map.hash.TIntObjectHashMap;
  17. import java.io.File;
  18. import java.util.Arrays;
  19. import java.util.Collection;
  20. import java.util.Map.Entry;
  21. import java.util.Set;
  22. import java.util.logging.Logger;
  23. import javax.xml.parsers.DocumentBuilderFactory;
  24. import javolution.util.FastList;
  25. import javolution.util.FastMap;
  26. import org.w3c.dom.Document;
  27. import org.w3c.dom.NamedNodeMap;
  28. import org.w3c.dom.Node;
  29. import com.l2jserver.Config;
  30. import com.l2jserver.gameserver.model.L2Clan;
  31. import com.l2jserver.gameserver.model.L2SkillLearn;
  32. import com.l2jserver.gameserver.model.StatsSet;
  33. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  34. import com.l2jserver.gameserver.model.base.ClassId;
  35. import com.l2jserver.gameserver.model.base.Race;
  36. import com.l2jserver.gameserver.model.base.SubClass;
  37. import com.l2jserver.gameserver.model.skills.L2Skill;
  38. import com.l2jserver.gameserver.util.Util;
  39. import com.l2jserver.util.file.filter.XMLFilter;
  40. /**
  41. * This class loads and manage the characters and pledges skills trees.<br>
  42. * Here can be found the following skill trees:<br>
  43. * <ul>
  44. * <li>Class skill trees: player skill trees for each class.</li>
  45. * <li>Transfer skill trees: player skill trees for each healer class.</lI>
  46. * <li>Collect skill tree: player skill tree for Gracia related skills.</li>
  47. * <li>Fishing skill tree: player skill tree for fishing related skills.</li>
  48. * <li>Transform skill tree: player skill tree for transformation related skills.</li>
  49. * <li>Sub-Class skill tree: player skill tree for sub-class related skills.</li>
  50. * <li>Noble skill tree: player skill tree for noblesse related skills.</li>
  51. * <li>Hero skill tree: player skill tree for heroes related skills.</li>
  52. * <li>GM skill tree: player skill tree for Game Master related skills.</li>
  53. * <li>Common skill tree: custom skill tree for players, skills in this skill tree will be available for all players.</li>
  54. * <li>Pledge skill tree: clan skill tree for main clan.</li>
  55. * <li>Sub-Pledge skill tree: clan skill tree for sub-clans.<li>
  56. * </ul>
  57. * For easy customization of player class skill trees, the parent Id of each class is taken from the XML data, this means you can use a different class parent Id than in the normal game play, for example all 3rd class dagger users will have Treasure Hunter skills as 1st and 2nd class skills.<br>
  58. * For XML schema please refer to skillTrees.xsd in datapack in xsd folder and for parameters documentation refer to documentation.txt in skillTrees folder.<br>
  59. * @author Zoey76
  60. */
  61. public final class SkillTreesData
  62. {
  63. private static final Logger _log = Logger.getLogger(SkillTreesData.class.getName());
  64. // ClassId, FastMap of Skill Hash Code, L2SkillLearn
  65. private static final FastMap<ClassId, FastMap<Integer, L2SkillLearn>> _classSkillTrees = new FastMap<ClassId, FastMap<Integer, L2SkillLearn>>();
  66. private static final FastMap<ClassId, FastMap<Integer, L2SkillLearn>> _transferSkillTrees = new FastMap<ClassId, FastMap<Integer, L2SkillLearn>>();
  67. // Skill Hash Code, L2SkillLearn
  68. private static final FastMap<Integer, L2SkillLearn> _collectSkillTree = new FastMap<Integer, L2SkillLearn>();
  69. private static final FastMap<Integer, L2SkillLearn> _fishingSkillTree = new FastMap<Integer, L2SkillLearn>();
  70. private static final FastMap<Integer, L2SkillLearn> _pledgeSkillTree = new FastMap<Integer, L2SkillLearn>();
  71. private static final FastMap<Integer, L2SkillLearn> _subClassSkillTree = new FastMap<Integer, L2SkillLearn>();
  72. private static final FastMap<Integer, L2SkillLearn> _subPledgeSkillTree = new FastMap<Integer, L2SkillLearn>();
  73. private static final FastMap<Integer, L2SkillLearn> _transformSkillTree = new FastMap<Integer, L2SkillLearn>();
  74. private static final FastMap<Integer, L2SkillLearn> _commonSkillTree = new FastMap<Integer, L2SkillLearn>();
  75. // Other skill trees
  76. private static final FastMap<Integer, L2SkillLearn> _nobleSkillTree = new FastMap<>();
  77. private static final FastMap<Integer, L2SkillLearn> _heroSkillTree = new FastMap<>();
  78. private static final FastMap<Integer, L2SkillLearn> _gameMasterSkillTree = new FastMap<>();
  79. private static final FastMap<Integer, L2SkillLearn> _gameMasterAuraSkillTree = new FastMap<>();
  80. // Checker, sorted arrays of hash codes
  81. private TIntObjectHashMap<int[]> _skillsByClassIdHashCodes; // Occupation skills
  82. private TIntObjectHashMap<int[]> _skillsByRaceHashCodes; // Race-specific Transformations
  83. private int[] _allSkillsHashCodes; // Fishing, Collection, Transformations, Common Skills.
  84. private boolean _loading = true;
  85. /**
  86. * Parent class IDs are read from XML and stored in this map, to allow easy customization.
  87. */
  88. private static final FastMap<ClassId, ClassId> _parentClassMap = new FastMap<ClassId, ClassId>();
  89. private SkillTreesData()
  90. {
  91. load();
  92. }
  93. /**
  94. * Wrapper for required actions to clear and load all skill trees.
  95. */
  96. public void load()
  97. {
  98. _loading = true;
  99. _classSkillTrees.clear();
  100. _collectSkillTree.clear();
  101. _fishingSkillTree.clear();
  102. _pledgeSkillTree.clear();
  103. _subClassSkillTree.clear();
  104. _subPledgeSkillTree.clear();
  105. _transferSkillTrees.clear();
  106. _transformSkillTree.clear();
  107. _nobleSkillTree.clear();
  108. _heroSkillTree.clear();
  109. _gameMasterSkillTree.clear();
  110. _gameMasterAuraSkillTree.clear();
  111. // Load files.
  112. _loading = loadFiles();
  113. // Generate check arrays.
  114. generateCheckArrays();
  115. int classSkillTreeCount = 0;
  116. for (ClassId classId : _classSkillTrees.keySet())
  117. {
  118. classSkillTreeCount += _classSkillTrees.get(classId).size();
  119. }
  120. int trasferSkillTreeCount = 0;
  121. for (ClassId classId : _transferSkillTrees.keySet())
  122. {
  123. trasferSkillTreeCount += _transferSkillTrees.get(classId).size();
  124. }
  125. int fishingDwarvenSkillCount = 0;
  126. for (L2SkillLearn fishSkill : _fishingSkillTree.values())
  127. {
  128. if ((fishSkill.getRaces() != null) && Util.contains(fishSkill.getRaces(), Race.Dwarf))
  129. {
  130. fishingDwarvenSkillCount++;
  131. }
  132. }
  133. int residentialSkillCount = 0;
  134. for (L2SkillLearn pledgeSkill : _pledgeSkillTree.values())
  135. {
  136. if (pledgeSkill.isResidencialSkill())
  137. {
  138. residentialSkillCount++;
  139. }
  140. }
  141. _log.info(getClass().getSimpleName() + ": Loaded " + classSkillTreeCount + " Class Skills for " + _classSkillTrees.size() + " Class Skill Trees.");
  142. _log.info(getClass().getSimpleName() + ": Loaded " + _subClassSkillTree.size() + " Sub-Class Skills.");
  143. _log.info(getClass().getSimpleName() + ": Loaded " + trasferSkillTreeCount + " Transfer Skills for " + _transferSkillTrees.size() + " Transfer Skill Trees.");
  144. _log.info(getClass().getSimpleName() + ": Loaded " + _fishingSkillTree.size() + " Fishing Skills, " + fishingDwarvenSkillCount + " Dwarven only Fishing Skills.");
  145. _log.info(getClass().getSimpleName() + ": Loaded " + _collectSkillTree.size() + " Collect Skills.");
  146. _log.info(getClass().getSimpleName() + ": Loaded " + _pledgeSkillTree.size() + " Pledge Skills, " + (_pledgeSkillTree.size() - residentialSkillCount) + " for Pledge and " + residentialSkillCount + " Residential.");
  147. _log.info(getClass().getSimpleName() + ": Loaded " + _subPledgeSkillTree.size() + " Sub-Pledge Skills.");
  148. _log.info(getClass().getSimpleName() + ": Loaded " + _transformSkillTree.size() + " Transform Skills.");
  149. _log.info(getClass().getSimpleName() + ": Loaded " + _nobleSkillTree.size() + " Noble Skills.");
  150. _log.info(getClass().getSimpleName() + ": Loaded " + _heroSkillTree.size() + " Hero Skills.");
  151. _log.info(getClass().getSimpleName() + ": Loaded " + _gameMasterSkillTree.size() + " Game Master Skills.");
  152. _log.info(getClass().getSimpleName() + ": Loaded " + _gameMasterAuraSkillTree.size() + " Game Master Aura Skills.");
  153. final int commonSkills = _commonSkillTree.size();
  154. if (commonSkills > 0)
  155. {
  156. _log.info(getClass().getSimpleName() + ": Loaded " + commonSkills + " Common Skills to all classes.");
  157. }
  158. }
  159. /**
  160. * Loads all files type XML from data/skillTrees/ and call the parser for each one of them.
  161. * @return {@code false} when the files are loaded.
  162. */
  163. private boolean loadFiles()
  164. {
  165. final File folder = new File(Config.DATAPACK_ROOT, "data/skillTrees/");
  166. if (!folder.exists())
  167. {
  168. _log.warning(getClass().getSimpleName() + ": Folder " + folder.getAbsolutePath() + " doesn't exist!");
  169. return false;
  170. }
  171. final File[] listOfFiles = folder.listFiles(new XMLFilter());
  172. for (File f : listOfFiles)
  173. {
  174. loadSkillTree(f);
  175. }
  176. return false;
  177. }
  178. /**
  179. * Parse a skill tree file and store it into the correct skill tree.
  180. * @param file the XML file to be parsed.
  181. */
  182. private void loadSkillTree(File file)
  183. {
  184. if (!file.exists())
  185. {
  186. _log.warning(getClass().getSimpleName() + ": Could not parse " + file.getName() + " file doesn't exist");
  187. return;
  188. }
  189. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  190. dbf.setValidating(false);
  191. dbf.setIgnoringComments(true);
  192. Document doc = null;
  193. try
  194. {
  195. doc = dbf.newDocumentBuilder().parse(file);
  196. }
  197. catch (Exception e)
  198. {
  199. _log.warning(getClass().getSimpleName() + ": Could not parse " + file.getName() + " file: " + e.getMessage());
  200. return;
  201. }
  202. NamedNodeMap attributes;
  203. Node attribute;
  204. String type = null;
  205. int cId = -1;
  206. int parentClassId = -1;
  207. ClassId classId = null;
  208. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  209. {
  210. if ("list".equalsIgnoreCase(n.getNodeName()))
  211. {
  212. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  213. {
  214. final FastMap<Integer, L2SkillLearn> classSkillTree = new FastMap<Integer, L2SkillLearn>();
  215. final FastMap<Integer, L2SkillLearn> trasferSkillTree = new FastMap<Integer, L2SkillLearn>();
  216. if ("skillTree".equalsIgnoreCase(d.getNodeName()))
  217. {
  218. attribute = d.getAttributes().getNamedItem("type");
  219. if (attribute == null)
  220. {
  221. _log.warning(getClass().getSimpleName() + ": Skill Tree without type!");
  222. continue;
  223. }
  224. type = attribute.getNodeValue();
  225. attribute = d.getAttributes().getNamedItem("classId");
  226. if (attribute != null)
  227. {
  228. try
  229. {
  230. cId = Integer.parseInt(attribute.getNodeValue());
  231. if (cId != -1)
  232. {
  233. classId = ClassId.values()[cId];
  234. }
  235. }
  236. catch (Exception e)
  237. {
  238. _log.warning(getClass().getSimpleName() + ": Invalid class Id " + attribute.getNodeValue() + " for Skill Tree type: " + type + "!");
  239. continue;
  240. }
  241. }
  242. attribute = d.getAttributes().getNamedItem("parentClassId");
  243. if (attribute != null)
  244. {
  245. try
  246. {
  247. parentClassId = Integer.parseInt(attribute.getNodeValue());
  248. if ((cId > -1) && (cId != parentClassId) && (parentClassId > -1))
  249. {
  250. _parentClassMap.putIfAbsent(classId, ClassId.values()[parentClassId]);
  251. }
  252. }
  253. catch (Exception e)
  254. {
  255. _log.warning(getClass().getSimpleName() + ": Invalid parent class Id " + attribute.getNodeValue() + " for Skill Tree type: " + type + "!");
  256. continue;
  257. }
  258. }
  259. for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
  260. {
  261. if ("skill".equalsIgnoreCase(c.getNodeName()))
  262. {
  263. final StatsSet learnSkillSet = new StatsSet();
  264. int skillId;
  265. int skillLvl;
  266. attributes = c.getAttributes();
  267. attribute = attributes.getNamedItem("skillName");
  268. if (attribute == null)
  269. {
  270. _log.severe(getClass().getSimpleName() + ": Missing skillName, skipping!");
  271. continue;
  272. }
  273. learnSkillSet.set("skillName", attribute.getNodeValue());
  274. attribute = attributes.getNamedItem("skillIdLvl");
  275. if (attribute == null)
  276. {
  277. _log.severe(getClass().getSimpleName() + ": Missing skillIdLvl, skipping!");
  278. continue;
  279. }
  280. try
  281. {
  282. skillId = Integer.parseInt(attribute.getNodeValue().split(",")[0]);
  283. skillLvl = Integer.parseInt(attribute.getNodeValue().split(",")[1]);
  284. learnSkillSet.set("skillId", skillId);
  285. learnSkillSet.set("skillLvl", skillLvl);
  286. }
  287. catch (Exception e)
  288. {
  289. _log.severe(getClass().getSimpleName() + ": Malformed skillIdLvl, skipping!");
  290. continue;
  291. }
  292. attribute = attributes.getNamedItem("getLevel");
  293. if (attribute != null)
  294. {
  295. learnSkillSet.set("getLevel", attribute.getNodeValue());
  296. }
  297. attribute = attributes.getNamedItem("autoGet");
  298. if (attribute != null)
  299. {
  300. learnSkillSet.set("autoGet", attribute.getNodeValue());
  301. }
  302. attribute = attributes.getNamedItem("levelUpSp");
  303. if (attribute != null)
  304. {
  305. learnSkillSet.set("levelUpSp", attribute.getNodeValue());
  306. }
  307. attribute = attributes.getNamedItem("itemsIdCount");
  308. if (attribute != null)
  309. {
  310. learnSkillSet.set("itemsIdCount", attribute.getNodeValue());
  311. }
  312. attribute = attributes.getNamedItem("race");
  313. if (attribute != null)
  314. {
  315. learnSkillSet.set("race", attribute.getNodeValue());
  316. }
  317. attribute = attributes.getNamedItem("preReqSkillIdLvl");
  318. if (attribute != null)
  319. {
  320. learnSkillSet.set("preReqSkillIdLvl", attribute.getNodeValue());
  321. }
  322. attribute = attributes.getNamedItem("socialClass");
  323. if (attribute != null)
  324. {
  325. learnSkillSet.set("socialClass", attribute.getNodeValue());
  326. }
  327. attribute = attributes.getNamedItem("subClassLvlNumber");
  328. if (attribute != null)
  329. {
  330. learnSkillSet.set("subClassLvlNumber", attribute.getNodeValue());
  331. }
  332. attribute = attributes.getNamedItem("residenceSkill");
  333. if (attribute != null)
  334. {
  335. learnSkillSet.set("residenceSkill", attribute.getNodeValue());
  336. }
  337. attribute = attributes.getNamedItem("residenceIds");
  338. if (attribute != null)
  339. {
  340. learnSkillSet.set("residenceIds", attribute.getNodeValue());
  341. }
  342. attribute = attributes.getNamedItem("learnedByNpc");
  343. if (attribute != null)
  344. {
  345. learnSkillSet.set("learnedByNpc", attribute.getNodeValue());
  346. }
  347. attribute = attributes.getNamedItem("learnedByFS");
  348. if (attribute != null)
  349. {
  350. learnSkillSet.set("learnedByFS", attribute.getNodeValue());
  351. }
  352. final L2SkillLearn skillLearn = new L2SkillLearn(learnSkillSet);
  353. final int skillHashCode = SkillTable.getSkillHashCode(skillId, skillLvl);
  354. if (type.equals("classSkillTree"))
  355. {
  356. if (cId != -1)
  357. {
  358. classSkillTree.put(skillHashCode, skillLearn);
  359. }
  360. else
  361. {
  362. _commonSkillTree.put(skillHashCode, skillLearn);
  363. }
  364. }
  365. else if (type.equals("transferSkillTree"))
  366. {
  367. trasferSkillTree.put(skillHashCode, skillLearn);
  368. }
  369. else
  370. {
  371. if (type.equals("collectSkillTree"))
  372. {
  373. _collectSkillTree.put(skillHashCode, skillLearn);
  374. }
  375. else if (type.equals("fishingSkillTree"))
  376. {
  377. _fishingSkillTree.put(skillHashCode, skillLearn);
  378. }
  379. else if (type.equals("pledgeSkillTree"))
  380. {
  381. _pledgeSkillTree.put(skillHashCode, skillLearn);
  382. }
  383. else if (type.equals("subClassSkillTree"))
  384. {
  385. _subClassSkillTree.put(skillHashCode, skillLearn);
  386. }
  387. else if (type.equals("subPledgeSkillTree"))
  388. {
  389. _subPledgeSkillTree.put(skillHashCode, skillLearn);
  390. }
  391. else if (type.equals("transformSkillTree"))
  392. {
  393. _transformSkillTree.put(skillHashCode, skillLearn);
  394. }
  395. else if (type.equals("nobleSkillTree"))
  396. {
  397. _nobleSkillTree.put(skillHashCode, skillLearn);
  398. }
  399. else if (type.equals("heroSkillTree"))
  400. {
  401. _heroSkillTree.put(skillHashCode, skillLearn);
  402. }
  403. else if (type.equals("gameMasterSkillTree"))
  404. {
  405. _gameMasterSkillTree.put(skillHashCode, skillLearn);
  406. }
  407. else if (type.equals("gameMasterAuraSkillTree"))
  408. {
  409. _gameMasterAuraSkillTree.put(skillHashCode, skillLearn);
  410. }
  411. }
  412. }
  413. }
  414. if (type.equals("classSkillTree"))
  415. {
  416. if (cId != -1)
  417. {
  418. if (_classSkillTrees.get(classId) == null)
  419. {
  420. _classSkillTrees.put(classId, classSkillTree);
  421. }
  422. else
  423. {
  424. _classSkillTrees.get(classId).putAll(classSkillTree);
  425. }
  426. }
  427. }
  428. else if (type.equals("transferSkillTree"))
  429. {
  430. _transferSkillTrees.put(classId, trasferSkillTree);
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. /**
  438. * Wrapper for class skill trees.
  439. * @return the {@code _classSkillTrees}, if it's null allocate a new map and returns it.
  440. */
  441. private FastMap<ClassId, FastMap<Integer, L2SkillLearn>> getClassSkillTrees()
  442. {
  443. return _classSkillTrees;
  444. }
  445. /**
  446. * Method to get the complete skill tree for a given class id.<br>
  447. * Include all skills common to all classes.<br>
  448. * Includes all parent skill trees.
  449. * @param classId the class skill tree ID.
  450. * @return the complete Class Skill Tree including skill trees from parent class for a given {@code classId}.
  451. */
  452. public FastMap<Integer, L2SkillLearn> getCompleteClassSkillTree(ClassId classId)
  453. {
  454. final FastMap<Integer, L2SkillLearn> skillTree = new FastMap<Integer, L2SkillLearn>();
  455. // Add all skills that belong to all classes.
  456. skillTree.putAll(_commonSkillTree);
  457. while ((classId != null) && (getClassSkillTrees().get(classId) != null))
  458. {
  459. skillTree.putAll(getClassSkillTrees().get(classId));
  460. classId = _parentClassMap.get(classId);
  461. }
  462. return skillTree;
  463. }
  464. /**
  465. * @param classId the transfer skill tree ID.
  466. * @return the complete Transfer Skill Tree for a given {@code classId}.
  467. */
  468. public FastMap<Integer, L2SkillLearn> getTransferSkillTree(ClassId classId)
  469. {
  470. // If new classes are implemented over 3rd class, we use a recursive call.
  471. if (classId.level() >= 3)
  472. {
  473. classId = classId.getParent();
  474. return getTransferSkillTree(classId);
  475. }
  476. return _transferSkillTrees.get(classId);
  477. }
  478. /**
  479. * @return the complete Common Skill Tree.
  480. */
  481. public FastMap<Integer, L2SkillLearn> getCommonSkillTree()
  482. {
  483. return _commonSkillTree;
  484. }
  485. /**
  486. * @return the complete Collect Skill Tree.
  487. */
  488. public FastMap<Integer, L2SkillLearn> getCollectSkillTree()
  489. {
  490. return _collectSkillTree;
  491. }
  492. /**
  493. * @return the complete Fishing Skill Tree.
  494. */
  495. public FastMap<Integer, L2SkillLearn> getFishingSkillTree()
  496. {
  497. return _fishingSkillTree;
  498. }
  499. /**
  500. * @return the complete Pledge Skill Tree.
  501. */
  502. public FastMap<Integer, L2SkillLearn> getPledgeSkillTree()
  503. {
  504. return _pledgeSkillTree;
  505. }
  506. /**
  507. * @return the complete Sub-Class Skill Tree.
  508. */
  509. public FastMap<Integer, L2SkillLearn> getSubClassSkillTree()
  510. {
  511. return _subClassSkillTree;
  512. }
  513. /**
  514. * @return the complete Sub-Pledge Skill Tree.
  515. */
  516. public FastMap<Integer, L2SkillLearn> getSubPledgeSkillTree()
  517. {
  518. return _subPledgeSkillTree;
  519. }
  520. /**
  521. * @return the complete Transform Skill Tree.
  522. */
  523. public FastMap<Integer, L2SkillLearn> getTransformSkillTree()
  524. {
  525. return _transformSkillTree;
  526. }
  527. /**
  528. * @return the complete Noble Skill Tree.
  529. */
  530. public FastMap<Integer, L2Skill> getNobleSkillTree()
  531. {
  532. final FastMap<Integer, L2Skill> tree = new FastMap<>();
  533. final SkillTable st = SkillTable.getInstance();
  534. for (Entry<Integer, L2SkillLearn> e : _nobleSkillTree.entrySet())
  535. {
  536. tree.put(e.getKey(), st.getInfo(e.getValue().getSkillId(), e.getValue().getSkillLevel()));
  537. }
  538. return tree;
  539. }
  540. /**
  541. * @return the complete Hero Skill Tree.
  542. */
  543. public FastMap<Integer, L2Skill> getHeroSkillTree()
  544. {
  545. final FastMap<Integer, L2Skill> tree = new FastMap<>();
  546. final SkillTable st = SkillTable.getInstance();
  547. for (Entry<Integer, L2SkillLearn> e : _heroSkillTree.entrySet())
  548. {
  549. tree.put(e.getKey(), st.getInfo(e.getValue().getSkillId(), e.getValue().getSkillLevel()));
  550. }
  551. return tree;
  552. }
  553. /**
  554. * @return the complete Game Master Skill Tree.
  555. */
  556. public FastMap<Integer, L2Skill> getGMSkillTree()
  557. {
  558. final FastMap<Integer, L2Skill> tree = new FastMap<>();
  559. final SkillTable st = SkillTable.getInstance();
  560. for (Entry<Integer, L2SkillLearn> e : _gameMasterSkillTree.entrySet())
  561. {
  562. tree.put(e.getKey(), st.getInfo(e.getValue().getSkillId(), e.getValue().getSkillLevel()));
  563. }
  564. return tree;
  565. }
  566. /**
  567. * @return the complete Game Master Aura Skill Tree.
  568. */
  569. public FastMap<Integer, L2Skill> getGMAuraSkillTree()
  570. {
  571. final FastMap<Integer, L2Skill> tree = new FastMap<>();
  572. final SkillTable st = SkillTable.getInstance();
  573. for (Entry<Integer, L2SkillLearn> e : _gameMasterAuraSkillTree.entrySet())
  574. {
  575. tree.put(e.getKey(), st.getInfo(e.getValue().getSkillId(), e.getValue().getSkillLevel()));
  576. }
  577. return tree;
  578. }
  579. /**
  580. * @param player the learning skill player.
  581. * @param classId the learning skill class ID.
  582. * @param includeByFs if {@code true} skills from Forgotten Scroll will be included.
  583. * @param includeAutoGet if {@code true} Auto-Get skills will be included.
  584. * @return all available skills for a given {@code player}, {@code classId}, {@code includeByFs} and {@code includeAutoGet}.
  585. */
  586. public FastList<L2SkillLearn> getAvailableSkills(L2PcInstance player, ClassId classId, boolean includeByFs, boolean includeAutoGet)
  587. {
  588. final FastList<L2SkillLearn> result = new FastList<L2SkillLearn>();
  589. final FastMap<Integer, L2SkillLearn> skills = getCompleteClassSkillTree(classId);
  590. if (skills.isEmpty())
  591. {
  592. // The Skill Tree for this class is undefined.
  593. _log.warning(getClass().getSimpleName() + ": Skilltree for class " + classId + " is not defined!");
  594. return result;
  595. }
  596. final L2Skill[] oldSkills = player.getAllSkills();
  597. for (L2SkillLearn temp : skills.values())
  598. {
  599. if (((includeAutoGet && temp.isAutoGet()) || temp.isLearnedByNpc() || (includeByFs && temp.isLearnedByFS())) && (player.getLevel() >= temp.getGetLevel()))
  600. {
  601. boolean knownSkill = false;
  602. for (int j = 0; (j < oldSkills.length) && !knownSkill; j++)
  603. {
  604. if (oldSkills[j].getId() == temp.getSkillId())
  605. {
  606. if (oldSkills[j].getLevel() == (temp.getSkillLevel() - 1))
  607. {
  608. // This is the next level of a known skill:
  609. result.add(temp);
  610. }
  611. knownSkill = true;
  612. }
  613. }
  614. if (!knownSkill && (temp.getSkillLevel() == 1))
  615. {
  616. // This is a new skill:
  617. result.add(temp);
  618. }
  619. }
  620. }
  621. return result;
  622. }
  623. /**
  624. * @param player the player requesting the Auto-Get skills.
  625. * @return all the available Auto-Get skills for a given {@code player}.
  626. */
  627. public FastList<L2SkillLearn> getAvailableAutoGetSkills(L2PcInstance player)
  628. {
  629. final FastList<L2SkillLearn> result = new FastList<L2SkillLearn>();
  630. final FastMap<Integer, L2SkillLearn> skills = getCompleteClassSkillTree(player.getClassId());
  631. if (skills.size() < 1)
  632. {
  633. // The Skill Tree for this class is undefined, so we return an empty list.
  634. _log.warning(getClass().getSimpleName() + ": Skill Tree for this classId(" + player.getClassId() + ") is not defined!");
  635. return result;
  636. }
  637. final L2Skill[] oldSkills = player.getAllSkills();
  638. for (L2SkillLearn temp : skills.values())
  639. {
  640. if ((temp.getRaces() != null) && Util.contains(temp.getRaces(), Race.Dwarf) && !player.hasDwarvenCraft())
  641. {
  642. continue;
  643. }
  644. if (temp.isAutoGet() && (player.getLevel() >= temp.getGetLevel()))
  645. {
  646. boolean knownSkill = false;
  647. for (int j = 0; (j < oldSkills.length) && !knownSkill; j++)
  648. {
  649. if (oldSkills[j].getId() == temp.getSkillId())
  650. {
  651. if (oldSkills[j].getLevel() < temp.getSkillLevel())
  652. {
  653. result.add(temp);
  654. }
  655. knownSkill = true;
  656. }
  657. }
  658. if (!knownSkill)
  659. {
  660. result.add(temp);
  661. }
  662. }
  663. }
  664. return result;
  665. }
  666. /**
  667. * Dwarvens will get additional dwarven only fishing skills.
  668. * @param player
  669. * @return all the available Fishing skills for a given {@code player}.
  670. */
  671. public FastList<L2SkillLearn> getAvailableFishingSkills(L2PcInstance player)
  672. {
  673. final FastList<L2SkillLearn> result = new FastList<L2SkillLearn>();
  674. final FastMap<Integer, L2SkillLearn> skills = new FastMap<Integer, L2SkillLearn>();
  675. skills.putAll(_fishingSkillTree);
  676. if (skills.size() < 1)
  677. {
  678. // The Skill Tree for fishing skills is undefined.
  679. _log.warning(getClass().getSimpleName() + ": Skilltree for fishing is not defined !");
  680. return result;
  681. }
  682. final L2Skill[] oldSkills = player.getAllSkills();
  683. final Race playerRace = player.getRace();
  684. for (L2SkillLearn temp : skills.values())
  685. {
  686. // If skill is Race specific and the player's race isn't allowed, skip it.
  687. if ((temp.getRaces() != null) && !Util.contains(temp.getRaces(), playerRace))
  688. {
  689. continue;
  690. }
  691. if (temp.isLearnedByNpc() && (player.getLevel() >= temp.getGetLevel()))
  692. {
  693. boolean knownSkill = false;
  694. for (int j = 0; (j < oldSkills.length) && !knownSkill; j++)
  695. {
  696. if (oldSkills[j].getId() == temp.getSkillId())
  697. {
  698. if (oldSkills[j].getLevel() == (temp.getSkillLevel() - 1))
  699. {
  700. // This is the next level of a known skill:
  701. result.add(temp);
  702. }
  703. knownSkill = true;
  704. }
  705. }
  706. if (!knownSkill && (temp.getSkillLevel() == 1))
  707. {
  708. // This is a new skill:
  709. result.add(temp);
  710. }
  711. }
  712. }
  713. return result;
  714. }
  715. /**
  716. * Used in Gracia continent.
  717. * @param player the collecting skill learning player.
  718. * @return all the available Collecting skills for a given {@code player}.
  719. */
  720. public FastList<L2SkillLearn> getAvailableCollectSkills(L2PcInstance player)
  721. {
  722. final FastList<L2SkillLearn> result = new FastList<L2SkillLearn>();
  723. final FastMap<Integer, L2SkillLearn> skills = new FastMap<Integer, L2SkillLearn>();
  724. skills.putAll(_collectSkillTree);
  725. if (skills.size() < 1)
  726. {
  727. // The Skill Tree for Collecting skills is undefined.
  728. _log.warning(getClass().getSimpleName() + ": Skilltree for collecting skills is not defined !");
  729. return result;
  730. }
  731. final L2Skill[] oldSkills = player.getAllSkills();
  732. for (L2SkillLearn temp : skills.values())
  733. {
  734. boolean knownSkill = false;
  735. for (int j = 0; (j < oldSkills.length) && !knownSkill; j++)
  736. {
  737. if (oldSkills[j].getId() == temp.getSkillId())
  738. {
  739. if (oldSkills[j].getLevel() == (temp.getSkillLevel() - 1))
  740. {
  741. // This is the next level of a known skill:
  742. result.add(temp);
  743. }
  744. knownSkill = true;
  745. }
  746. }
  747. if (!knownSkill && (temp.getSkillLevel() == 1))
  748. {
  749. // This is a new skill:
  750. result.add(temp);
  751. }
  752. }
  753. return result;
  754. }
  755. /**
  756. * @param player the transfer skill learning player.
  757. * @return all the available Transfer skills for a given {@code player}.
  758. */
  759. public FastList<L2SkillLearn> getAvailableTransferSkills(L2PcInstance player)
  760. {
  761. final FastList<L2SkillLearn> result = new FastList<L2SkillLearn>();
  762. ClassId classId = player.getClassId();
  763. // If new classes are implemented over 3rd class, a different way should be implemented.
  764. if (classId.level() == 3)
  765. {
  766. classId = classId.getParent();
  767. }
  768. if (_transferSkillTrees.get(classId) == null)
  769. {
  770. return result;
  771. }
  772. for (L2SkillLearn temp : _transferSkillTrees.get(classId).values())
  773. {
  774. // If player doesn't know this transfer skill:
  775. if (player.getKnownSkill(temp.getSkillId()) == null)
  776. {
  777. result.add(temp);
  778. }
  779. }
  780. return result;
  781. }
  782. /**
  783. * Some transformations are not available for some races.
  784. * @param player the transformation skill learning player.
  785. * @return all the available Transformation skills for a given {@code player}.
  786. */
  787. public FastList<L2SkillLearn> getAvailableTransformSkills(L2PcInstance player)
  788. {
  789. final FastList<L2SkillLearn> result = new FastList<L2SkillLearn>();
  790. final FastMap<Integer, L2SkillLearn> skills = _transformSkillTree;
  791. if (skills == null)
  792. {
  793. // The Skill Tree for Transformation skills is undefined.
  794. _log.warning(getClass().getSimpleName() + ": No Transform skills defined!");
  795. return result;
  796. }
  797. final L2Skill[] oldSkills = player.getAllSkills();
  798. for (L2SkillLearn temp : skills.values())
  799. {
  800. if ((player.getLevel() >= temp.getGetLevel()) && ((temp.getRaces() == null) || Util.contains(temp.getRaces(), player.getRace())))
  801. {
  802. boolean knownSkill = false;
  803. for (int j = 0; (j < oldSkills.length) && !knownSkill; j++)
  804. {
  805. if (oldSkills[j].getId() == temp.getSkillId())
  806. {
  807. if (oldSkills[j].getLevel() == (temp.getSkillLevel() - 1))
  808. {
  809. // This is the next level of a known skill:
  810. result.add(temp);
  811. }
  812. knownSkill = true;
  813. }
  814. }
  815. if (!knownSkill && (temp.getSkillLevel() == 1))
  816. {
  817. // This is a new skill:
  818. result.add(temp);
  819. }
  820. }
  821. }
  822. return result;
  823. }
  824. /**
  825. * @param clan the pledge skill learning clan.
  826. * @return all the available Pledge skills for a given {@code clan}.
  827. */
  828. public FastList<L2SkillLearn> getAvailablePledgeSkills(L2Clan clan)
  829. {
  830. final FastList<L2SkillLearn> result = new FastList<L2SkillLearn>();
  831. final FastMap<Integer, L2SkillLearn> skills = _pledgeSkillTree;
  832. if (skills == null)
  833. {
  834. // The Skill Tree for Pledge skills is undefined.
  835. _log.warning(getClass().getSimpleName() + ": No clan skills defined!");
  836. return result;
  837. }
  838. final L2Skill[] oldSkills = clan.getAllSkills();
  839. for (L2SkillLearn temp : skills.values())
  840. {
  841. if (!temp.isResidencialSkill() && (clan.getLevel() >= temp.getGetLevel()))
  842. {
  843. boolean knownSkill = false;
  844. for (int j = 0; (j < oldSkills.length) && !knownSkill; j++)
  845. {
  846. if (oldSkills[j].getId() == temp.getSkillId())
  847. {
  848. if (oldSkills[j].getLevel() == (temp.getSkillLevel() - 1))
  849. {
  850. // This is the next level of a known skill:
  851. result.add(temp);
  852. }
  853. knownSkill = true;
  854. }
  855. }
  856. if (!knownSkill && (temp.getSkillLevel() == 1))
  857. {
  858. // This is a new skill:
  859. result.add(temp);
  860. }
  861. }
  862. }
  863. return result;
  864. }
  865. /**
  866. * @param clan the sub-pledge skill learning clan.
  867. * @return all the available Sub-Pledge skills for a given {@code clan}.
  868. */
  869. public FastList<L2SkillLearn> getAvailableSubPledgeSkills(L2Clan clan)
  870. {
  871. final FastList<L2SkillLearn> result = new FastList<L2SkillLearn>();
  872. final FastMap<Integer, L2SkillLearn> skills = _subPledgeSkillTree;
  873. if (skills == null)
  874. {
  875. // The Skill Tree for Sub-Pledge skills is undefined.
  876. _log.warning(getClass().getSimpleName() + ": No sub-clan skills defined!");
  877. return result;
  878. }
  879. for (L2SkillLearn temp : skills.values())
  880. {
  881. if ((clan.getLevel() >= temp.getGetLevel()) && clan.isLearnableSubSkill(temp.getSkillId(), temp.getSkillLevel()))
  882. {
  883. result.add(temp);
  884. }
  885. }
  886. return result;
  887. }
  888. /**
  889. * @param player the sub-class skill learning player.
  890. * @return all the available Sub-Class skills for a given {@code player}.
  891. */
  892. public FastList<L2SkillLearn> getAvailableSubClassSkills(L2PcInstance player)
  893. {
  894. final FastList<L2SkillLearn> result = new FastList<L2SkillLearn>();
  895. final FastMap<Integer, L2SkillLearn> skills = _subClassSkillTree;
  896. if (skills == null)
  897. {
  898. // The Skill Tree for Sub-Class skills is undefined.
  899. _log.warning(getClass().getSimpleName() + ": No Sub-Class skills defined!");
  900. return result;
  901. }
  902. final L2Skill[] oldSkills = player.getAllSkills();
  903. for (L2SkillLearn temp : skills.values())
  904. {
  905. if (player.getLevel() >= temp.getGetLevel())
  906. {
  907. int[][] subClassConds = null;
  908. for (SubClass subClass : player.getSubClasses().values())
  909. {
  910. subClassConds = temp.getSubClassConditions();
  911. if ((subClassConds != null) && (subClass.getClassIndex() <= subClassConds.length) && (subClass.getClassIndex() == subClassConds[subClass.getClassIndex() - 1][1]) && (subClassConds[subClass.getClassIndex() - 1][0] <= subClass.getLevel()))
  912. {
  913. boolean knownSkill = false;
  914. for (int j = 0; (j < oldSkills.length) && !knownSkill; j++)
  915. {
  916. if (oldSkills[j].getId() == temp.getSkillId())
  917. {
  918. if (oldSkills[j].getLevel() == (temp.getSkillLevel() - 1))
  919. {
  920. // This is the next level of a known skill:
  921. result.add(temp);
  922. }
  923. knownSkill = true;
  924. }
  925. }
  926. if (!knownSkill && (temp.getSkillLevel() == 1))
  927. {
  928. // This is a new skill:
  929. result.add(temp);
  930. }
  931. }
  932. }
  933. }
  934. }
  935. return result;
  936. }
  937. /**
  938. * @param residenceId the id of the Castle, Fort, Territory.
  939. * @return all the available Residential skills for a given {@code residenceId}.
  940. */
  941. public FastList<L2SkillLearn> getAvailableResidentialSkills(int residenceId)
  942. {
  943. final FastList<L2SkillLearn> result = new FastList<L2SkillLearn>();
  944. final FastMap<Integer, L2SkillLearn> skills = _pledgeSkillTree;
  945. if (skills == null)
  946. {
  947. // The Skill Tree for Residential skills is undefined?
  948. _log.warning(getClass().getSimpleName() + ": No residential skills defined!");
  949. return result;
  950. }
  951. for (L2SkillLearn temp : skills.values())
  952. {
  953. if (temp.isResidencialSkill() && (temp.getRecidenceIds() != null) && Util.contains(temp.getRecidenceIds(), residenceId))
  954. {
  955. result.add(temp);
  956. }
  957. }
  958. return result;
  959. }
  960. /**
  961. * @param id the transformation skill ID.
  962. * @param lvl the transformation skill level.
  963. * @return the transform skill from the Transform Skill Tree for a given {@code id} and {@code lvl}.
  964. */
  965. public L2SkillLearn getTransformSkill(int id, int lvl)
  966. {
  967. return _transformSkillTree.get(SkillTable.getSkillHashCode(id, lvl));
  968. }
  969. /**
  970. * @param id the class skill ID.
  971. * @param lvl the class skill level.
  972. * @param classId the class skill tree ID.
  973. * @return the class skill from the Class Skill Trees for a given {@code classId}, {@code id} and {@code lvl}.
  974. */
  975. public L2SkillLearn getClassSkill(int id, int lvl, ClassId classId)
  976. {
  977. final FastMap<Integer, L2SkillLearn> skills = getCompleteClassSkillTree(classId);
  978. return skills.get(SkillTable.getSkillHashCode(id, lvl));
  979. }
  980. /**
  981. * @param id the fishing skill ID.
  982. * @param lvl the fishing skill level.
  983. * @return Fishing skill from the Fishing Skill Tree for a given {@code id} and {@code lvl}.
  984. */
  985. public L2SkillLearn getFishingSkill(int id, int lvl)
  986. {
  987. return _fishingSkillTree.get(SkillTable.getSkillHashCode(id, lvl));
  988. }
  989. /**
  990. * @param id the pledge skill ID.
  991. * @param lvl the pledge skill level.
  992. * @return the pledge skill from the Pledge Skill Tree for a given {@code id} and {@code lvl}.
  993. */
  994. public L2SkillLearn getPledgeSkill(int id, int lvl)
  995. {
  996. return _pledgeSkillTree.get(SkillTable.getSkillHashCode(id, lvl));
  997. }
  998. /**
  999. * @param id the sub-pledge skill ID.
  1000. * @param lvl the sub-pledge skill level.
  1001. * @return the sub-pledge skill from the Sub-Pledge Skill Tree for a given {@code id} and {@code lvl}.
  1002. */
  1003. public L2SkillLearn getSubPledgeSkill(int id, int lvl)
  1004. {
  1005. return _subPledgeSkillTree.get(SkillTable.getSkillHashCode(id, lvl));
  1006. }
  1007. /**
  1008. * @param id the transfer skill ID.
  1009. * @param lvl the transfer skill level.
  1010. * @param classId the transfer skill tree ID.
  1011. * @return the transfer skill from the Transfer Skill Trees for a given {@code classId}, {@code id} and {@code lvl}.
  1012. */
  1013. public L2SkillLearn getTransferSkill(int id, int lvl, ClassId classId)
  1014. {
  1015. if (classId.getParent() != null)
  1016. {
  1017. final ClassId parentId = classId.getParent();
  1018. if (_transferSkillTrees.get(parentId) != null)
  1019. {
  1020. return _transferSkillTrees.get(parentId).get(SkillTable.getSkillHashCode(id, lvl));
  1021. }
  1022. }
  1023. return null;
  1024. }
  1025. /**
  1026. * @param id the sub-class skill ID.
  1027. * @param lvl the sub-class skill level.
  1028. * @return the sub-class skill from the Sub-Class Skill Tree for a given {@code id} and {@code lvl}.
  1029. */
  1030. public L2SkillLearn getSubClassSkill(int id, int lvl)
  1031. {
  1032. return _subClassSkillTree.get(SkillTable.getSkillHashCode(id, lvl));
  1033. }
  1034. /**
  1035. * @param id the common skill Id.
  1036. * @param lvl the common skill level.
  1037. * @return the common skill from the Common Skill Tree for a given {@code id} and {@code lvl}.
  1038. */
  1039. public L2SkillLearn getCommonSkill(int id, int lvl)
  1040. {
  1041. return _commonSkillTree.get(SkillTable.getSkillHashCode(id, lvl));
  1042. }
  1043. /**
  1044. * @param id the collect skill ID.
  1045. * @param lvl the collect skill level.
  1046. * @return the collect skill from the Collect Skill Tree for a given {@code id} and {@code lvl}.
  1047. */
  1048. public L2SkillLearn getCollectSkill(int id, int lvl)
  1049. {
  1050. return _collectSkillTree.get(SkillTable.getSkillHashCode(id, lvl));
  1051. }
  1052. /**
  1053. * @param player the player that requires the minimum level.
  1054. * @param skillTree the skill tree to search the minimum get level.
  1055. * @return the minimum level for a new skill for a given {@code player} and {@code skillTree}.
  1056. */
  1057. public int getMinLevelForNewSkill(L2PcInstance player, FastMap<Integer, L2SkillLearn> skillTree)
  1058. {
  1059. int minLevel = 0;
  1060. if (skillTree.isEmpty())
  1061. {
  1062. _log.warning(getClass().getSimpleName() + ": SkillTree is not defined for getMinLevelForNewSkill!");
  1063. }
  1064. else
  1065. {
  1066. for (L2SkillLearn s : skillTree.values())
  1067. {
  1068. if (s.isLearnedByNpc() && (player.getLevel() < s.getGetLevel()))
  1069. {
  1070. if ((minLevel == 0) || (minLevel > s.getGetLevel()))
  1071. {
  1072. minLevel = s.getGetLevel();
  1073. }
  1074. }
  1075. }
  1076. }
  1077. return minLevel;
  1078. }
  1079. /**
  1080. * @param skillId the Id of the skill to check.
  1081. * @param skillLevel the level of the skill to check, if it's -1 only Id will be checked.
  1082. * @return {@code true} if the skill is present in the Hero Skill Tree, {@code false} otherwise.
  1083. */
  1084. public boolean isHeroSkill(int skillId, int skillLevel)
  1085. {
  1086. if (_heroSkillTree.containsKey(SkillTable.getSkillHashCode(skillId, skillLevel)))
  1087. {
  1088. return true;
  1089. }
  1090. for (L2SkillLearn skill : _heroSkillTree.values())
  1091. {
  1092. if ((skill.getSkillId() == skillId) && (skillLevel == -1))
  1093. {
  1094. return true;
  1095. }
  1096. }
  1097. return false;
  1098. }
  1099. /**
  1100. * @param skillId skillId the Id of the skill to check.
  1101. * @param skillLevel skillLevel the level of the skill to check, if it's -1 only Id will be checked.
  1102. * @return {@code true} if the skill is present in the Game Master Skill Trees, {@code false} otherwise.
  1103. */
  1104. public boolean isGMSkill(int skillId, int skillLevel)
  1105. {
  1106. final FastMap<Integer, L2SkillLearn> gmSkills = new FastMap<>();
  1107. gmSkills.putAll(_gameMasterSkillTree);
  1108. gmSkills.putAll(_gameMasterAuraSkillTree);
  1109. if (gmSkills.containsKey(SkillTable.getSkillHashCode(skillId, skillLevel)))
  1110. {
  1111. return true;
  1112. }
  1113. for (L2SkillLearn skill : gmSkills.values())
  1114. {
  1115. if ((skill.getSkillId() == skillId) && (skillLevel == -1))
  1116. {
  1117. return true;
  1118. }
  1119. }
  1120. return false;
  1121. }
  1122. /**
  1123. * @param gmchar the player to add the Game Master skills.
  1124. * @param auraSkills if {@code true} it will add "GM Aura" skills, else will add the "GM regular" skills.
  1125. */
  1126. public void addSkills(L2PcInstance gmchar, boolean auraSkills)
  1127. {
  1128. final Collection<L2SkillLearn> skills = auraSkills ? _gameMasterAuraSkillTree.values() : _gameMasterSkillTree.values();
  1129. final SkillTable st = SkillTable.getInstance();
  1130. for (L2SkillLearn sl : skills)
  1131. {
  1132. gmchar.addSkill(st.getInfo(sl.getSkillId(), sl.getSkillLevel()), false); // Don't Save GM skills to database
  1133. }
  1134. }
  1135. /**
  1136. * Create and store hash values for skills for easy and fast checks.
  1137. */
  1138. private void generateCheckArrays()
  1139. {
  1140. int i;
  1141. int[] array;
  1142. // Class specific skills:
  1143. FastMap<Integer, L2SkillLearn> tempMap;
  1144. final Set<ClassId> keySet = getClassSkillTrees().keySet();
  1145. _skillsByClassIdHashCodes = new TIntObjectHashMap<int[]>(keySet.size());
  1146. for (ClassId cls : keySet)
  1147. {
  1148. i = 0;
  1149. tempMap = getCompleteClassSkillTree(cls);
  1150. array = new int[tempMap.size()];
  1151. for (int h : tempMap.keySet())
  1152. {
  1153. array[i++] = h;
  1154. }
  1155. tempMap.clear();
  1156. Arrays.sort(array);
  1157. _skillsByClassIdHashCodes.put(cls.ordinal(), array);
  1158. }
  1159. // Race specific skills from Fishing and Transformation skill trees.
  1160. final FastList<Integer> list = new FastList<Integer>();
  1161. _skillsByRaceHashCodes = new TIntObjectHashMap<int[]>(Race.values().length);
  1162. for (Race r : Race.values())
  1163. {
  1164. for (L2SkillLearn s : _fishingSkillTree.values())
  1165. {
  1166. if ((s.getRaces() != null) && Util.contains(s.getRaces(), r))
  1167. {
  1168. list.add(SkillTable.getSkillHashCode(s.getSkillId(), s.getSkillLevel()));
  1169. }
  1170. }
  1171. for (L2SkillLearn s : _transformSkillTree.values())
  1172. {
  1173. if ((s.getRaces() != null) && Util.contains(s.getRaces(), r))
  1174. {
  1175. list.add(SkillTable.getSkillHashCode(s.getSkillId(), s.getSkillLevel()));
  1176. }
  1177. }
  1178. i = 0;
  1179. array = new int[list.size()];
  1180. for (int s : list)
  1181. {
  1182. array[i++] = s;
  1183. }
  1184. Arrays.sort(array);
  1185. _skillsByRaceHashCodes.put(r.ordinal(), array);
  1186. list.clear();
  1187. }
  1188. // Skills available for all classes and races
  1189. for (L2SkillLearn s : _commonSkillTree.values())
  1190. {
  1191. if (s.getRaces() == null)
  1192. {
  1193. list.add(SkillTable.getSkillHashCode(s.getSkillId(), s.getSkillLevel()));
  1194. }
  1195. }
  1196. for (L2SkillLearn s : _fishingSkillTree.values())
  1197. {
  1198. if (s.getRaces() == null)
  1199. {
  1200. list.add(SkillTable.getSkillHashCode(s.getSkillId(), s.getSkillLevel()));
  1201. }
  1202. }
  1203. for (L2SkillLearn s : _transformSkillTree.values())
  1204. {
  1205. if (s.getRaces() == null)
  1206. {
  1207. list.add(SkillTable.getSkillHashCode(s.getSkillId(), s.getSkillLevel()));
  1208. }
  1209. }
  1210. for (L2SkillLearn s : _collectSkillTree.values())
  1211. {
  1212. list.add(SkillTable.getSkillHashCode(s.getSkillId(), s.getSkillLevel()));
  1213. }
  1214. _allSkillsHashCodes = new int[list.size()];
  1215. int j = 0;
  1216. for (int hashcode : list)
  1217. {
  1218. _allSkillsHashCodes[j++] = hashcode;
  1219. }
  1220. Arrays.sort(_allSkillsHashCodes);
  1221. }
  1222. /**
  1223. * Verify if the give skill is valid for the given player.<br>
  1224. * GM's skills are excluded for GM players.
  1225. * @param player the player to verify the skill.
  1226. * @param skill the skill to be verified.
  1227. * @return {@code true} if the skill is allowed to the given player.
  1228. */
  1229. public boolean isSkillAllowed(L2PcInstance player, L2Skill skill)
  1230. {
  1231. if (skill.isExcludedFromCheck())
  1232. {
  1233. return true;
  1234. }
  1235. if (player.isGM() && skill.isGMSkill())
  1236. {
  1237. return true;
  1238. }
  1239. // Prevent accidental skill remove during reload
  1240. if (_loading)
  1241. {
  1242. return true;
  1243. }
  1244. final int maxLvl = SkillTable.getInstance().getMaxLevel(skill.getId());
  1245. final int hashCode = SkillTable.getSkillHashCode(skill.getId(), Math.min(skill.getLevel(), maxLvl));
  1246. if (Arrays.binarySearch(_skillsByClassIdHashCodes.get(player.getClassId().ordinal()), hashCode) >= 0)
  1247. {
  1248. return true;
  1249. }
  1250. if (Arrays.binarySearch(_skillsByRaceHashCodes.get(player.getRace().ordinal()), hashCode) >= 0)
  1251. {
  1252. return true;
  1253. }
  1254. if (Arrays.binarySearch(_allSkillsHashCodes, hashCode) >= 0)
  1255. {
  1256. return true;
  1257. }
  1258. // Exclude Transfer Skills from this check.
  1259. if (getTransferSkill(skill.getId(), Math.min(skill.getLevel(), maxLvl), player.getClassId()) != null)
  1260. {
  1261. return true;
  1262. }
  1263. return false;
  1264. }
  1265. /**
  1266. * @return the only instance of this class.
  1267. */
  1268. public static SkillTreesData getInstance()
  1269. {
  1270. return SingletonHolder._instance;
  1271. }
  1272. /**
  1273. * Singleton holder for the SkillTreesData class.
  1274. */
  1275. @SuppressWarnings("synthetic-access")
  1276. private static class SingletonHolder
  1277. {
  1278. protected static final SkillTreesData _instance = new SkillTreesData();
  1279. }
  1280. }