EnchantSkillGroupsData.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.data.xml.impl;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import java.util.logging.Level;
  23. import org.w3c.dom.Document;
  24. import org.w3c.dom.NamedNodeMap;
  25. import org.w3c.dom.Node;
  26. import com.l2jserver.Config;
  27. import com.l2jserver.gameserver.model.L2EnchantSkillGroup;
  28. import com.l2jserver.gameserver.model.L2EnchantSkillGroup.EnchantSkillHolder;
  29. import com.l2jserver.gameserver.model.L2EnchantSkillLearn;
  30. import com.l2jserver.gameserver.model.StatsSet;
  31. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  32. import com.l2jserver.gameserver.model.skills.Skill;
  33. import com.l2jserver.util.data.xml.IXmlReader;
  34. /**
  35. * This class holds the Enchant Groups information.
  36. * @author Micr0
  37. */
  38. public class EnchantSkillGroupsData implements IXmlReader
  39. {
  40. public static final int NORMAL_ENCHANT_COST_MULTIPLIER = Config.NORMAL_ENCHANT_COST_MULTIPLIER;
  41. public static final int SAFE_ENCHANT_COST_MULTIPLIER = Config.SAFE_ENCHANT_COST_MULTIPLIER;
  42. public static final int NORMAL_ENCHANT_BOOK = 6622;
  43. public static final int SAFE_ENCHANT_BOOK = 9627;
  44. public static final int CHANGE_ENCHANT_BOOK = 9626;
  45. public static final int UNTRAIN_ENCHANT_BOOK = 9625;
  46. private final Map<Integer, L2EnchantSkillGroup> _enchantSkillGroups = new HashMap<>();
  47. private final Map<Integer, L2EnchantSkillLearn> _enchantSkillTrees = new HashMap<>();
  48. /**
  49. * Instantiates a new enchant groups table.
  50. */
  51. protected EnchantSkillGroupsData()
  52. {
  53. load();
  54. }
  55. @Override
  56. public void load()
  57. {
  58. _enchantSkillGroups.clear();
  59. _enchantSkillTrees.clear();
  60. parseDatapackFile("data/enchantSkillGroups.xml");
  61. int routes = 0;
  62. for (L2EnchantSkillGroup group : _enchantSkillGroups.values())
  63. {
  64. routes += group.getEnchantGroupDetails().size();
  65. }
  66. LOGGER.info(getClass().getSimpleName() + ": Loaded " + _enchantSkillGroups.size() + " groups and " + routes + " routes.");
  67. }
  68. @Override
  69. public void parseDocument(Document doc)
  70. {
  71. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  72. {
  73. if ("list".equalsIgnoreCase(n.getNodeName()))
  74. {
  75. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  76. {
  77. if ("group".equalsIgnoreCase(d.getNodeName()))
  78. {
  79. NamedNodeMap attrs = d.getAttributes();
  80. final int id = parseInteger(attrs, "id");
  81. L2EnchantSkillGroup group = _enchantSkillGroups.get(id);
  82. if (group == null)
  83. {
  84. group = new L2EnchantSkillGroup(id);
  85. _enchantSkillGroups.put(id, group);
  86. }
  87. for (Node b = d.getFirstChild(); b != null; b = b.getNextSibling())
  88. {
  89. if ("enchant".equalsIgnoreCase(b.getNodeName()))
  90. {
  91. attrs = b.getAttributes();
  92. StatsSet set = new StatsSet();
  93. for (int i = 0; i < attrs.getLength(); i++)
  94. {
  95. Node att = attrs.item(i);
  96. set.set(att.getNodeName(), att.getNodeValue());
  97. }
  98. group.addEnchantDetail(new EnchantSkillHolder(set));
  99. }
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. /**
  107. * Adds the new route for skill.
  108. * @param skillId the skill id
  109. * @param maxLvL the max lvl
  110. * @param route the route
  111. * @param group the group
  112. * @return the int
  113. */
  114. public int addNewRouteForSkill(int skillId, int maxLvL, int route, int group)
  115. {
  116. L2EnchantSkillLearn enchantableSkill = _enchantSkillTrees.get(skillId);
  117. if (enchantableSkill == null)
  118. {
  119. enchantableSkill = new L2EnchantSkillLearn(skillId, maxLvL);
  120. _enchantSkillTrees.put(skillId, enchantableSkill);
  121. }
  122. if (_enchantSkillGroups.containsKey(group))
  123. {
  124. enchantableSkill.addNewEnchantRoute(route, group);
  125. return _enchantSkillGroups.get(group).getEnchantGroupDetails().size();
  126. }
  127. LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Error while loading generating enchant skill id: " + skillId + "; route: " + route + "; missing group: " + group);
  128. return 0;
  129. }
  130. /**
  131. * Gets the skill enchantment for skill.
  132. * @param skill the skill
  133. * @return the skill enchantment for skill
  134. */
  135. public L2EnchantSkillLearn getSkillEnchantmentForSkill(Skill skill)
  136. {
  137. // there is enchantment for this skill and we have the required level of it
  138. final L2EnchantSkillLearn esl = getSkillEnchantmentBySkillId(skill.getId());
  139. if ((esl != null) && (skill.getLevel() >= esl.getBaseLevel()))
  140. {
  141. return esl;
  142. }
  143. return null;
  144. }
  145. /**
  146. * Gets the skill enchantment by skill id.
  147. * @param skillId the skill id
  148. * @return the skill enchantment by skill id
  149. */
  150. public L2EnchantSkillLearn getSkillEnchantmentBySkillId(int skillId)
  151. {
  152. return _enchantSkillTrees.get(skillId);
  153. }
  154. /**
  155. * Gets the enchant skill group by id.
  156. * @param id the id
  157. * @return the enchant skill group by id
  158. */
  159. public L2EnchantSkillGroup getEnchantSkillGroupById(int id)
  160. {
  161. return _enchantSkillGroups.get(id);
  162. }
  163. /**
  164. * Gets the enchant skill sp cost.
  165. * @param skill the skill
  166. * @return the enchant skill sp cost
  167. */
  168. public int getEnchantSkillSpCost(Skill skill)
  169. {
  170. final L2EnchantSkillLearn enchantSkillLearn = _enchantSkillTrees.get(skill.getId());
  171. if (enchantSkillLearn != null)
  172. {
  173. final EnchantSkillHolder esh = enchantSkillLearn.getEnchantSkillHolder(skill.getLevel());
  174. if (esh != null)
  175. {
  176. return esh.getSpCost();
  177. }
  178. }
  179. return Integer.MAX_VALUE;
  180. }
  181. /**
  182. * Gets the enchant skill Adena cost.
  183. * @param skill the skill
  184. * @return the enchant skill Adena cost
  185. */
  186. public int getEnchantSkillAdenaCost(Skill skill)
  187. {
  188. final L2EnchantSkillLearn enchantSkillLearn = _enchantSkillTrees.get(skill.getId());
  189. if (enchantSkillLearn != null)
  190. {
  191. final EnchantSkillHolder esh = enchantSkillLearn.getEnchantSkillHolder(skill.getLevel());
  192. if (esh != null)
  193. {
  194. return esh.getAdenaCost();
  195. }
  196. }
  197. return Integer.MAX_VALUE;
  198. }
  199. /**
  200. * Gets the enchant skill rate.
  201. * @param player the player
  202. * @param skill the skill
  203. * @return the enchant skill rate
  204. */
  205. public byte getEnchantSkillRate(L2PcInstance player, Skill skill)
  206. {
  207. final L2EnchantSkillLearn enchantSkillLearn = _enchantSkillTrees.get(skill.getId());
  208. if (enchantSkillLearn != null)
  209. {
  210. final EnchantSkillHolder esh = enchantSkillLearn.getEnchantSkillHolder(skill.getLevel());
  211. if (esh != null)
  212. {
  213. return esh.getRate(player);
  214. }
  215. }
  216. return 0;
  217. }
  218. /**
  219. * Gets the single instance of EnchantGroupsData.
  220. * @return single instance of EnchantGroupsData
  221. */
  222. public static EnchantSkillGroupsData getInstance()
  223. {
  224. return SingletonHolder._instance;
  225. }
  226. private static class SingletonHolder
  227. {
  228. protected static final EnchantSkillGroupsData _instance = new EnchantSkillGroupsData();
  229. }
  230. }