SkillTreeTable.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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 java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.util.Collection;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.logging.Level;
  23. import java.util.logging.Logger;
  24. import com.l2jserver.L2DatabaseFactory;
  25. import com.l2jserver.gameserver.model.L2PledgeSkillLearn;
  26. import com.l2jserver.gameserver.model.L2Skill;
  27. import com.l2jserver.gameserver.model.L2SkillLearn;
  28. import com.l2jserver.gameserver.model.L2TransformSkillLearn;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.base.ClassId;
  31. import javolution.util.FastList;
  32. import javolution.util.FastMap;
  33. /**
  34. * This class ...
  35. *
  36. * @version $Revision: 1.13.2.2.2.8 $ $Date: 2005/04/06 16:13:25 $
  37. */
  38. public class SkillTreeTable
  39. {
  40. private static Logger _log = Logger.getLogger(SkillTreeTable.class.getName());
  41. private Map<ClassId, Map<Integer, L2SkillLearn>> _skillTrees;
  42. private List<L2SkillLearn> _fishingSkillTrees; //all common skills (teached by Fisherman)
  43. private List<L2SkillLearn> _expandDwarfCraftSkillTrees; //list of special skill for dwarf (expand dwarf craft) learned by class teacher
  44. private List<L2PledgeSkillLearn> _pledgeSkillTrees; //pledge skill list
  45. private List<L2TransformSkillLearn> _TransformSkillTrees; // Transform Skills (Test)
  46. private FastList<L2SkillLearn> _specialSkillTrees;
  47. public static SkillTreeTable getInstance()
  48. {
  49. return SingletonHolder._instance;
  50. }
  51. private SkillTreeTable()
  52. {
  53. load();
  54. }
  55. /**
  56. * Return the minimum level needed to have this Expertise.<BR><BR>
  57. *
  58. * @param grade The grade level searched
  59. */
  60. public int getExpertiseLevel(int grade)
  61. {
  62. if (grade <= 0)
  63. return 0;
  64. // since expertise comes at same level for all classes we use paladin for now
  65. Map<Integer, L2SkillLearn> learnMap = getSkillTrees().get(ClassId.paladin);
  66. int skillHashCode = SkillTable.getSkillHashCode(239, grade);
  67. if (learnMap.containsKey(skillHashCode))
  68. {
  69. return learnMap.get(skillHashCode).getMinLevel();
  70. }
  71. _log.severe("Expertise not found for grade " + grade);
  72. return 0;
  73. }
  74. /**
  75. * Each class receives new skill on certain levels, this methods allow the retrieval of the minimun character level
  76. * of given class required to learn a given skill
  77. * @param skillId The iD of the skill
  78. * @param classID The classId of the character
  79. * @param skillLvl The SkillLvl
  80. * @return The min level
  81. */
  82. public int getMinSkillLevel(int skillId, ClassId classId, int skillLvl)
  83. {
  84. Map<Integer, L2SkillLearn> map = getSkillTrees().get(classId);
  85. int skillHashCode = SkillTable.getSkillHashCode(skillId, skillLvl);
  86. if (map.containsKey(skillHashCode))
  87. {
  88. return map.get(skillHashCode).getMinLevel();
  89. }
  90. return 0;
  91. }
  92. public int getMinSkillLevel(int skillId, int skillLvl)
  93. {
  94. int skillHashCode = SkillTable.getSkillHashCode(skillId, skillLvl);
  95. // Look on all classes for this skill (takes the first one found)
  96. for (Map<Integer, L2SkillLearn> map : getSkillTrees().values())
  97. {
  98. // checks if the current class has this skill
  99. if (map.containsKey(skillHashCode))
  100. {
  101. return map.get(skillHashCode).getMinLevel();
  102. }
  103. }
  104. return 0;
  105. }
  106. private void load()
  107. {
  108. int classId = 0;
  109. int count = 0;
  110. int count2 = 0;
  111. int count3 = 0;
  112. int count4 = 0;
  113. int count5 = 0;
  114. int count6 = 0;
  115. Connection con = null;
  116. try
  117. {
  118. con = L2DatabaseFactory.getInstance().getConnection();
  119. try
  120. {
  121. PreparedStatement statement = con.prepareStatement("SELECT * FROM class_list ORDER BY id");
  122. ResultSet classlist = statement.executeQuery();
  123. Map<Integer, L2SkillLearn> map;
  124. int parentClassId;
  125. L2SkillLearn skillLearn;
  126. PreparedStatement statement2 = con.prepareStatement("SELECT class_id, skill_id, level, name, sp, min_level FROM skill_trees where class_id=? ORDER BY skill_id, level");
  127. while (classlist.next())
  128. {
  129. map = new FastMap<Integer, L2SkillLearn>();
  130. parentClassId = classlist.getInt("parent_id");
  131. classId = classlist.getInt("id");
  132. statement2.setInt(1, classId);
  133. ResultSet skilltree = statement2.executeQuery();
  134. statement2.clearParameters();
  135. if (parentClassId != -1)
  136. {
  137. Map<Integer, L2SkillLearn> parentMap = getSkillTrees().get(ClassId.values()[parentClassId]);
  138. map.putAll(parentMap);
  139. }
  140. int prevSkillId = -1;
  141. while (skilltree.next())
  142. {
  143. int id = skilltree.getInt("skill_id");
  144. int lvl = skilltree.getInt("level");
  145. String name = skilltree.getString("name");
  146. int minLvl = skilltree.getInt("min_level");
  147. int cost = skilltree.getInt("sp");
  148. if (prevSkillId != id)
  149. prevSkillId = id;
  150. skillLearn = new L2SkillLearn(id, lvl, minLvl, name, cost, 0, 0);
  151. map.put(SkillTable.getSkillHashCode(id, lvl), skillLearn);
  152. }
  153. getSkillTrees().put(ClassId.values()[classId], map);
  154. skilltree.close();
  155. count += map.size();
  156. _log.fine("SkillTreeTable: skill tree for class " + classId + " has " + map.size() + " skills");
  157. }
  158. classlist.close();
  159. statement.close();
  160. statement2.close();
  161. }
  162. catch (Exception e)
  163. {
  164. _log.log(Level.SEVERE, "Error while creating skill tree (Class ID " + classId + "): " + e.getMessage(), e);
  165. }
  166. _log.info("SkillTreeTable: Loaded " + count + " skills.");
  167. //Skill tree for fishing skill (from Fisherman)
  168. try
  169. {
  170. _fishingSkillTrees = new FastList<L2SkillLearn>();
  171. _expandDwarfCraftSkillTrees = new FastList<L2SkillLearn>();
  172. PreparedStatement statement = con.prepareStatement("SELECT skill_id, level, name, sp, min_level, costid, cost, isfordwarf FROM fishing_skill_trees ORDER BY skill_id, level");
  173. ResultSet skilltree2 = statement.executeQuery();
  174. int prevSkillId = -1;
  175. while (skilltree2.next())
  176. {
  177. int id = skilltree2.getInt("skill_id");
  178. int lvl = skilltree2.getInt("level");
  179. String name = skilltree2.getString("name");
  180. int minLvl = skilltree2.getInt("min_level");
  181. int cost = skilltree2.getInt("sp");
  182. int costId = skilltree2.getInt("costid");
  183. int costCount = skilltree2.getInt("cost");
  184. int isDwarven = skilltree2.getInt("isfordwarf");
  185. if (prevSkillId != id)
  186. prevSkillId = id;
  187. L2SkillLearn skill = new L2SkillLearn(id, lvl, minLvl, name, cost, costId, costCount);
  188. if (isDwarven == 0)
  189. _fishingSkillTrees.add(skill);
  190. else
  191. _expandDwarfCraftSkillTrees.add(skill);
  192. }
  193. skilltree2.close();
  194. statement.close();
  195. count2 = _fishingSkillTrees.size();
  196. count3 = _expandDwarfCraftSkillTrees.size();
  197. }
  198. catch (Exception e)
  199. {
  200. _log.log(Level.SEVERE, "Error while creating fishing skill table: " + e.getMessage(), e);
  201. }
  202. try
  203. {
  204. _pledgeSkillTrees = new FastList<L2PledgeSkillLearn>();
  205. PreparedStatement statement = con.prepareStatement("SELECT skill_id, level, name, clan_lvl, repCost, itemId, itemCount FROM pledge_skill_trees ORDER BY skill_id, level");
  206. ResultSet skilltree4 = statement.executeQuery();
  207. int prevSkillId = -1;
  208. while (skilltree4.next())
  209. {
  210. int id = skilltree4.getInt("skill_id");
  211. int lvl = skilltree4.getInt("level");
  212. String name = skilltree4.getString("name");
  213. int baseLvl = skilltree4.getInt("clan_lvl");
  214. int sp = skilltree4.getInt("repCost");
  215. int itemId = skilltree4.getInt("itemId");
  216. int itemCount = skilltree4.getInt("itemCount");
  217. if (prevSkillId != id)
  218. prevSkillId = id;
  219. L2PledgeSkillLearn skill = new L2PledgeSkillLearn(id, lvl, baseLvl, name, sp, itemId, itemCount);
  220. _pledgeSkillTrees.add(skill);
  221. }
  222. skilltree4.close();
  223. statement.close();
  224. count4 = _pledgeSkillTrees.size();
  225. }
  226. catch (Exception e)
  227. {
  228. _log.log(Level.SEVERE, "Error while creating pledge skill table: " + e.getMessage(), e);
  229. }
  230. try
  231. {
  232. _TransformSkillTrees = new FastList<L2TransformSkillLearn>();
  233. PreparedStatement statement = con.prepareStatement("SELECT race_id, skill_id, item_id, level, name, sp, min_level FROM transform_skill_trees ORDER BY race_id, skill_id, level");
  234. ResultSet skilltree5 = statement.executeQuery();
  235. int prevSkillId = -1;
  236. while (skilltree5.next())
  237. {
  238. int race_id = skilltree5.getInt("race_id");
  239. int skill_id = skilltree5.getInt("skill_id");
  240. int item_id = skilltree5.getInt("item_id");
  241. int level = skilltree5.getInt("level");
  242. String name = skilltree5.getString("name");
  243. int sp = skilltree5.getInt("sp");
  244. int min_level = skilltree5.getInt("min_level");
  245. if (prevSkillId != skill_id)
  246. prevSkillId = skill_id;
  247. L2TransformSkillLearn skill = new L2TransformSkillLearn(race_id, skill_id, item_id, level, name, sp, min_level);
  248. _TransformSkillTrees.add(skill);
  249. }
  250. skilltree5.close();
  251. statement.close();
  252. count5 = _TransformSkillTrees.size();
  253. }
  254. catch (Exception e)
  255. {
  256. _log.log(Level.SEVERE, "Error while creating Transformation skill table ", e);
  257. }
  258. try
  259. {
  260. _specialSkillTrees = new FastList<L2SkillLearn>();
  261. PreparedStatement statement = con.prepareStatement("SELECT skill_id, level, name, costid, cost FROM special_skill_trees ORDER BY skill_id, level");
  262. ResultSet skilltree6 = statement.executeQuery();
  263. int prevSkillId = -1;
  264. while (skilltree6.next())
  265. {
  266. int id = skilltree6.getInt("skill_id");
  267. int lvl = skilltree6.getInt("level");
  268. String name = skilltree6.getString("name");
  269. int costId = skilltree6.getInt("costid");
  270. int costCount = skilltree6.getInt("cost");
  271. if (prevSkillId != id)
  272. prevSkillId = id;
  273. L2SkillLearn skill = new L2SkillLearn(id, lvl, 0, name, 0, costId, costCount);
  274. _specialSkillTrees.add(skill);
  275. }
  276. skilltree6.close();
  277. statement.close();
  278. count6 = _specialSkillTrees.size();
  279. }
  280. catch (Exception e)
  281. {
  282. _log.log(Level.SEVERE, "Error while creating special skill table: " + e.getMessage(), e);
  283. }
  284. }
  285. catch (Exception e)
  286. {
  287. _log.log(Level.SEVERE, "Error while skill tables ", e);
  288. }
  289. finally
  290. {
  291. try
  292. {
  293. con.close();
  294. }
  295. catch (Exception e)
  296. {
  297. }
  298. }
  299. _log.info("FishingSkillTreeTable: Loaded " + count2 + " general skills.");
  300. _log.info("DwarvenCraftSkillTreeTable: Loaded " + count3 + " dwarven skills.");
  301. _log.info("PledgeSkillTreeTable: Loaded " + count4 + " pledge skills");
  302. _log.info("TransformSkillTreeTable: Loaded " + count5 + " transform skills");
  303. _log.info("SpecialSkillTreeTable: Loaded " + count6 + " special skills");
  304. }
  305. private Map<ClassId, Map<Integer, L2SkillLearn>> getSkillTrees()
  306. {
  307. if (_skillTrees == null)
  308. _skillTrees = new FastMap<ClassId, Map<Integer, L2SkillLearn>>();
  309. return _skillTrees;
  310. }
  311. public L2SkillLearn[] getAvailableSkills(L2PcInstance cha, ClassId classId)
  312. {
  313. List<L2SkillLearn> result = new FastList<L2SkillLearn>();
  314. Collection<L2SkillLearn> skills = getSkillTrees().get(classId).values();
  315. if (skills == null)
  316. {
  317. // the skilltree for this class is undefined, so we give an empty list
  318. _log.warning("Skilltree for class " + classId + " is not defined !");
  319. return new L2SkillLearn[0];
  320. }
  321. L2Skill[] oldSkills = cha.getAllSkills();
  322. for (L2SkillLearn temp : skills)
  323. {
  324. if (temp.getMinLevel() <= cha.getLevel())
  325. {
  326. boolean knownSkill = false;
  327. for (int j = 0; j < oldSkills.length && !knownSkill; j++)
  328. {
  329. if (oldSkills[j].getId() == temp.getId())
  330. {
  331. knownSkill = true;
  332. if (oldSkills[j].getLevel() == temp.getLevel() - 1)
  333. {
  334. // this is the next level of a skill that we know
  335. result.add(temp);
  336. }
  337. }
  338. }
  339. if (!knownSkill && temp.getLevel() == 1)
  340. {
  341. // this is a new skill
  342. result.add(temp);
  343. }
  344. }
  345. }
  346. return result.toArray(new L2SkillLearn[result.size()]);
  347. }
  348. public L2SkillLearn[] getAvailableSkills(L2PcInstance cha)
  349. {
  350. List<L2SkillLearn> result = new FastList<L2SkillLearn>();
  351. List<L2SkillLearn> skills = new FastList<L2SkillLearn>();
  352. skills.addAll(_fishingSkillTrees);
  353. if (skills.size() < 1)
  354. {
  355. // the skilltree for this class is undefined, so we give an empty list
  356. _log.warning("Skilltree for fishing is not defined !");
  357. return new L2SkillLearn[0];
  358. }
  359. if (cha.hasDwarvenCraft() && _expandDwarfCraftSkillTrees != null)
  360. {
  361. skills.addAll(_expandDwarfCraftSkillTrees);
  362. }
  363. L2Skill[] oldSkills = cha.getAllSkills();
  364. for (L2SkillLearn temp : skills)
  365. {
  366. if (temp.getMinLevel() <= cha.getLevel())
  367. {
  368. boolean knownSkill = false;
  369. for (int j = 0; j < oldSkills.length && !knownSkill; j++)
  370. {
  371. if (oldSkills[j].getId() == temp.getId())
  372. {
  373. knownSkill = true;
  374. if (oldSkills[j].getLevel() == temp.getLevel() - 1)
  375. {
  376. // this is the next level of a skill that we know
  377. result.add(temp);
  378. }
  379. }
  380. }
  381. if (!knownSkill && temp.getLevel() == 1)
  382. {
  383. // this is a new skill
  384. result.add(temp);
  385. }
  386. }
  387. }
  388. return result.toArray(new L2SkillLearn[result.size()]);
  389. }
  390. public L2SkillLearn[] getAvailableSpecialSkills(L2PcInstance cha)
  391. {
  392. List<L2SkillLearn> result = new FastList<L2SkillLearn>();
  393. List<L2SkillLearn> skills = new FastList<L2SkillLearn>();
  394. skills.addAll(_specialSkillTrees);
  395. if (skills.size() < 1)
  396. {
  397. // the skilltree for this class is undefined, so we give an empty list
  398. _log.warning("Skilltree for special is not defined !");
  399. return new L2SkillLearn[0];
  400. }
  401. L2Skill[] oldSkills = cha.getAllSkills();
  402. for (L2SkillLearn temp : skills)
  403. {
  404. boolean knownSkill = false;
  405. for (int j = 0; j < oldSkills.length && !knownSkill; j++)
  406. {
  407. if (oldSkills[j].getId() == temp.getId())
  408. {
  409. knownSkill = true;
  410. if (oldSkills[j].getLevel() == temp.getLevel() - 1)
  411. {
  412. // this is the next level of a skill that we know
  413. result.add(temp);
  414. }
  415. }
  416. }
  417. if (!knownSkill && temp.getLevel() == 1)
  418. {
  419. // this is a new skill
  420. result.add(temp);
  421. }
  422. }
  423. return result.toArray(new L2SkillLearn[result.size()]);
  424. }
  425. public L2TransformSkillLearn[] getAvailableTransformSkills(L2PcInstance cha)
  426. {
  427. List<L2TransformSkillLearn> result = new FastList<L2TransformSkillLearn>();
  428. List<L2TransformSkillLearn> skills = _TransformSkillTrees;
  429. if (skills == null)
  430. {
  431. // the skilltree for this class is undefined, so we give an empty list
  432. _log.warning("No Transform skills defined!");
  433. return new L2TransformSkillLearn[0];
  434. }
  435. L2Skill[] oldSkills = cha.getAllSkills();
  436. for (L2TransformSkillLearn temp : skills)
  437. {
  438. if (temp.getMinLevel() <= cha.getLevel() && (temp.getRace() == cha.getRace().ordinal() || temp.getRace() == -1))
  439. {
  440. boolean knownSkill = false;
  441. for (int j = 0; j < oldSkills.length && !knownSkill; j++)
  442. {
  443. if (oldSkills[j].getId() == temp.getId())
  444. {
  445. knownSkill = true;
  446. if (oldSkills[j].getLevel() == temp.getLevel() - 1)
  447. {
  448. // this is the next level of a skill that we know
  449. result.add(temp);
  450. }
  451. }
  452. }
  453. if (!knownSkill && temp.getLevel() == 1)
  454. {
  455. // this is a new skill
  456. result.add(temp);
  457. }
  458. }
  459. }
  460. return result.toArray(new L2TransformSkillLearn[result.size()]);
  461. }
  462. public L2PledgeSkillLearn[] getAvailablePledgeSkills(L2PcInstance cha)
  463. {
  464. List<L2PledgeSkillLearn> result = new FastList<L2PledgeSkillLearn>();
  465. List<L2PledgeSkillLearn> skills = _pledgeSkillTrees;
  466. if (skills == null)
  467. {
  468. // the skilltree for this class is undefined, so we give an empty list
  469. _log.warning("No clan skills defined!");
  470. return new L2PledgeSkillLearn[0];
  471. }
  472. L2Skill[] oldSkills = cha.getClan().getAllSkills();
  473. for (L2PledgeSkillLearn temp : skills)
  474. {
  475. if (temp.getBaseLevel() <= cha.getClan().getLevel())
  476. {
  477. boolean knownSkill = false;
  478. for (int j = 0; j < oldSkills.length && !knownSkill; j++)
  479. {
  480. if (oldSkills[j].getId() == temp.getId())
  481. {
  482. knownSkill = true;
  483. if (oldSkills[j].getLevel() == temp.getLevel() - 1)
  484. {
  485. // this is the next level of a skill that we know
  486. result.add(temp);
  487. }
  488. }
  489. }
  490. if (!knownSkill && temp.getLevel() == 1)
  491. {
  492. // this is a new skill
  493. result.add(temp);
  494. }
  495. }
  496. }
  497. return result.toArray(new L2PledgeSkillLearn[result.size()]);
  498. }
  499. /**
  500. * Returns all allowed skills for a given class.
  501. * @param classId
  502. * @return all allowed skills for a given class.
  503. */
  504. public Collection<L2SkillLearn> getAllowedSkills(ClassId classId)
  505. {
  506. return getSkillTrees().get(classId).values();
  507. }
  508. public int getMinLevelForNewSkill(L2PcInstance cha, ClassId classId)
  509. {
  510. int minLevel = 0;
  511. Collection<L2SkillLearn> skills = getSkillTrees().get(classId).values();
  512. if (skills == null)
  513. {
  514. // the skilltree for this class is undefined, so we give an empty list
  515. _log.warning("Skilltree for class " + classId + " is not defined !");
  516. return minLevel;
  517. }
  518. for (L2SkillLearn temp : skills)
  519. {
  520. if (temp.getMinLevel() > cha.getLevel() && temp.getSpCost() != 0)
  521. if (minLevel == 0 || temp.getMinLevel() < minLevel)
  522. minLevel = temp.getMinLevel();
  523. }
  524. return minLevel;
  525. }
  526. public int getMinLevelForNewSkill(L2PcInstance cha)
  527. {
  528. int minLevel = 0;
  529. List<L2SkillLearn> skills = new FastList<L2SkillLearn>();
  530. skills.addAll(_fishingSkillTrees);
  531. if (skills.size() < 1)
  532. {
  533. // the skilltree for this class is undefined, so we give an empty list
  534. _log.warning("SkillTree for fishing is not defined !");
  535. return minLevel;
  536. }
  537. if (cha.hasDwarvenCraft() && _expandDwarfCraftSkillTrees != null)
  538. {
  539. skills.addAll(_expandDwarfCraftSkillTrees);
  540. }
  541. for (L2SkillLearn s : skills)
  542. {
  543. if (s.getMinLevel() > cha.getLevel())
  544. if (minLevel == 0 || s.getMinLevel() < minLevel)
  545. minLevel = s.getMinLevel();
  546. }
  547. return minLevel;
  548. }
  549. public int getMinLevelForNewTransformSkill(L2PcInstance cha)
  550. {
  551. int minLevel = 0;
  552. List<L2TransformSkillLearn> skills = new FastList<L2TransformSkillLearn>();
  553. skills.addAll(_TransformSkillTrees);
  554. if (skills.size() < 1)
  555. {
  556. // the skilltree for this class is undefined, so we give an empty list
  557. _log.warning("SkillTree for fishing is not defined !");
  558. return minLevel;
  559. }
  560. for (L2TransformSkillLearn s : skills)
  561. {
  562. if ((s.getMinLevel() > cha.getLevel()) && (s.getRace() == cha.getRace().ordinal()))
  563. if (minLevel == 0 || s.getMinLevel() < minLevel)
  564. minLevel = s.getMinLevel();
  565. }
  566. return minLevel;
  567. }
  568. public int getSkillCost(L2PcInstance player, L2Skill skill)
  569. {
  570. int skillCost = 100000000;
  571. ClassId classId = player.getSkillLearningClassId();
  572. int skillHashCode = SkillTable.getSkillHashCode(skill);
  573. if (getSkillTrees().get(classId).containsKey(skillHashCode))
  574. {
  575. L2SkillLearn skillLearn = getSkillTrees().get(classId).get(skillHashCode);
  576. if (skillLearn.getMinLevel() <= player.getLevel())
  577. {
  578. skillCost = skillLearn.getSpCost();
  579. if (!player.getClassId().equalsOrChildOf(classId))
  580. return skillCost;
  581. }
  582. }
  583. return skillCost;
  584. }
  585. @SuppressWarnings("synthetic-access")
  586. private static class SingletonHolder
  587. {
  588. protected static final SkillTreeTable _instance = new SkillTreeTable();
  589. }
  590. public void reload()
  591. {
  592. load();
  593. }
  594. }