SkillTreesData.java 43 KB

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